问:
Solutions for deploying enterprise mobile applications using react native
I'm looking for solutions for deploying an exclusively internal mobile application for a business using react native. I need to keep it out of the App and Play stores.

Any suggestions would be very much appreciated.

Thanks peeps..

答:
iOS

Apple's supported way:

Enroll your Apple Developer Organization in the Enterprise Program. This will allow you to build and distribute within a large business.

Unsupported way:

Upload the app normally to TestFlight and invite users via Internal or External testing. Even if you choose to go this route, builds expire after a number of days, so new builds will have to be distributed/updated during that timeframe.

Android

Generate a Signed Release APK and distribute it how ever you'd like. Users will download it to their phones and install it directly

Upload to Google Play Developer Console and set the uploaded APKs in the "Beta" track. From there you have to provide emails to invite, then they can install directly from the Google Play Store and receive updates (Only invited users will see).


来源: stackexchange

问:
How to get device console in Xcode6?
I am exploring iOS8 beta. I couldn't find the device console logs in "Window->Devices->MyiPad". Can someone tell me how I can get the console logs?</p>

答:
Xcode 9

Window -> Devices and Simulators

ContentLicense: CC BY-SA 3.0

Title: How to get device console in Xcode6?


问:
Count of images uploaded in a page
i have created with some X number of images, i want the total count of images to be displayed on top. kindly help me out how can i do this using Java Script or jQuery.</p>

```<code><div class="images">
        <div class="slide">
        <img class="photo"  src="img001.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img002.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img003.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img003.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img002.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img001.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>

    </div>
</code>```

答:
Find all images using getElementsByTagName and count them using .length.

var count = document.getElementsByTagName('img').length;

console.log(count);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="images">
        <div class="slide">
        <img class="photo"  src="img001.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img002.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img003.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img003.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img002.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img001.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>

    </div></code>```

Title: Count of images uploaded in a page

Body:
i have created with some X number of images, i want the total count of images to be displayed on top. kindly help me out how can i do this using Java Script or jQuery.

image description

            <button>Delete</button>

image description

            <button>Delete</button>

image description

            <button>Delete</button>

image description

            <button>Delete</button>

image description

            <button>Delete</button>

image description

            <button>Delete</button>

Body:
Find all images using getElementsByTagName and count them using .length.

var count = document.getElementsByTagName('img').length;

console.log(count);

<div class="images">
        <div class="slide">
        <img class="photo"  src="img001.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img002.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img003.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img003.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img002.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>
        <div class="slide">
        <img src="img001.jpg">
        <p>image description</p>
            <button>Delete</button>
        </div>

    </div>


问:
lodash: mapping array to object
Is there a built-in lodash function to take this:

```<code>var params = [
    { name: 'foo', input: 'bar' },
    { name: 'baz', input: 'zle' }
];
</code>```

And output this:

```<code>var output = {
    foo: 'bar',
    baz: 'zle'
};
</code>```

Right now I'm just using Array.prototype.reduce():

```<code>function toHash(array, keyName, valueName) {
    return array.reduce(function(dictionary, next) {
        dictionary[next[keyName]] = next[valueName];
        return dictionary;
    }, {});
}

toHash(params, 'name', 'input');
</code>```

Wondering if there's a lodash short-cut.

答:
Another way with lodash

creating pairs, and then either construct a object or ES6 Map easily

_(params).map(v=>[v.name, v.input]).fromPairs().value()

or

_.fromPairs(params.map(v=>[v.name, v.input]))

Here is a working example

var params = [
    { name: 'foo', input: 'bar' },
    { name: 'baz', input: 'zle' }
];

var obj = _(params).map(v=>[v.name, v.input]).fromPairs().value();

console.log(obj);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script></code>```

Title: lodash: mapping array to object

Body:
Is there a built-in lodash function to take this:

var params = [
    { name: 'foo', input: 'bar' },
    { name: 'baz', input: 'zle' }
];

And output this:

var output = {
    foo: 'bar',
    baz: 'zle'
};

Right now I'm just using Array.prototype.reduce():

function toHash(array, keyName, valueName) {
    return array.reduce(function(dictionary, next) {
        dictionary[next[keyName]] = next[valueName];
        return dictionary;
    }, {});
}

toHash(params, 'name', 'input');

Wondering if there's a lodash short-cut.

Body:
Another way with lodash

creating pairs, and then either construct a object or ES6 Map easily

_(params).map(v=>[v.name, v.input]).fromPairs().value()

or

_.fromPairs(params.map(v=>[v.name, v.input]))

Here is a working example

var params = [
    { name: 'foo', input: 'bar' },
    { name: 'baz', input: 'zle' }
];

var obj = _(params).map(v=>[v.name, v.input]).fromPairs().value();

console.log(obj);

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script>


问:
Change the text in a NSTextField programmatically?
I am used to doing this in Cocoa-touch, so I assumed it would be quite simple. I have already tried:

```<code>field.text = [nsstring stringwithformat:@"%i", number];
[field setText:@"%i", number];
</code>```

and setString, all to no avail.

答:
You should be able to use the setStringValue: method that NSTextField inherits from NSControl.

The full signature is:

```<code>- (void)setStringValue:(NSString *)aString
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I am used to doing this in Cocoa-touch, so I assumed it would be quite simple. I have already tried:

field.text = [nsstring stringwithformat:@"%i", number];
[field setText:@"%i", number];

and setString, all to no avail.

Body:
You should be able to use the setStringValue: method that NSTextField inherits from NSControl.

The full signature is:

- (void)setStringValue:(NSString *)aString

ContentLicense: CC BY-SA 2.5


问:
Same pattern of a special character in 2 strings. Check outline level code of two strings
I have two strings like A.B.C.D_E and in other string I have "..._*" as shown in str.
I want to check if both string are at the same outline level code and both have the same structure.

I tried the following.

```<code>string str= "*.*.*.*_*";
str= str.Replace("*", "");
</code>```

So I will get only dots and dashes and I can count them.

```<code>string abc = "A.B.C.D_E";
var count = Regex.Matches(abc, ".").Count;
var countdash = Regex.Matches(abc, "_").Count;
count= count+countdash;
</code>```

If count is equal to characters in string one than the string have same format.
Unfortunately this solution does not work for different formats.
Is there any better way of doing it?

答:
```<code>string abc = "*.*.*.*_*";
string str = "...._*";
bool isMatch = Regex.Replace(abc, "[^._]", "") == Regex.Replace(str,"[^._]","");
</code>```

<p>[^._] will match any characters that aren't a dot or dash</p>

Body:
I have two strings like A.B.C.D_E and in other string I have "..._*" as shown in str.
I want to check if both string are at the same outline level code and both have the same structure.

I tried the following.

string str= "*.*.*.*_*";
str= str.Replace("*", "");

So I will get only dots and dashes and I can count them.

string abc = "A.B.C.D_E";
var count = Regex.Matches(abc, ".").Count;
var countdash = Regex.Matches(abc, "_").Count;
count= count+countdash;

If count is equal to characters in string one than the string have same format.
Unfortunately this solution does not work for different formats.
Is there any better way of doing it?

Body:
string abc = "*.*.*.*_*";
string str = "...._*";
bool isMatch = Regex.Replace(abc, "[^._]", "") == Regex.Replace(str,"[^._]","");

[^._] will match any characters that aren't a dot or dash


问:
ReactiveUI command unsubscription
I have 2 Views and 2 ViewModels:

First View:

```<code>public partial class FirstView : Page
{
    FirstViewModel ViewModel;
    public FirstView()
    {
        ViewModel = new FirstViewModel();
        ViewModel.ShowSecondView.Subscribe(_ =>
        {
            NavigationService.Navigate(new SecondView(ViewModel.ChildViewModel));
        });

        this.DataContext = ViewModel;
        InitializeComponent();
    }
}
</code>```

First ViewModel:

```<code>public class FirstViewModel
{
    SecondViewModel ChildViewModel;
    public ReactiveCommand<Unit, Unit> ShowSecondView { get; set; }
    public FirstViewModel()
    {
        ChildViewModel = new SecondViewModel();
        ShowSecondView = ReactiveCommand.Create(() =>
        {
             ChildViewModel.Reconfigure(...);
        });
    }
}
</code>```

Second View:

```<code>public partial class SecondView : Page
{
    SecondViewModel ViewModel;
    public SecondView(SecondViewModel viewModel)
    {
        ViewModel = viewModel;
        ViewModel.GoBack.Subscribe(_ =>
        {
            DoSomethingHard();
            if(NavigationService != null)  NavigationService.GoBack();
        });
        this.DataContext = ViewModel;
        InitializeComponent();
    }
}
</code>```

Second ViewModel:

```<code>public class SecondViewModel
{
    public ReactiveCommand<Unit, Unit> GoBack { get; set; }
    public FirstViewModel()
    {
        VeryLongInitialization();
        GoBack = ReactiveCommand.Create(() => { });
    }
    public void Reconfigure(...)
    { ... }
}
</code>```

So, when I run FirstViewModel.ShowSecondView several times and run SecondViewModel.GoBack several times, DoSomethingHard() execute also several times on each created SecondView.

Why do I want create ChildViewModel in FilstViewModel once? Because creating of SecondViewModel takes long time. And I don't recreate every time SecondViewModel but only reconfigure it.

My question is how can I unsubscribe ViewModel.GoBack.Subscribe in SecondView?

P.S. Maybe I should not recreate SecondView in FirstView but reconfigure it as well as SecondViewModel?

UPDATE 1 (thanks to Julien Mialon)

I add IDisposable goBackSubscr and it works! Am I right to implement it?

```<code>public partial class SecondView : Page
{
    SecondViewModel ViewModel;
    IDisposable goBackSubscr;
    public SecondView(SecondViewModel viewModel)
    {
        ViewModel = viewModel;
        goBackSubscr = ViewModel.GoBack.Subscribe(_ =>
        {
            DoSomethingHard();
            if(NavigationService != null)  NavigationService.GoBack();
            goBackSubscr.Dispose();
        });
        this.DataContext = ViewModel;
        InitializeComponent();
    }
}
</code>```

答:
Thanks to @Krzysztof Skowronek

I once again read about IViewFor and resolve my problem

```<code>public partial class SecondView : Page, IViewFor<SecondViewModel>
{
    public SecondViewModel ViewModel { get; set; }
    object IViewFor.ViewModel { get => ViewModel; set { ViewModel = (SecondViewModel)value; } }
    public SecondView(SecondViewModel viewModel)
    {
        ViewModel = viewModel;
        this.WhenActivated(disposables =>
        {
            ViewModel.GoBack.Subscribe(_ =>
                {
                    DoSomethingHard();
                    if (NavigationService != null) NavigationService.GoBack();
                })
                .DisposeWith(disposables);

            this.WhenAnyValue(p => p.ViewModel)
                .BindTo(this, x => x.DataContext)
                .DisposeWith(disposables);
        });
    InitializeComponent();
    }
}
</code>```

Title: ReactiveUI command unsubscription

Body:
I have 2 Views and 2 ViewModels:

First View:

public partial class FirstView : Page
{
    FirstViewModel ViewModel;
    public FirstView()
    {
        ViewModel = new FirstViewModel();
        ViewModel.ShowSecondView.Subscribe(_ =>
        {
            NavigationService.Navigate(new SecondView(ViewModel.ChildViewModel));
        });

        this.DataContext = ViewModel;
        InitializeComponent();
    }
}

First ViewModel:

public class FirstViewModel
{
    SecondViewModel ChildViewModel;
    public ReactiveCommand<Unit, Unit> ShowSecondView { get; set; }
    public FirstViewModel()
    {
        ChildViewModel = new SecondViewModel();
        ShowSecondView = ReactiveCommand.Create(() =>
        {
             ChildViewModel.Reconfigure(...);
        });
    }
}

Second View:

public partial class SecondView : Page
{
    SecondViewModel ViewModel;
    public SecondView(SecondViewModel viewModel)
    {
        ViewModel = viewModel;
        ViewModel.GoBack.Subscribe(_ =>
        {
            DoSomethingHard();
            if(NavigationService != null)  NavigationService.GoBack();
        });
        this.DataContext = ViewModel;
        InitializeComponent();
    }
}

Second ViewModel:

public class SecondViewModel
{
    public ReactiveCommand<Unit, Unit> GoBack { get; set; }
    public FirstViewModel()
    {
        VeryLongInitialization();
        GoBack = ReactiveCommand.Create(() => { });
    }
    public void Reconfigure(...)
    { ... }
}

So, when I run FirstViewModel.ShowSecondView several times and run SecondViewModel.GoBack several times, DoSomethingHard() execute also several times on each created SecondView.

Why do I want create ChildViewModel in FilstViewModel once? Because creating of SecondViewModel takes long time. And I don't recreate every time SecondViewModel but only reconfigure it.

My question is how can I unsubscribe ViewModel.GoBack.Subscribe in SecondView?

P.S. Maybe I should not recreate SecondView in FirstView but reconfigure it as well as SecondViewModel?

UPDATE 1 (thanks to Julien Mialon)

I add IDisposable goBackSubscr and it works! Am I right to implement it?

public partial class SecondView : Page
{
    SecondViewModel ViewModel;
    IDisposable goBackSubscr;
    public SecondView(SecondViewModel viewModel)
    {
        ViewModel = viewModel;
        goBackSubscr = ViewModel.GoBack.Subscribe(_ =>
        {
            DoSomethingHard();
            if(NavigationService != null)  NavigationService.GoBack();
            goBackSubscr.Dispose();
        });
        this.DataContext = ViewModel;
        InitializeComponent();
    }
}

Body:
Thanks to @Krzysztof Skowronek

I once again read about IViewFor and resolve my problem

public partial class SecondView : Page, IViewFor<SecondViewModel>
{
    public SecondViewModel ViewModel { get; set; }
    object IViewFor.ViewModel { get => ViewModel; set { ViewModel = (SecondViewModel)value; } }
    public SecondView(SecondViewModel viewModel)
    {
        ViewModel = viewModel;
        this.WhenActivated(disposables =>
        {
            ViewModel.GoBack.Subscribe(_ =>
                {
                    DoSomethingHard();
                    if (NavigationService != null) NavigationService.GoBack();
                })
                .DisposeWith(disposables);

            this.WhenAnyValue(p => p.ViewModel)
                .BindTo(this, x => x.DataContext)
                .DisposeWith(disposables);
        });
    InitializeComponent();
    }
}


问:
How to check the size of String pool in Java? or Do we have any tools to see the String pool to see the literals how many it has?
Just to know how many literals have been stored as per the current program which has only one literal but what If I do use toLowerCase() which returns another string, will this another string also get stored into the String pool? or it will not untill it gets assigned to a string variable?</p>

答:
will this another string also get stored into the String pool?

No.

or it will not untill it gets assigned to a string variable?

No. It won't get stored into the string pool at all, unless and until you call intern() on it.


问:
how to compute the variable name of a session scope variable for a repeat control
I would like to compute the variable name of a sessionScope variable that I use as the data binding source for a xp:repeat control.

I notice the diamond to compute the variable name is not there. Perhaps it is possible via another way?

答:
There are 2 approaches, one favored over the other, but the other forced onto you in case the name you have to concatenate strings in order to have the final variable name (as it seems to me since you are speaking of a repeat control):

EL approach

```<code><xp:repeat value="#{something}" var="whatever">
    <xp:text value="#{sessionScope[whatever]}" />
</code>```

SSJS approach

```<code><xp:repeat value="#{something}" var="whatever">
    <xp:text value="#{javascript:sessionScope.get('somePrefix' + whatever)}" />
</code>```

Problem of the second approach is that you can't do proper data binding with it if it's an input field, only for display.

If you need proper data binding then I suggest, although inelegant - but I don't have your full picture, a backing bean that concatenates your string so that it can be served through EL ready for use.

Body:
There are 2 approaches, one favored over the other, but the other forced onto you in case the name you have to concatenate strings in order to have the final variable name (as it seems to me since you are speaking of a repeat control):

EL approach

<xp:repeat value="#{something}" var="whatever">
    <xp:text value="#{sessionScope[whatever]}" />

SSJS approach

<xp:repeat value="#{something}" var="whatever">
    <xp:text value="#{javascript:sessionScope.get('somePrefix' + whatever)}" />

Problem of the second approach is that you can't do proper data binding with it if it's an input field, only for display.

If you need proper data binding then I suggest, although inelegant - but I don't have your full picture, a backing bean that concatenates your string so that it can be served through EL ready for use.


问:
glob() expects parameter 1 to be a valid path
I am trying to retrieve a directory saved from database and open all the images inside that directory. The problem is, when I run the code, the result is "Warning: glob() expects parameter 1 to be a valid path, object given in C:\xampp\htdocs\try\test.php on line 5". BTW I'm just starting php and I'm not yet knowledgeable enough on it. Any help will be appreciated. Thanks.

Here is my code in test.php

```<code><?php
require_once 'config.php';
$path = 'SELECT directory FROM path WHERE id = 1';

$files = glob($link, $path);
for ($i=0; $i<count($files); $i++)
{
    $num = $files[$i];
    echo '<a href="'.$num.'"><img src="'.$num.'" alt="random image" style="width:300px;height:200px;"></a>'."  ";
}
?>
</code>```

And this is the config.php

```<code><?php
session_start();
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'sam');

$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
?>
</code>```

答:
This solves the problem.

```<code><?php

$conn = new PDO('mysql:host=localhost;dbname=sam', 'root', '');

$q= $conn->query("SELECT directory FROM path WHERE id='1'");
$result = $q->fetchColumn();
$path = glob($result);
for ($i=0; $i<count($path); $i++)
{
    $num = $path[$i];
    echo '<a href="'.$num.'"><img src="'.$num.'" alt="random image" style="width:300px;height:200px;"></a>'."  ";
}

?>
</code>```

Successfully retrieved the directory from database and displayed the files inside of it.

Body:
I am trying to retrieve a directory saved from database and open all the images inside that directory. The problem is, when I run the code, the result is "Warning: glob() expects parameter 1 to be a valid path, object given in C:\xampp\htdocs\try\test.php on line 5". BTW I'm just starting php and I'm not yet knowledgeable enough on it. Any help will be appreciated. Thanks.

Here is my code in test.php

<?php
require_once 'config.php';
$path = 'SELECT directory FROM path WHERE id = 1';

$files = glob($link, $path);
for ($i=0; $i<count($files); $i++)
{
    $num = $files[$i];
    echo ''."  ";
}
?>

And this is the config.php

<?php
session_start();
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'sam');

$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
?>

Body:
This solves the problem.

<?php

$conn = new PDO('mysql:host=localhost;dbname=sam', 'root', '');

$q= $conn->query("SELECT directory FROM path WHERE id='1'");
$result = $q->fetchColumn();
$path = glob($result);
for ($i=0; $i<count($path); $i++)
{
    $num = $path[$i];
    echo '<a href="'.$num.'"><img src="'.$num.'" alt="random image" style="width:300px;height:200px;"></a>'."&nbsp;&nbsp;";
}

?>

Successfully retrieved the directory from database and displayed the files inside of it.


问:
How to get cell style by name in Apache poi
Am using 3.16

I create some cell styles in a method. And I pass on the workbook to another method for setting cell values.

In this scenario, I have to pass all my cell styles as params to other method. Is there a way I pass only workbook and get styles from that workbook itself.

I found

```<code>workbook.getCellStyleAt(idx).
</code>```

But for this, i have to keep indexed track of all styles i created. And hardcode it value. if i code for a new style in between then I may mess up the sheet format as the index numbers will change.

sample code

```<code>SXSSFWorkbook workbook = new SXSSFWorkbook(1000);
SXSSFSheet sheet = workbook.createSheet("SheetName");

CellStyle styleBOM = workbook.createCellStyle();
Font fontBOM = workbook.createFont();
fontBOM.setFontHeightInPoints((short) 16);
fontBOM.setFontName("Arial");
fontBOM.setBold(false);
styleBOM.setFont(fontBOM);

CellStyle headKey = workbook.createCellStyle();
Font fontKey = workbook.createFont();
fontKey.setFontHeightInPoints((short) 11);
fontKey.setFontName("Arial");
fontKey.setBold(true);
headKey.setFont(fontKey);

CellStyle headValue = workbook.createCellStyle();
Font fontValue = workbook.createFont();
fontValue.setFontHeightInPoints((short) 11);
fontValue.setFontName("Arial");
fontValue.setBold(false);
headValue.setFont(fontValue);

valueList=someLogicToFetchValues(someInput);

downloadExcel(valueList, workbook,styleBOM, headKey,headValue)
</code>```

答:
You could create a static table with all created styles, each identified by its name (or whatever you choose).

Every time you create a style, you add it to that table and when you need it, you read it from that same table.

Something like this:

```<code>class CellStyleMap
{
  public static synchronized void addStyle(String    identifier,
                                           CellStyle style)
  {
    styles.put(identifier, style);
  }

  public static synchronized CellStyle getStyle(String identifier)
  {
    return (styles.get(identifier));
  }

  private static Hashtable<String, CellStyle> styles = new Hashtable<String, CellStyle>();

} // class CellStyleMap
</code>```

Within your code:

```<code>CellStyle styleBOM = workbook.createCellStyle();
...
CellStyleMap.addStyle("BOM", styleBOM);
</code>```

And when you need it:

```<code>CellStyle styleBOM;
styleBOM = CellStyleMap.getStyle("BOM");
</code>```

Body:
Am using 3.16

I create some cell styles in a method. And I pass on the workbook to another method for setting cell values.

In this scenario, I have to pass all my cell styles as params to other method. Is there a way I pass only workbook and get styles from that workbook itself.

I found

workbook.getCellStyleAt(idx).

But for this, i have to keep indexed track of all styles i created. And hardcode it value. if i code for a new style in between then I may mess up the sheet format as the index numbers will change.

sample code

SXSSFWorkbook workbook = new SXSSFWorkbook(1000);
SXSSFSheet sheet = workbook.createSheet("SheetName");

CellStyle styleBOM = workbook.createCellStyle();
Font fontBOM = workbook.createFont();
fontBOM.setFontHeightInPoints((short) 16);
fontBOM.setFontName("Arial");
fontBOM.setBold(false);
styleBOM.setFont(fontBOM);

CellStyle headKey = workbook.createCellStyle();
Font fontKey = workbook.createFont();
fontKey.setFontHeightInPoints((short) 11);
fontKey.setFontName("Arial");
fontKey.setBold(true);
headKey.setFont(fontKey);

CellStyle headValue = workbook.createCellStyle();
Font fontValue = workbook.createFont();
fontValue.setFontHeightInPoints((short) 11);
fontValue.setFontName("Arial");
fontValue.setBold(false);
headValue.setFont(fontValue);

valueList=someLogicToFetchValues(someInput);

downloadExcel(valueList, workbook,styleBOM, headKey,headValue)

Body:
You could create a static table with all created styles, each identified by its name (or whatever you choose).

Every time you create a style, you add it to that table and when you need it, you read it from that same table.

Something like this:

class CellStyleMap
{
  public static synchronized void addStyle(String    identifier,
                                           CellStyle style)
  {
    styles.put(identifier, style);
  }

  public static synchronized CellStyle getStyle(String identifier)
  {
    return (styles.get(identifier));
  }

  private static Hashtable<String, CellStyle> styles = new Hashtable<String, CellStyle>();

} // class CellStyleMap

Within your code:

CellStyle styleBOM = workbook.createCellStyle();
...
CellStyleMap.addStyle("BOM", styleBOM);

And when you need it:

CellStyle styleBOM;
styleBOM = CellStyleMap.getStyle("BOM");


问:
WPF Usercontrol caller didnt work
I have the mainwindow. I call the Usercontrols in the mainwindow. I call Usercontrol1 in the mainwindow.loaded section. I would like to bring Usercontrol2 instead of Usercontrol1 by clicking on a button inside Usercontrol1.

My usercontrol caller class:

```<code> public class uc_call
{
    public static void uc_add(Grid grd, UserControl uc)
    {
        if (grd.Children.Count > 0)
        {
            grd.Children.Clear();
            grd.Children.Add(uc);
        }
        else
        {
            grd.Children.Add(uc);
        }
    }
}
</code>```

My Mainwindow_Loaded(It works):

```<code>uc_call.uc_add(Content, new UserControl1());
</code>```

Button Click function in UserControl1:

```<code>        MainWindow mw = new MainWindow();
        uc_call.uc_add(mw.Content, new Usercontrol2());
</code>```

答:
Do not create a new MainWindow. Instead, use the existing one:

```<code>var topLevelPanel = Application.Current.MainWindow.Content as Panel;

if (topLevelPanel != null)
{
    topLevelPanel.Children.Clear();
    topLevelPanel.Children.Add(new Usercontrol2());
}
</code>```

Note that is doesn't hurt to call Children.Clear() even when the collection is empty.

In case you've added another Content property that holds the Grid where you want to replace the child elements:

```<code>var mainWindow = (MainWindow)Application.Current.MainWindow;
var grid = mainWindow.Content;
grid.Children.Clear();
grid.Children.Add(new Usercontrol2());
</code>```

or with your static method:

```<code>var mw = (MainWindow)Application.Current.MainWindow;
uc_call.uc_add(mw.Content, new Usercontrol2());
</code>```

Title: WPF Usercontrol caller didnt work

Body:
I have the mainwindow. I call the Usercontrols in the mainwindow. I call Usercontrol1 in the mainwindow.loaded section. I would like to bring Usercontrol2 instead of Usercontrol1 by clicking on a button inside Usercontrol1.

My usercontrol caller class:

 public class uc_call
{
    public static void uc_add(Grid grd, UserControl uc)
    {
        if (grd.Children.Count > 0)
        {
            grd.Children.Clear();
            grd.Children.Add(uc);
        }
        else
        {
            grd.Children.Add(uc);
        }
    }
}

My Mainwindow_Loaded(It works):

uc_call.uc_add(Content, new UserControl1());

Button Click function in UserControl1:

        MainWindow mw = new MainWindow();
        uc_call.uc_add(mw.Content, new Usercontrol2());

Body:
Do not create a new MainWindow. Instead, use the existing one:

var topLevelPanel = Application.Current.MainWindow.Content as Panel;

if (topLevelPanel != null)
{
    topLevelPanel.Children.Clear();
    topLevelPanel.Children.Add(new Usercontrol2());
}

Note that is doesn't hurt to call Children.Clear() even when the collection is empty.

In case you've added another Content property that holds the Grid where you want to replace the child elements:

var mainWindow = (MainWindow)Application.Current.MainWindow;
var grid = mainWindow.Content;
grid.Children.Clear();
grid.Children.Add(new Usercontrol2());

or with your static method:

var mw = (MainWindow)Application.Current.MainWindow;
uc_call.uc_add(mw.Content, new Usercontrol2());


问:
Warning/error "function declaration isn't a prototype"
I have a library I created,

File mylib.c:

```<code>#include <mylib.h>

int
testlib() {
    printf("Hello, World!\n");
    return (0);
}
</code>```

File mylib.h:

```<code>#include <stdio.h>
extern int testlib();
</code>```

In my program, I've attempted to call this library function:

File myprogram.c:

```<code>#include <mylib.h>

int
main (int argc, char *argv[]) {
    testlib();
    return (0);
}
</code>```

When I attempt to compile this program I get the following error:

```In file included from myprogram.c:1
mylib.h:2 warning: function declaration isn't a prototype```

I'm using: gcc (GCC) 3.4.5 20051201 (Red Hat 3.4.5-2)

What is the proper way to declare a function prototype?

答:
In C int foo() and int foo(void) are different functions. int foo() accepts an arbitrary number of arguments, while int foo(void) accepts 0 arguments. In C++ they mean the same thing. I suggest that you use void consistently when you mean no arguments.

If you have a variable a, extern int a; is a way to tell the compiler that a is a symbol that might be present in a different translation unit (C compiler speak for source file), don't resolve it until link time. On the other hand, symbols which are function names are anyway resolved at link time. The meaning of a storage class specifier on a function (extern, static) only affects its visibility and extern is the default, so extern is actually unnecessary.

I suggest removing the extern, it is extraneous and is usually omitted.

Body:
I have a library I created,

File mylib.c:

#include <mylib.h>

int
testlib() {
    printf("Hello, World!\n");
    return (0);
}

File mylib.h:

#include <stdio.h>
extern int testlib();

In my program, I've attempted to call this library function:

File myprogram.c:

#include <mylib.h>

int
main (int argc, char *argv[]) {
    testlib();
    return (0);
}

When I attempt to compile this program I get the following error:

In file included from myprogram.c:1
mylib.h:2 warning: function declaration isn't a prototype

I'm using: gcc (GCC) 3.4.5 20051201 (Red Hat 3.4.5-2)

What is the proper way to declare a function prototype?

OwnerDisplayName: Pramod


问:
Removing strings from another string in java
Lets say I have this list of words:

```<code> String[] stopWords = new String[]{"i","a","and","about","an","are","as","at","be","by","com","for","from","how","in","is","it","not","of","on","or","that","the","this","to","was","what","when","where","who","will","with","the","www"};
</code>```

Than I have text

```<code> String text = "I would like to do a nice novel about nature AND people"
</code>```

Is there method that matches the stopWords and removes them while ignoring case; like this somewhere out there?:

```<code> String noStopWordsText = remove(text, stopWords);
</code>```

Result:

```<code> " would like do nice novel nature people"
</code>```

If you know about regex that wold work great but I would really prefer something like commons solution that is bit more performance oriented.

BTW, right now I'm using this commons method which is lacking proper insensitive case handling:

```<code> private static final String[] stopWords = new String[]{"i", "a", "and", "about", "an", "are", "as", "at", "be", "by", "com", "for", "from", "how", "in", "is", "it", "not", "of", "on", "or", "that", "the", "this", "to", "was", "what", "when", "where", "who", "will", "with", "the", "www", "I", "A", "AND", "ABOUT", "AN", "ARE", "AS", "AT", "BE", "BY", "COM", "FOR", "FROM", "HOW", "IN", "IS", "IT", "NOT", "OF", "ON", "OR", "THAT", "THE", "THIS", "TO", "WAS", "WHAT", "WHEN", "WHERE", "WHO", "WILL", "WITH", "THE", "WWW"};
 private static final String[] blanksForStopWords = new String[]{"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};

 noStopWordsText = StringUtils.replaceEach(text, stopWords, blanksForStopWords);
</code>```

答:
You can make a reg expression to match all the stop words [for example a , note space here]and end up with

```<code>str.replaceAll(regexpression,"");
</code>```

OR

```<code> String[] stopWords = new String[]{" i ", " a ", " and ", " about ", " an ", " are ", " as ", " at ", " be ", " by ", " com ", " for ", " from ", " how ", " in ", " is ", " it ", " not ", " of ", " on ", " or ", " that ", " the ", " this ", " to ", " was ", " what ", " when ", " where ", " who ", " will ", " with ", " the ", " www "};
        String text = " I would like to do a nice novel about nature AND people ";

        for (String stopword : stopWords) {
            text = text.replaceAll("(?i)"+stopword, " ");
        }
        System.out.println(text);
</code>```

output:

```<code> would like do nice novel nature people
</code>```

IdeOneDemo

There might be better way.

Body:
Lets say I have this list of words:

 String[] stopWords = new String[]{"i","a","and","about","an","are","as","at","be","by","com","for","from","how","in","is","it","not","of","on","or","that","the","this","to","was","what","when","where","who","will","with","the","www"};

Than I have text

 String text = "I would like to do a nice novel about nature AND people"

Is there method that matches the stopWords and removes them while ignoring case; like this somewhere out there?:

 String noStopWordsText = remove(text, stopWords);

Result:

 " would like do nice novel nature people"

If you know about regex that wold work great but I would really prefer something like commons solution that is bit more performance oriented.

BTW, right now I'm using this commons method which is lacking proper insensitive case handling:

 private static final String[] stopWords = new String[]{"i", "a", "and", "about", "an", "are", "as", "at", "be", "by", "com", "for", "from", "how", "in", "is", "it", "not", "of", "on", "or", "that", "the", "this", "to", "was", "what", "when", "where", "who", "will", "with", "the", "www", "I", "A", "AND", "ABOUT", "AN", "ARE", "AS", "AT", "BE", "BY", "COM", "FOR", "FROM", "HOW", "IN", "IS", "IT", "NOT", "OF", "ON", "OR", "THAT", "THE", "THIS", "TO", "WAS", "WHAT", "WHEN", "WHERE", "WHO", "WILL", "WITH", "THE", "WWW"};
 private static final String[] blanksForStopWords = new String[]{"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};

 noStopWordsText = StringUtils.replaceEach(text, stopWords, blanksForStopWords);

Body:
You can make a reg expression to match all the stop words [for example a , note space here]and end up with

str.replaceAll(regexpression,"");

OR

 String[] stopWords = new String[]{" i ", " a ", " and ", " about ", " an ", " are ", " as ", " at ", " be ", " by ", " com ", " for ", " from ", " how ", " in ", " is ", " it ", " not ", " of ", " on ", " or ", " that ", " the ", " this ", " to ", " was ", " what ", " when ", " where ", " who ", " will ", " with ", " the ", " www "};
        String text = " I would like to do a nice novel about nature AND people ";

        for (String stopword : stopWords) {
            text = text.replaceAll("(?i)"+stopword, " ");
        }
        System.out.println(text);

output:

 would like do nice novel nature people

IdeOneDemo

There might be better way.


问:
Zooming and scrolling in SpriteKit
I am new to SpriteKit. I need to display an image via UIImageView OR SpriteNode (it is a background image for a game). However, I need the user to be able to zoom in to the background and pan around. I accomplished this easily without using SpriteKit but cannot figure out how to make a node accept zoom and pan. If I use UIScrollView in the storyboard, all the sprites added in my scene don't become children and will not zoom or pan.

Is it possible and can you point me in the right direction?

EDIT:

I'm a little confused by your answer, but here's what I did:

In my root view controller .m:

```<code>- (void)viewDidLoad
{
    [super viewDidLoad];
    SKView * showDesigner = (SKView *)self.view;
    SKScene * scene = [iMarchMyScene sceneWithSize:showDesigner.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;
    [showDesigner presentScene:scene];
}
</code>```

In my scene .m: (your steps are commented)

```<code>-(id)initWithSize:(CGSize)size {
    if (self = [super initWithSize:size]) {

        //create SKView (step 1)
        SKView *skview_field = [[SKView alloc]initWithFrame:(CGRectMake(0, 0, size.width, size.height))];

        //create UIScrollView with same dimensions as your SpriteKit view (step 2)
        UIScrollView* uiscrollview_field = [[UIScrollView alloc]initWithFrame:skview_field.frame];

        //initialize the field (field is the game's background node)
        SKSpriteNode *field = [SKSpriteNode spriteNodeWithImageNamed:@"Field"];
        field.position = CGPointMake(CGRectGetMidX(self.frame), (CGRectGetMidY(self.frame)));
        field.size = CGSizeMake(self.size.width, self.size.height / 3);

        //create a UIView (called scrollViewContent) with dimensions of background node (step 3)
        UIView* scrollViewContent = [[UIView alloc]initWithFrame:field.frame];

        //set UIScrollView contentSize with same dimensions as your scrollViewContent and add a scrollContentview as your UISCrollView subview (step 4)
        [uiscrollview_field setContentSize:(CGSizeMake(scrollViewContent.frame.size.width, scrollViewContent.frame.size.height))];
        scrollViewContent.frame = field.frame;
        [uiscrollview_field addSubview:scrollViewContent];

        //[self addChild:field]; -- my original code
        //.....does a bunch of other inits

        return self;
}
</code>```

And here's where I get lost:
Step 5: Now, to your root view add your SKView, and UIScrollView on top of SKView.

If I understood you correctly, I need to go to myRootViewController.m and in the viewDidLoad method, add the SKView and UIScrollView (which are initialized in myScene.m) as subviews to SKView initialized here in the viewDidLoad method? I don't see how to do that part.

答:
If you are using an SKCameraNode you can calculate the difference between two touches to define zooming and panning at once.

Define an SKCameraNode for your SKView

Check if there are two touches

If so, calculate the difference between the previous touches and current touches

Tell the camera to scale by that much

Pan by the camera by either the average of the two points, or the first one (if there's only one)

Result should be something like this. Note that I used the event?.allTouches instead of the received set, if one finger doesn't move between touches, it's not in the touches set, which would cause a pan where a user would expect a zoom.

```<code>let cameraNode = SKCameraNode()

override func didMove(to view: SKView) {

    cameraNode.position = CGPoint(x: size.width / 2, y: size.height / 2)
    addChild(cameraNode)
    camera = cameraNode
}

override func touchesMoved(_ touch: Set<UITouch>, with event: UIEvent?) {

    guard let touches = event?.allTouches else {
        return
    }

    let arr = Array(touches)
    guard let touch = arr.first else {
        return
    }

    var positionInScene = touch.location(in: self)
    var previousPosition = touch.previousLocation(in: self)

    if touches.count > 1 {

        let touch2 = arr[1]

        let positionInScene2 = touch2.location(in: self)
        let previousPosition2 = touch2.previousLocation(in: self)

        let oldDistance = distance(previousPosition, previousPosition2)
        let newDistance = distance(positionInScene, positionInScene2)

        let diff = (oldDistance / newDistance)

        if diff.isNormal && diff != 1 {

            let scaleAction = SKAction.scale(by: diff, duration: 0)
            cameraNode.run(scaleAction)
        }

        previousPosition = average(previousPosition, previousPosition2)
        positionInScene = average(positionInScene, positionInScene2)
    }

    let translation = CGPoint(x: positionInScene.x - previousPosition.x, y: positionInScene.y - previousPosition.y)

    let panAction = SKAction.moveBy(x: -translation.x, y: -translation.y, duration: 0)
    cameraNode.run(panAction)
}

func average(_ a: CGPoint, _ b: CGPoint) -> CGPoint {

    return CGPoint(x: (a.x + b.x) / 2, y: (a.y + b.y) / 2)
}

func distance(_ a: CGPoint, _ b: CGPoint) -> CGFloat {

    let xDist = a.x - b.x
    let yDist = a.y - b.y
    return CGFloat(sqrt((xDist * xDist) + (yDist * yDist)))
}
</code>```

Title: Zooming and scrolling in SpriteKit

Body:
I am new to SpriteKit. I need to display an image via UIImageView OR SpriteNode (it is a background image for a game). However, I need the user to be able to zoom in to the background and pan around. I accomplished this easily without using SpriteKit but cannot figure out how to make a node accept zoom and pan. If I use UIScrollView in the storyboard, all the sprites added in my scene don't become children and will not zoom or pan.

Is it possible and can you point me in the right direction?

EDIT:

I'm a little confused by your answer, but here's what I did:

In my root view controller .m:

- (void)viewDidLoad
{
    [super viewDidLoad];
    SKView * showDesigner = (SKView *)self.view;
    SKScene * scene = [iMarchMyScene sceneWithSize:showDesigner.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;
    [showDesigner presentScene:scene];
}

In my scene .m: (your steps are commented)

-(id)initWithSize:(CGSize)size {
    if (self = [super initWithSize:size]) {

        //create SKView (step 1)
        SKView *skview_field = [[SKView alloc]initWithFrame:(CGRectMake(0, 0, size.width, size.height))];

        //create UIScrollView with same dimensions as your SpriteKit view (step 2)
        UIScrollView* uiscrollview_field = [[UIScrollView alloc]initWithFrame:skview_field.frame];

        //initialize the field (field is the game's background node)
        SKSpriteNode *field = [SKSpriteNode spriteNodeWithImageNamed:@"Field"];
        field.position = CGPointMake(CGRectGetMidX(self.frame), (CGRectGetMidY(self.frame)));
        field.size = CGSizeMake(self.size.width, self.size.height / 3);

        //create a UIView (called scrollViewContent) with dimensions of background node (step 3)
        UIView* scrollViewContent = [[UIView alloc]initWithFrame:field.frame];

        //set UIScrollView contentSize with same dimensions as your scrollViewContent and add a scrollContentview as your UISCrollView subview (step 4)
        [uiscrollview_field setContentSize:(CGSizeMake(scrollViewContent.frame.size.width, scrollViewContent.frame.size.height))];
        scrollViewContent.frame = field.frame;
        [uiscrollview_field addSubview:scrollViewContent];

        //[self addChild:field]; -- my original code
        //.....does a bunch of other inits

        return self;
}

And here's where I get lost:
Step 5: Now, to your root view add your SKView, and UIScrollView on top of SKView.

If I understood you correctly, I need to go to myRootViewController.m and in the viewDidLoad method, add the SKView and UIScrollView (which are initialized in myScene.m) as subviews to SKView initialized here in the viewDidLoad method? I don't see how to do that part.

Body:
If you are using an SKCameraNode you can calculate the difference between two touches to define zooming and panning at once.

Define an SKCameraNode for your SKView

Check if there are two touches

If so, calculate the difference between the previous touches and current touches

Tell the camera to scale by that much

Pan by the camera by either the average of the two points, or the first one (if there's only one)

Result should be something like this. Note that I used the event?.allTouches instead of the received set, if one finger doesn't move between touches, it's not in the touches set, which would cause a pan where a user would expect a zoom.

let cameraNode = SKCameraNode()

override func didMove(to view: SKView) {

    cameraNode.position = CGPoint(x: size.width / 2, y: size.height / 2)
    addChild(cameraNode)
    camera = cameraNode
}

override func touchesMoved(_ touch: Set<UITouch>, with event: UIEvent?) {

    guard let touches = event?.allTouches else {
        return
    }

    let arr = Array(touches)
    guard let touch = arr.first else {
        return
    }

    var positionInScene = touch.location(in: self)
    var previousPosition = touch.previousLocation(in: self)

    if touches.count > 1 {

        let touch2 = arr[1]

        let positionInScene2 = touch2.location(in: self)
        let previousPosition2 = touch2.previousLocation(in: self)

        let oldDistance = distance(previousPosition, previousPosition2)
        let newDistance = distance(positionInScene, positionInScene2)

        let diff = (oldDistance / newDistance)

        if diff.isNormal && diff != 1 {

            let scaleAction = SKAction.scale(by: diff, duration: 0)
            cameraNode.run(scaleAction)
        }

        previousPosition = average(previousPosition, previousPosition2)
        positionInScene = average(positionInScene, positionInScene2)
    }

    let translation = CGPoint(x: positionInScene.x - previousPosition.x, y: positionInScene.y - previousPosition.y)

    let panAction = SKAction.moveBy(x: -translation.x, y: -translation.y, duration: 0)
    cameraNode.run(panAction)
}

func average(_ a: CGPoint, _ b: CGPoint) -> CGPoint {

    return CGPoint(x: (a.x + b.x) / 2, y: (a.y + b.y) / 2)
}

func distance(_ a: CGPoint, _ b: CGPoint) -> CGFloat {

    let xDist = a.x - b.x
    let yDist = a.y - b.y
    return CGFloat(sqrt((xDist * xDist) + (yDist * yDist)))
}


问:
Can we create multiple instance of hyperledger composer rest server for same business network?
To understand application architecture of composer rest server, I would like to understand following things.

Lets say, We have 4 peers of different organization. Now, What would be recommended approach in context of how we would be managing composer rest server.

1) Having one composer rest server per peer

2) Having one composer rest server per network and all peers will share composer rest server

3) Having one composer rest server per channel

答:
firstly, just to confirm its called 'Hyperledger Composer' and 'Fabric Composer' was its old name from way back.

secondly, the answer is you would have one or more (think HA and availability) REST server instances per Composer business network, per Organisation that participates in that business network. It is also dependent on how each deploys REST server instances within their own infrastructure zones and somewhat dependent what user / user base will be authenticating to it  (the likelihood is they would be authenticating their own users / REST clients to consume the REST server APIs - by whatever the chosen Passport strategy is, to authenticate in a multi-user environment - eg. LDAP OAuth2 etc. So, the REST server is not strictly tied to 'peers' per se. The peer information is defined in the connection profile info, in the business network card.

Composer business networks are deployed to a specific channel/ledger -  and configured so in the business network cards that access it - the connection info specifies the channel, and the REST server instance is instantiated using an appropriate business network card.

See more on deploying your REST server here:
https://hyperledger.github.io/composer/integrating/deploying-the-rest-server.html


问:
Angular - How to delete data from Firebase DB
I am trying to delete specific values from my firebase DB.
I want to delete this entry from firebase:

What I tried so far is my button on how to trigger the delete button:

```<code> <div class="single-bfunctions"
 *ngFor='let bfunc of liste'>
<b> Name: </b>{{bfunc.Name}} <br>
<b> Beschreibung: </b>  {{bfunc.Descr}}<br>
<b> Key: </b>   {{bfunc.$key}}
<button type="button"  ng-click="deleteSth(bfunc.name)">Delete Item </button>
</div>
</code>```

... and my delete-method:

```<code>deleteSth(name){
  firebase.database().ref('/BFunctions/').child(name).remove();
}
</code>```

As I am also pretty new to Angular I don't really what the solution could be.
I appreciate your answers!

答:
your button initialisation should look like this, becuase your bfunc.Key is not defined. As is see your bfunc.Name is your key in your database. If this is like that you can make your code as follow:

```<code><button type="button"  ng-click="deleteSth(bfunc.$key=bfunc.Name)">Delete Item
</code>```

than just use:

```<code>deleteSth(key){
    firebase.database().ref().child('/BFunctions/'+key+'/').remove();
}
</code>```

:)

Body:
I am trying to delete specific values from my firebase DB.
I want to delete this entry from firebase:

What I tried so far is my button on how to trigger the delete button:

 Name: {{bfunc.Name}}

 Beschreibung:   {{bfunc.Descr}}

 Key:    {{bfunc.$key}}
<button type="button"  ng-click="deleteSth(bfunc.name)">Delete Item </button>

... and my delete-method:

deleteSth(name){
  firebase.database().ref('/BFunctions/').child(name).remove();
}

As I am also pretty new to Angular I don't really what the solution could be.
I appreciate your answers!

Body:
your button initialisation should look like this, becuase your bfunc.Key is not defined. As is see your bfunc.Name is your key in your database. If this is like that you can make your code as follow:

<button type="button"  ng-click="deleteSth(bfunc.$key=bfunc.Name)">Delete Item

than just use:

deleteSth(key){
    firebase.database().ref().child('/BFunctions/'+key+'/').remove();
}

:)


问:
Meta and # in a UK mac terminal
In the mac terminal application there is a setting (preferences -> keyboard) that lets you set "use option as meta key". This is useful as a lot of unix boxes use bash as default shell and that has emacs keybindings M-f and M-b that let you skip words.

Problem is that on a Mac with a UK keyboard the # symbol is tricky to get to - normally it can  be typed with alt-3, but not if you are in a terminal and alt=meta.

Anyone have a nice way round this?

答: I'm using iTerm2 and I was having this problem. With iTerm2 you can use the left alt key as a meta key, and the right as a normal key. So ralt-3 does the # key.</p>

Title: Meta and # in a UK mac terminal


问:
Spark RDD lineage graph representation
I would like to know if there is a way of using the information provided by
the function of the spark api RDD.toDebugString() to a more structured format, so it can be used to automatically get a graphical representation, for example with graphviz.

It seems that there is some activity around this going on:
https://issues.apache.org/jira/browse/SPARK-1015

But I would like to get the info from toDebugString() to a structured format,
and later decide which graph format to use for representation.

答:
A more detailed and formatted visual representation can be seen using the spark UI which run by default on 4040 port.
Here it the screenshot showing all the details:

Title: Spark RDD lineage graph representation


问:
wildfly 10: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
I have a maven application that works fine in wildfly 8.2, but when Ideployed it in wildfly 10 this error happened:

```<code>[2016-02-21 11:22:08,411] Artifact SaramadIssueTracking:war exploded: Error during artifact deployment. See server log for details.
[2016-02-21 11:22:08,411] Artifact SaramadIssueTracking:war exploded: java.lang.Exception: {"WFLYCTL0080: Failed services" =>
 {"jboss.persistenceunit.SaramadIssueTracking-1#SaramadIssueTracking" => "org.jboss.msc.service.StartException in service
 jboss.persistenceunit.SaramadIssueTracking-1#SaramadIssueTracking: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
    Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory"}}
</code>```

I read this and there was no other dom4j library. I also read this and did it, but after removing dom4j, I got this error:

```<code>    [2016-02-21 01:46:38,384] Artifact SaramadIssueTracking:war exploded: Error during artifact deployment. See server log for details.
[2016-02-21 01:46:38,385] Artifact SaramadIssueTracking:war exploded: java.lang.Exception: {"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./: java.lang.RuntimeException: java.lang.NullPointerException
    Caused by: java.lang.RuntimeException: java.lang.NullPointerException
    Caused by: java.lang.NullPointerException"}}
</code>```

here is my pom.xml

```<code><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>ir.farzanehfar</groupId>
    <artifactId>SaramadIssueTracking</artifactId>
    <version>1</version>
    <packaging>war</packaging>

    <name>SaramadIssueTracking</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
        <repository>
            <id>SimpleCaptchaRepository</id>
            <url>http://repo.jfrog.org/artifactory/libs-releases/</url>
        </repository>
    </repositories>

    <dependencies>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.2</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces.themes</groupId>
            <artifactId>all-themes</artifactId>
            <version>1.0.10</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces.extensions</groupId>
            <artifactId>primefaces-extensions</artifactId>
            <version>3.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces.extensions</groupId>
            <artifactId>resources-ckeditor</artifactId>
            <version>3.1.0</version>
        </dependency>

        <!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.1.0.Final</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>5.1.0.Final</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>12.0</version>
        </dependency>

        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.1</version>
        </dependency>

        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>

        <dependency>
            <groupId>com.jhlabs</groupId>
            <artifactId>imaging</artifactId>
            <version>01012005</version>
        </dependency>

        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis-jaxrpc</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.11</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.11</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webXml>src\main\webapp\WEB-INF\web.xml</webXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
</code>```

答: Your EAR may contain the duplicate spring jpa configuration file, check and remove the duplicate file</p>

Body:
I have a maven application that works fine in wildfly 8.2, but when Ideployed it in wildfly 10 this error happened:

[2016-02-21 11:22:08,411] Artifact SaramadIssueTracking:war exploded: Error during artifact deployment. See server log for details.
[2016-02-21 11:22:08,411] Artifact SaramadIssueTracking:war exploded: java.lang.Exception: {"WFLYCTL0080: Failed services" =>
 {"jboss.persistenceunit.SaramadIssueTracking-1#SaramadIssueTracking" => "org.jboss.msc.service.StartException in service
 jboss.persistenceunit.SaramadIssueTracking-1#SaramadIssueTracking: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
    Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory"}}

I read this and there was no other dom4j library. I also read this and did it, but after removing dom4j, I got this error:

    [2016-02-21 01:46:38,384] Artifact SaramadIssueTracking:war exploded: Error during artifact deployment. See server log for details.
[2016-02-21 01:46:38,385] Artifact SaramadIssueTracking:war exploded: java.lang.Exception: {"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./: java.lang.RuntimeException: java.lang.NullPointerException
    Caused by: java.lang.RuntimeException: java.lang.NullPointerException
    Caused by: java.lang.NullPointerException"}}

here is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>ir.farzanehfar</groupId>
    <artifactId>SaramadIssueTracking</artifactId>
    <version>1</version>
    <packaging>war</packaging>

    <name>SaramadIssueTracking</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
        <repository>
            <id>SimpleCaptchaRepository</id>
            <url>http://repo.jfrog.org/artifactory/libs-releases/</url>
        </repository>
    </repositories>

    <dependencies>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.2</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces.themes</groupId>
            <artifactId>all-themes</artifactId>
            <version>1.0.10</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces.extensions</groupId>
            <artifactId>primefaces-extensions</artifactId>
            <version>3.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces.extensions</groupId>
            <artifactId>resources-ckeditor</artifactId>
            <version>3.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.1.0.Final</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>5.1.0.Final</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>12.0</version>
        </dependency>

        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.1</version>
        </dependency>

        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>

        <dependency>
            <groupId>com.jhlabs</groupId>
            <artifactId>imaging</artifactId>
            <version>01012005</version>
        </dependency>

        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis-jaxrpc</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.11</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.11</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webXml>src\main\webapp\WEB-INF\web.xml</webXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>


问:
How to convert const char* to KString in Kotlin/Native?
In a C++ file, I want to convert a const char* to KString, so that I can then pass the KString to a Kotlin file using Kotlin/Native.

I believe the answer lies in the function

```<code>    OBJ_GETTER(utf8ToUtf16, const char* rawString, size_t rawStringLength)
</code>```

that I found in KString.cpp. But even though I discovered the used define statements in Memory.h, I have not yet managed to properly call the function utf8ToUtf16 from my own C++ file to get a KString. Any help is appreciated.

答:
I ended up taking the pieces to write my own function:

```<code>KString getKString(const char* rawString) {
    size_t rawStringLength = strlen(rawString);
    ObjHeader** OBJ_RESULT;
    uint32_t charCount = utf8::unchecked::distance(rawString, rawString + rawStringLength);
    ArrayHeader* result = AllocArrayInstance(theStringTypeInfo, charCount, OBJ_RESULT)->array();
    KChar* rawResult = CharArrayAddressOfElementAt(result, 0);
    auto convertResult =
    utf8::unchecked::utf8to16(rawString, rawString + rawStringLength, rawResult);
    ObjHeader* obj = result->obj();
    UpdateReturnRef(OBJ_RESULT, obj);
    return (const ArrayHeader*)obj;
}
</code>```

In my test code (C++), I use it like this:

```<code>...
RuntimeState* state = InitRuntime();
KString inMessage;
{
    ObjHolder args;
    inMessage = getKString("Hello from C++");
}
...
DeinitRuntime(state);
</code>```

and include Memory.h, Natives.h, Runtime.h, KString.h, utf8.h, stdlib.h, and string. You may be able to get rid of some of these.

As a side remark, you may realize how AllocArrayInstance is used in the function. It would be nice, if one simply could do the same thing for getting a KString, something like:

```<code>ObjHeader** OBJ_RESULT;
KString kstr = utf8ToUtf16(rawString, rawStringLength, OBJ_RESULT);
</code>```

This did not work from my function, since utf8ToUtf16 was not found. I believe the reason is, that (at the time of writing) the respective function in KString.cpp is inside a namespace {...} block, such that it cannot be used from another file. That's why I ended up mimicking the function as shown above.

Body:
In a C++ file, I want to convert a const char* to KString, so that I can then pass the KString to a Kotlin file using Kotlin/Native.

I believe the answer lies in the function

    OBJ_GETTER(utf8ToUtf16, const char* rawString, size_t rawStringLength)

that I found in KString.cpp. But even though I discovered the used define statements in Memory.h, I have not yet managed to properly call the function utf8ToUtf16 from my own C++ file to get a KString. Any help is appreciated.

Body:
I ended up taking the pieces to write my own function:

KString getKString(const char* rawString) {
    size_t rawStringLength = strlen(rawString);
    ObjHeader** OBJ_RESULT;
    uint32_t charCount = utf8::unchecked::distance(rawString, rawString + rawStringLength);
    ArrayHeader* result = AllocArrayInstance(theStringTypeInfo, charCount, OBJ_RESULT)->array();
    KChar* rawResult = CharArrayAddressOfElementAt(result, 0);
    auto convertResult =
    utf8::unchecked::utf8to16(rawString, rawString + rawStringLength, rawResult);
    ObjHeader* obj = result->obj();
    UpdateReturnRef(OBJ_RESULT, obj);
    return (const ArrayHeader*)obj;
}

In my test code (C++), I use it like this:

...
RuntimeState* state = InitRuntime();
KString inMessage;
{
    ObjHolder args;
    inMessage = getKString("Hello from C++");
}
...
DeinitRuntime(state);

and include Memory.h, Natives.h, Runtime.h, KString.h, utf8.h, stdlib.h, and string. You may be able to get rid of some of these.

As a side remark, you may realize how AllocArrayInstance is used in the function. It would be nice, if one simply could do the same thing for getting a KString, something like:

ObjHeader** OBJ_RESULT;
KString kstr = utf8ToUtf16(rawString, rawStringLength, OBJ_RESULT);

This did not work from my function, since utf8ToUtf16 was not found. I believe the reason is, that (at the time of writing) the respective function in KString.cpp is inside a namespace {...} block, such that it cannot be used from another file. That's why I ended up mimicking the function as shown above.


问:
Not In query not working
I'm trying to run this query, it's supposed to get all employees who're not drivers in wh_route, the driver is a fk for

The following queries are working and giving me back results:

```<code>select distinct driver from wh_route;
select id from pa_employee o where o.id not in (1,2,3,4,5);
</code>```

But when I try to do this:

```<code>select id from pa_employee o where o.id not in (select distinct driver from wh_route);
</code>```

It doesn't return any results.

Tables for reference:

```<code>WH_ROUTE
id    driver
1     1
2     2

PA_EMPLOYEE
id
1
2
3
</code>```

The expected behaviour is that it returns me the id 3, but it returns me nothing

答: You may also want to remove the DISTINCT in your sub-SELECT since it's not needed. That may speed up your query. </p>

Title: Not In query not working

Body:
I'm trying to run this query, it's supposed to get all employees who're not drivers in wh_route, the driver is a fk for

The following queries are working and giving me back results:

select distinct driver from wh_route;
select id from pa_employee o where o.id not in (1,2,3,4,5);

But when I try to do this:

select id from pa_employee o where o.id not in (select distinct driver from wh_route);

It doesn't return any results.

Tables for reference:

WH_ROUTE
id    driver
1     1
2     2

PA_EMPLOYEE
id
1
2
3

The expected behaviour is that it returns me the id 3, but it returns me nothing


问:
dynamically show text box based on dynamically created dropdown menue
I am very new in jsp, and jquery
my code create dynamic text boxes and one drop-down menu based on button clicked,

after created textboxes I want to add one more textbox if the user select option male after the text boxes dynamically added.

the add code works, but the text box when selecting the male option not works.

please please help.

this is my code

```<code><body>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <br />
    <div class="container">
        <h3 align="center">Change Control Board (CCB)</h3>
        <br />
        <h4 align="center">Enter Change Details</h4>
        <br />
        <form name="form1" method="GET" action="jsv" id="form1">
            <div class="table-repsonsive">
                <span id="error"></span>
                <table class="table table-bordered" id="item_table">
                    <tr>
                        <th>Enter Change Name</th>
                        <th>Enter Change Description</th>
                        <th>Enter Change GW</th>
                        <th>Enter Change AW</th>
                        <th><button type="button" name="add" class="btn btn-success btn-sm add"><span class="glyphicon glyphicon-plus"></span></button></th>
                    </tr>
                </table>
                <div align="center">
                    <input type="submit" name="submit" class="btn btn-info" value="Insert" />
                </div>
            </div>
        </form>
    </div>
</body>

</html>
<script>
    $(document).ready(function() {

        $(document).on('click', '.add', function() {
            var html = '';
            html += '<tr> name="change_name1[]"';
            html += '<td><input type="text" name="change_name[]" class="form-control change_name" /></td>';
            html += '<td><textarea name="change_desc[]" class="form-control change_desc rows="3"" /></td>';
            html += '<td><input  type="text" name="change_GW[]" class="form-control change_GW" /></td>';
            html += '<td><input style="display:none;" id="business"  type="text" name="change_G[]" class="form-control change_GW" /></td>';

            html += '<td><select id="purpose" name="sex-type" class="form-control item_unit"><option value="0">select</option><option value="1">male</option><option value="2">Passing on to a client</option></select></td>';

            html += '<td><button type="button" name="remove" class="btn btn-danger btn-sm remove"><span class="glyphicon glyphicon-minus"></span></button></td></tr>';
            $('#item_table').append(html);
        });

        $(document).on('click', '.remove', function() {
            $(this).closest('tr').remove();
        });
    });

    $(document).ready(function() {
        $('#purpose').on('change', function() {
            if (this.value == '1') {
                $("#business").show();
            } else {
                $("#business").hide();
            }
        });
    });
</script>
</code>```

答:
First of all you have an error on the first line where you are concatenating the tr in the $html, it is '
 name="change_name1[]"'; where as it should be '
'; but since the name attribute is not a valid attribute for tr you should change it to a unique id.

I hope the select menu and the input boxes that are generated by the click of a button are not multiple as there is an id attribute on the select input which needs to be unique in case there are multiple select boxes, but since it is not mentioned you make a slight change to your event binding like the code below
You must change the id  attributes from static to dynamic something like appending a count along with their ids i have added it for you hope it solves your problem.

your final script will look like this

```<code>$(document).ready(function () {
        var count = 0;
        $(document).on('click', '.add', function () {
            var html = '';
            html += '<tr>';
            html +='<td><input type="text" name="change_name[]" class="form-control change_name" /></td>';
            html +='<td><textarea name="change_desc[]" class="form-control change_desc rows="3"" /></td>';
            html +='<td><input  type="text" name="change_GW[]" class="form-control change_GW" /></td>';
            html += '<td><input style="display:none;" id="business_' + count +
                '"  type="text" name="change_G[]" class="form-control change_GW" /></td>';

            html += '<td><select id="purpose_' + count +
                '" name="sex-type" class="form-control item_unit"><option value="0">select</option><option value="1">male</option><option value="2">Passing on to a client</option></select></td>';

            html +=
                '<td><button type="button" name="remove" class="btn btn-danger btn-sm remove"><span class="glyphicon glyphicon-minus"></span></button></td></tr>';
            $('#item_table').append(html);

            $('#purpose_' + count).on('change', function () {
                if (this.value == '1') {
                    $("#business_"+count).show();
                } else {
                    $("#business_"+count).hide();
                }

            });
            count++;
        });

        $(document).on('click', '.remove', function () {
            $(this).closest('tr').remove();
        });

    });
</code>```

Body:
I am very new in jsp, and jquery
my code create dynamic text boxes and one drop-down menu based on button clicked,

after created textboxes I want to add one more textbox if the user select option male after the text boxes dynamically added.

the add code works, but the text box when selecting the male option not works.

please please help.

this is my code

Change Control Board (CCB)

Enter Change Details

        <form name="form1" method="GET" action="jsv" id="form1">

                        Enter Change Name
                        Enter Change Description
                        Enter Change GW
                        Enter Change AW
                        <button type="button" name="add" class="btn btn-success btn-sm add"></button>

                    <input type="submit" name="submit" class="btn btn-info" value="Insert" />

        </form>

Body:
First of all you have an error on the first line where you are concatenating the tr in the $html, it is '<tr> name="change_name1[]"'; where as it should be '<tr  name="change_name1[]">'; but since the name attribute is not a valid attribute for tr you should change it to a unique id.

I hope the select menu and the input boxes that are generated by the click of a button are not multiple as there is an id attribute on the select input which needs to be unique in case there are multiple select boxes, but since it is not mentioned you make a slight change to your event binding like the code below
You must change the id  attributes from static to dynamic something like appending a count along with their ids i have added it for you hope it solves your problem.

your final script will look like this

$(document).ready(function () {
        var count = 0;
        $(document).on('click', '.add', function () {
            var html = '';
            html += '<tr>';
            html +='<td><input type="text" name="change_name[]" class="form-control change_name" /></td>';
            html +='<td><textarea name="change_desc[]" class="form-control change_desc rows="3"" /></td>';
            html +='<td><input  type="text" name="change_GW[]" class="form-control change_GW" /></td>';
            html += '<td><input style="display:none;" id="business_' + count +
                '"  type="text" name="change_G[]" class="form-control change_GW" /></td>';

            html += '<td><select id="purpose_' + count +
                '" name="sex-type" class="form-control item_unit"><option value="0">select</option><option value="1">male</option><option value="2">Passing on to a client</option></select></td>';

            html +=
                '<td><button type="button" name="remove" class="btn btn-danger btn-sm remove"><span class="glyphicon glyphicon-minus"></span></button></td></tr>';
            $('#item_table').append(html);

            $('#purpose_' + count).on('change', function () {
                if (this.value == '1') {
                    $("#business_"+count).show();
                } else {
                    $("#business_"+count).hide();
                }

            });
            count++;
        });

        $(document).on('click', '.remove', function () {
            $(this).closest('tr').remove();
        });

    });


问:
TypeError: 'str' object cannot be interpreted as an integer
I don't understand what the problem is with the code, it is very simple so this is an easy one.

```<code>x = input("Give starting number: ")
y = input("Give ending number: ")

for i in range(x,y):
 print(i)
</code>```

It gives me an error

```<code>Traceback (most recent call last):
  File "C:/Python33/harj4.py", line 6, in <module>
    for i in range(x,y):
TypeError: 'str' object cannot be interpreted as an integer
</code>```

As an example, if x is 3 and y is 14,  I want it to print

```<code>Give starting number: 4
Give ending number: 13
4
5
6
7
8
9
10
11
12
13
</code>```

What is the problem?

答:
```<code>x = int(input("Give starting number: "))
y = int(input("Give ending number: "))
</code>```

P.S. Add function int()

Body:
I don't understand what the problem is with the code, it is very simple so this is an easy one.

x = input("Give starting number: ")
y = input("Give ending number: ")

for i in range(x,y):
 print(i)

It gives me an error

Traceback (most recent call last):
  File "C:/Python33/harj4.py", line 6, in <module>
    for i in range(x,y):
TypeError: 'str' object cannot be interpreted as an integer

As an example, if x is 3 and y is 14,  I want it to print

Give starting number: 4
Give ending number: 13
4
5
6
7
8
9
10
11
12
13

What is the problem?

Body:
x = int(input("Give starting number: "))
y = int(input("Give ending number: "))

P.S. Add function int()


问:
Debian 9: the php5 packages is not installed
I need to install some packages to prepare the workspace for a project in the Debian 9 OS runs in a VB. I have the instruction:

```<code>----------------------------------------------------------------------
The following Debian 8 packages are required to run [X-Product]:

sudo apt-get install exim4 ntp pwgen curl php5-dev php-pear pkg-config nmap libzmq3 libzmq3-dev libapache2-mod-php5 apache2 percona-server-server-5.6 php5-cli php5-mysql php5-curl php5-intl daemontools-run oracle-java8-installer ant ruby-compass libtool-bin
----------------------------------------------------------------------
</code>```

When I run the command, I get the following terminal stack,

```<code>Reading package lists... Done
Building dependency tree
Reading state information... Done
Package php5-cli is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package php5-mysql is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package php5-curl is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package libapache2-mod-php5 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Unable to locate package php5-dev
E: Unable to locate package libzmq3
E: Package 'libapache2-mod-php5' has no installation candidate
E: Package 'php5-cli' has no installation candidate
E: Package 'php5-mysql' has no installation candidate
E: Package 'php5-curl' has no installation candidate
E: Unable to locate package php5-intl
</code>```

I did some research on the internet, did the following at next,

```<code>sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
</code>```

It doesn't help me at all. What do I need to fix this? I have very little knowledge about Debian if you ask

Note: I followed the instructions in the answer provided, the issue is still not solved like I cant see the php version

When I run the command of
sudo apt-get install php5.6

It prints in the terminal,

```<code>Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'php5.6-json' for regex 'php5.6'
Note, selecting 'php5.6-common' for regex 'php5.6'
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
</code>```

To look for the PHP version,

```<code>sudo php -v
</code>```

It prints in the terminal,

```<code>sudo: php: command not found
</code>```

More info like if I run it

sudo apt-get install php5-dev
I get error
E: Unable to locate package php5-dev

But, the command
sudo apt-get install php-dev is successful

The command
dpkg -l | grep php| awk '{print $2}' |tr "\n" " " returns value,

Is that mean I hvae php7 installed and that blocks other operations?

```<code>dh-php php-cli php-common php-dev php-gd php-pear php-xml php7.0-cli php7.0-common php7.0-dev php7.0-gd php7.0-json php7.0-opcache php7.0-readline php7.0-xml pkg-php-tools
</code>```

答:
The package libapache2-mod-php5.6, php5-dev, php5-mysql,php5-curl can be installed only on debian Wheezy (7) , Jessie (8) or Sid . Also the ondrej/php repository does not provide those package for debian Stretch  it is only provide the php5.6 package.

The command sudo apt-get install php-dev will install the development module for PHP7 :

```<code>dh-php libssl-dev libssl-doc php7.1-cli php7.1-common php7.1-dev php7.1-json
php7.1-opcache php7.1-readline pkg-php-tools shtool xml2
</code>```

Body:
I need to install some packages to prepare the workspace for a project in the Debian 9 OS runs in a VB. I have the instruction:

----------------------------------------------------------------------
The following Debian 8 packages are required to run [X-Product]:

sudo apt-get install exim4 ntp pwgen curl php5-dev php-pear pkg-config nmap libzmq3 libzmq3-dev libapache2-mod-php5 apache2 percona-server-server-5.6 php5-cli php5-mysql php5-curl php5-intl daemontools-run oracle-java8-installer ant ruby-compass libtool-bin
----------------------------------------------------------------------

When I run the command, I get the following terminal stack,

Reading package lists... Done
Building dependency tree
Reading state information... Done
Package php5-cli is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package php5-mysql is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package php5-curl is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package libapache2-mod-php5 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Unable to locate package php5-dev
E: Unable to locate package libzmq3
E: Package 'libapache2-mod-php5' has no installation candidate
E: Package 'php5-cli' has no installation candidate
E: Package 'php5-mysql' has no installation candidate
E: Package 'php5-curl' has no installation candidate
E: Unable to locate package php5-intl

I did some research on the internet, did the following at next,

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

It doesn't help me at all. What do I need to fix this? I have very little knowledge about Debian if you ask

Note: I followed the instructions in the answer provided, the issue is still not solved like I cant see the php version

When I run the command of
sudo apt-get install php5.6

It prints in the terminal,

Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'php5.6-json' for regex 'php5.6'
Note, selecting 'php5.6-common' for regex 'php5.6'
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

To look for the PHP version,

sudo php -v

It prints in the terminal,

sudo: php: command not found

More info like if I run it

sudo apt-get install php5-dev
I get error
E: Unable to locate package php5-dev

But, the command
sudo apt-get install php-dev is successful

The command
dpkg -l | grep php| awk '{print $2}' |tr "\n" " " returns value,

Is that mean I hvae php7 installed and that blocks other operations?

dh-php php-cli php-common php-dev php-gd php-pear php-xml php7.0-cli php7.0-common php7.0-dev php7.0-gd php7.0-json php7.0-opcache php7.0-readline php7.0-xml pkg-php-tools

Body:
The package libapache2-mod-php5.6, php5-dev, php5-mysql,php5-curl can be installed only on debian Wheezy (7) , Jessie (8) or Sid . Also the ondrej/php repository does not provide those package for debian Stretch  it is only provide the php5.6 package.

The command sudo apt-get install php-dev will install the development module for PHP7 :

dh-php libssl-dev libssl-doc php7.1-cli php7.1-common php7.1-dev php7.1-json
php7.1-opcache php7.1-readline pkg-php-tools shtool xml2


问:
change matrix inside a function and use it in main
I'm new to c language and I have an assignment to allocate a dymanic matrix inside a function, put values in it and return to main and then call to another function that prints the matrix. I know that if I want to change the matrix values inside a function I need to use '&'. But when I return to main in order to print the matrix I get "Segmentation fault (core dumped)".
Can somone tell me what's wrong with my code:</p>

```<code>#include <stdio.h>
#include <stdlib.h>

int checkSize(int); //checking matrix size
void printMatrix(int **, int);  //print matrix
int createMatrix(int ***, int); //allocate matrix and puts values from user.

int main()
{
  int c; int **p=NULL;
  printf("enter size of a matrix\n");
  c=getchar();
  if (checkSize(c))
  {
    if((createMatrix(&p, c-'0'))!=0)
      printMatrix(p, c-'0');
  }
  return 0;
}

int checkSize(int c)
{
  if (c>'9'||c<'0')
    return 0;
  return 1;
}

int createMatrix(int ***p, int n)
{
  int m=n;
  int k;
  p=(int***)malloc(m*sizeof(int**));
  for (k=0; k<m; k++)
    p[k]=(int**)malloc(m*sizeof(int*));
  printf("enter numbers\n");
  int *l;
  int i;
  int c;
  for (i=0; i<m; i++)
  {
    k=n;
    for (l=(int*)(p)+i;k>0;l++)
    {
      c=getchar();
      if (c==EOF)
      {
        printf("error EOF");
        return 0;
      }
      if (c>'9'||c<'0')
      {
        printf("error");
        return 0;
      }
      *l=c-'0';
      k--;
    }
  }
  return 1;
}

void printMatrix(int **p, int n)
{
  int k=n;
  int* l;
  int i;
  int m=n;
  for (i=0; i<k; i++)
  {
    m=n;
    printf("\n");
    for (l=(int*)(p)+i;m>0;l++)
    {
      printf("%d ", *l);
      m--;
    }
  }
}
</code>```

答:
One issue is your memory allocation. You allocate space for the wrong types and save the result incorrectly. That is

```<code>p=(int***)malloc(m*sizeof(int**));
</code>```

should be

```<code>*p = malloc(m * sizeof(int*));
</code>```

and

```<code>p[k]=(int**)malloc(m*sizeof(int*));
</code>```

should be

```<code>(*p)[k] = malloc(m * sizeof(int));
</code>```

Here is an alternative approach that doesn't operate directly on the input argument:

```<code>#include <stdio.h>
#include <stdlib.h>

int create(int ***m, int n)
{
    int i, j;

    // Create the matrix
    int** p = malloc(n * sizeof *p);   // ToDo: Check return value
    for (i=0; i < n; ++i)
    {
        p[i] = malloc(n * sizeof **p);   // ToDo: Check return value
    }

    for (i=0; i < n; ++i)
    {
        for (j=0; j < n; ++j)
        {
            *(p[i] + j) = 10 * i + j;
        }
    }

    // Assign the matrix to the passed pointer
    *m = p;

    return 0;
}

void pm(int **m, int n)
{
    int i, j;
    for (i=0; i < n; ++i)
    {
        for (j=0; j < n; ++j)
        {
            printf("%d ", *(m[i] + j));
        }
        printf("\n");
    }
}
int main(void) {
    int** m;
    create(&m, 5);
    pm(m, 5);

    // ToDo: Add code to free memory

    return 0;
}
</code>```

Output:

```<code>0 1 2 3 4
10 11 12 13 14
20 21 22 23 24
30 31 32 33 34
40 41 42 43 44
</code>```

note For clarity check of malloc return value is omitted.

Body:
I'm new to c language and I have an assignment to allocate a dymanic matrix inside a function, put values in it and return to main and then call to another function that prints the matrix. I know that if I want to change the matrix values inside a function I need to use '&'. But when I return to main in order to print the matrix I get "Segmentation fault (core dumped)".
Can somone tell me what's wrong with my code:

#include <stdio.h>
#include <stdlib.h>

int checkSize(int); //checking matrix size
void printMatrix(int **, int);  //print matrix
int createMatrix(int ***, int); //allocate matrix and puts values from user.

int main()
{
  int c; int **p=NULL;
  printf("enter size of a matrix\n");
  c=getchar();
  if (checkSize(c))
  {
    if((createMatrix(&p, c-'0'))!=0)
      printMatrix(p, c-'0');
  }
  return 0;
}

int checkSize(int c)
{
  if (c>'9'||c<'0')
    return 0;
  return 1;
}

int createMatrix(int ***p, int n)
{
  int m=n;
  int k;
  p=(int***)malloc(m*sizeof(int**));
  for (k=0; k<m; k++)
    p[k]=(int**)malloc(m*sizeof(int*));
  printf("enter numbers\n");
  int *l;
  int i;
  int c;
  for (i=0; i<m; i++)
  {
    k=n;
    for (l=(int*)(p)+i;k>0;l++)
    {
      c=getchar();
      if (c==EOF)
      {
        printf("error EOF");
        return 0;
      }
      if (c>'9'||c<'0')
      {
        printf("error");
        return 0;
      }
      *l=c-'0';
      k--;
    }
  }
  return 1;
}

void printMatrix(int **p, int n)
{
  int k=n;
  int* l;
  int i;
  int m=n;
  for (i=0; i<k; i++)
  {
    m=n;
    printf("\n");
    for (l=(int*)(p)+i;m>0;l++)
    {
      printf("%d ", *l);
      m--;
    }
  }
}

Body:
One issue is your memory allocation. You allocate space for the wrong types and save the result incorrectly. That is

p=(int***)malloc(m*sizeof(int**));

should be

*p = malloc(m * sizeof(int*));

and

p[k]=(int**)malloc(m*sizeof(int*));

should be

(*p)[k] = malloc(m * sizeof(int));

Here is an alternative approach that doesn't operate directly on the input argument:

#include <stdio.h>
#include <stdlib.h>

int create(int ***m, int n)
{
    int i, j;

    // Create the matrix
    int** p = malloc(n * sizeof *p);   // ToDo: Check return value
    for (i=0; i < n; ++i)
    {
        p[i] = malloc(n * sizeof **p);   // ToDo: Check return value
    }

    for (i=0; i < n; ++i)
    {
        for (j=0; j < n; ++j)
        {
            *(p[i] + j) = 10 * i + j;
        }
    }

    // Assign the matrix to the passed pointer
    *m = p;

    return 0;
}

void pm(int **m, int n)
{
    int i, j;
    for (i=0; i < n; ++i)
    {
        for (j=0; j < n; ++j)
        {
            printf("%d ", *(m[i] + j));
        }
        printf("\n");
    }
}
int main(void) {
    int** m;
    create(&m, 5);
    pm(m, 5);

    // ToDo: Add code to free memory

    return 0;
}

Output:

0 1 2 3 4
10 11 12 13 14
20 21 22 23 24
30 31 32 33 34
40 41 42 43 44

note For clarity check of malloc return value is omitted.


问:
How to ignore or remove null element from an array inside collection
```<code>Collection {#363 ▼
  #items: array:3 [▼
    0 => Tag {#376 ▶}
    1 => null
    2 => Tag {#374 ▶}
  ]
}
</code>```

I want to remove the second key/pair element from this collection. How can I achieve this?

答:
As you're dealing with an array of strings, you can simply use array_filter(), which conveniently handles all this for you:

```<code>print_r(array_filter($linksArray));
</code>```

Keep in mind that if no callback is supplied, all entries of array equal to FALSE (see converting to boolean) will be removed. So if you need to preserve elements that are i.e. exact string '0', you will need a custom callback:

```<code>// PHP < 5.3
print_r(array_filter($linksArray, create_function('$value', 'return $value !== "";')));

// PHP 5.3 and later
print_r(array_filter($linksArray, function($value) { return $value !== ''; }));
</code>```

Body:
Collection {#363 ▼
  #items: array:3 [▼
    0 => Tag {#376 ▶}
    1 => null
    2 => Tag {#374 ▶}
  ]
}

I want to remove the second key/pair element from this collection. How can I achieve this?

Body:
As you're dealing with an array of strings, you can simply use array_filter(), which conveniently handles all this for you:

print_r(array_filter($linksArray));

Keep in mind that if no callback is supplied, all entries of array equal to FALSE (see converting to boolean) will be removed. So if you need to preserve elements that are i.e. exact string '0', you will need a custom callback:

// PHP < 5.3
print_r(array_filter($linksArray, create_function('$value', 'return $value !== "";')));

// PHP 5.3 and later
print_r(array_filter($linksArray, function($value) { return $value !== ''; }));