问:
Enable autocomplete querying in ElasticSearch
I am trying to build an ElasticSearch index which will have documents with product names, for instance of laptops -

```<code>{ "name" : "Laptop Blue I7"}
</code>```

Then I want to use it for autocomplete suggestion by querying the ES index. I have 2 main constraints:

There can be Synonyms of the name -

I want to define Synonyms for terms, like "Notebook" for "Laptop"
The ingested documents can be of the following kind -

```<code>"Laptop Blue I7"
"Laptop Blue I7"
"Laptop Blue I7"
"Laptop Blue I7"
"Laptop Red I7"
"Laptop Red I7"
"Notebook Blue I7"
</code>```

Now, I am adding the following settings and mapping file while creating the index -

```<code>{
  "settings": {
    "index": {
      "analysis": {
        "filter" : {
                    "synonym" : {
                        "type" : "synonym",
                        "synonyms" : ["Laptop,Notebook"]
                    }
                },
        "analyzer": {
        "synonym" : {
                        "tokenizer" : "keyword",
                        "filter" : ["synonym"]
                    }
}}}},
"mappings": {
    "catalog": {
      "properties": {
        "name": {
          "type": "text",
          "analyzer": "synonym"
        }
      }
    }
  }
}

</code>```

Querying -

When I query the data, with "Notebook",
the preferred response should be ordered in terms of frequency and synonym. However, when I query, the response is normally independent of the synonym and frequency. I use the following query -

```<code>/_search
{"query": {
        "query_string" : {"default_field" : "name", "query" : "Notebook"}
            } }
</code>```

The response I get is -

```<code>"Notebook Blue I7"
</code>```

While I would hope the response to be either of the following -

```<code>"Laptop Blue I7"
"Laptop Red I7"
</code>```

or

```<code>"Notebook Blue I7"
"Laptop Blue I7"
"Laptop Red I7"
</code>```

Any insights in resolving this would be helpful. Thanks

========
Edit 1:

When I use \_analyze on "Notebook" the response is

```<code>{'tokens': [{'end_offset': 3,
             'position': 0,
             'start_offset': 0,
             'token': 'Notebook',
             'type': '<ALPHANUM>'},
            {'end_offset': 3,
             'position': 0,
             'start_offset': 0,
             'token': 'Laptop',
             'type': 'SYNONYM'}]}
</code>```

答:
Issue is with your keyword tokenizer which you have used in your synonym analyzer. Please do below things to debug your issue.

Check the tokens generated for your matched and unmatched documents using analyze API.

Use explain API, to understand how its generated tokens and how its matching against your inverted index.

If tokens generated for your documents in Inverted index match with the tokens generated from your search term, then elasticsearch will show it matched and explain query gives a lot of other information like how many documents in a shard matched the search term and its score etc.

Above is just a very basic steps to troubleshoot your issue, but you have not implemented a proper autocomplete search which in turn should return results for note and lapt in your case. To implement this you need to use edge n gram analyzer and this ES official post can help you implement this.

Let me know if you face any other issue or requires any clarification.

Body:
I am trying to build an ElasticSearch index which will have documents with product names, for instance of laptops -

{ "name" : "Laptop Blue I7"}

Then I want to use it for autocomplete suggestion by querying the ES index. I have 2 main constraints:

There can be Synonyms of the name -

I want to define Synonyms for terms, like "Notebook" for "Laptop"
The ingested documents can be of the following kind -

"Laptop Blue I7"
"Laptop Blue I7"
"Laptop Blue I7"
"Laptop Blue I7"
"Laptop Red I7"
"Laptop Red I7"
"Notebook Blue I7"

Now, I am adding the following settings and mapping file while creating the index -

{
  "settings": {
    "index": {
      "analysis": {
        "filter" : {
                    "synonym" : {
                        "type" : "synonym",
                        "synonyms" : ["Laptop,Notebook"]
                    }
                },
        "analyzer": {
        "synonym" : {
                        "tokenizer" : "keyword",
                        "filter" : ["synonym"]
                    }
}}}},
"mappings": {
    "catalog": {
      "properties": {
        "name": {
          "type": "text",
          "analyzer": "synonym"
        }
      }
    }
  }
}

Querying -

When I query the data, with "Notebook",
the preferred response should be ordered in terms of frequency and synonym. However, when I query, the response is normally independent of the synonym and frequency. I use the following query -

/_search
{"query": {
        "query_string" : {"default_field" : "name", "query" : "Notebook"}
            } }

The response I get is -

"Notebook Blue I7"

While I would hope the response to be either of the following -

"Laptop Blue I7"
"Laptop Red I7"

or

"Notebook Blue I7"
"Laptop Blue I7"
"Laptop Red I7"

Any insights in resolving this would be helpful. Thanks

========
Edit 1:

When I use \_analyze on "Notebook" the response is

{'tokens': [{'end_offset': 3,
             'position': 0,
             'start_offset': 0,
             'token': 'Notebook',
             'type': '<ALPHANUM>'},
            {'end_offset': 3,
             'position': 0,
             'start_offset': 0,
             'token': 'Laptop',
             'type': 'SYNONYM'}]}


来源: stackexchange

问:
Typing a HOC component connected with Redux
In my Route component i have a Layout HOC that have some components as Children. In this HOC, i render the Top and Side bars, and i also connect him to my redux store to get the current user and dispatch the logout action. The problem is i defined my Hoc's Props and put the children as ReactNode, my user as UserType and the logout action as a function. But in the Route component i get a error because a didn't pass the user and the action as props.

My HOC component

```<code>interface Props extends RouteComponentProps {
  children?: ReactNode
  user?: UserType
  logoutAction(): void
}

const AppLayout = (props: Props) => (
  <Layout>
    {/* <Sidebar {...props} /> */}
    <Layout>
      {/* <TopBar user={props.user} /> */}
      <Content
        style={{
          margin: '24px 16px',
          padding: 24,
          background: '#fff',
          minHeight: 280
        }}
      >
        {props.children}
      </Content>
    </Layout>
  </Layout>
)
const mapStateToProps = (state: AppStateType, ownProps: Props) => ({
  ...ownProps,
  user: state.auth.currentUser
})

const mapDispatchToProps = (dispatch: Dispatch) => ({
  logoutAction: () => dispatch(logoutUserSuccessAction())
})

export default withRouter(
  connect(
    mapStateToProps,
    mapDispatchToProps
  )(AppLayout)
)
</code>```

My Route Component

```<code>class Routes extends React.Component<Props> {
  componentDidMount = () => {
    this.props.fetchFields()
    // this.props.fetchQuestions();
  }

  render() {
    return (
      <div
        style={{
          display: 'flex',
          height: '100vh',
          flexDirection: 'column',
          width: '100vw'
        }}
      >
        <AppLayoutContainer>
          <React.Fragment>
            <Switch>
              <Route path="/" exact component={HomePageContainer} />

              <Route path="/login" exact component={LoginPageContainer} />
              {/* NEED AUTH HOC */}
              <Route path="/gerencia" component={GerenciaPageContainer} />
              <Route path="/relatorio" component={ReportPageContainer} />
              <Route path="/exportar" component={ExportPageContainer} />
            </Switch>
          </React.Fragment>
        </AppLayoutContainer>
      </div>
    )
  }
}
</code>```

The error i got:

```<code>Property 'logoutAction' is missing in type '{ children: Element; }' but required in type 'Readonly<Pick<Pick<Props, never> & Props, "user" | "children" | "logoutAction">>'.ts(2741)
AppLayoutContainer.tsx(20, 3): 'logoutAction' is declared here.
</code>```

I'm trying to type the connect function but i'm getting other error:

```<code>interface OwnProps extends RouteComponentProps {
  children?: ReactNode
  // user?: UserType
}

interface StateProps {
  user?: UserType
}

interface DispatchProps {
  logoutAction: () => void
}

type Props = StateProps & DispatchProps & OwnProps

const AppLayout = (props: Props) => (
  <Layout>
    {/* <Sidebar {...props} /> */}
    <Layout>
      {/* <TopBar {...props} /> */}
      <Content
        style={{
          margin: '24px 16px',
          padding: 24,
          background: '#fff',
          minHeight: 280
        }}
      >
        <Button onClick={() => props.logoutAction()}>Fazer Logout</Button>
        {props.children}
      </Content>
    </Layout>
  </Layout>
)

function mapStateToProps(
  state: AppStateType,
  ownProps: OwnProps
): StateProps & OwnProps {
  // ...ownProps,
  return {
    ...ownProps,
    user: state.auth.currentUser
  }
}

const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
  logoutAction: () => dispatch(logoutUserSuccessAction())
})

export default connect<StateProps, DispatchProps, void>(
  mapStateToProps,
  mapDispatchToProps
)(AppLayout)
</code>```

and i'm getting this error now:

```<code>Argument of type '(state: { auth: AuthReducerStateType; }, ownProps: OwnProps) => StateProps & OwnProps' is not assignable to parameter of type 'MapStateToPropsParam<StateProps, void, {}>'.
  Type '(state: { auth: AuthReducerStateType; }, ownProps: OwnProps) => StateProps & OwnProps' is not assignable to type 'MapStateToPropsFactory<StateProps, void, {}>'.
    Types of parameters 'state' and 'initialState' are incompatible.
      Property 'auth' is missing in type '{}' but required in type '{ auth: AuthReducerStateType; }'.ts(2345)
getReducers.ts(41, 3): 'auth' is declared here.
</code>```

答:
So logoutAction is provided by redux, not manually by you.

You've marked this prop as required. Typescript doesnt know it's redux component and it'll have this prop passed basing on mapDispatchToProps so it's complaining you didn't provide it

In such case, when some prop is provided by external lib (redux in your case) I usually mark it as optional (which makes sense because you don't really control this prop being passed)

```<code>interface Props extends RouteComponentProps {
  children?: ReactNode
  user?: UserType
  logoutAction()?: void // <<<--- ? added
}
</code>```

Should solve the issue

ContentLicense: CC BY-SA 4.0

Body:
In my Route component i have a Layout HOC that have some components as Children. In this HOC, i render the Top and Side bars, and i also connect him to my redux store to get the current user and dispatch the logout action. The problem is i defined my Hoc's Props and put the children as ReactNode, my user as UserType and the logout action as a function. But in the Route component i get a error because a didn't pass the user and the action as props.

My HOC component

interface Props extends RouteComponentProps {
  children?: ReactNode
  user?: UserType
  logoutAction(): void
}

const AppLayout = (props: Props) => (
  <Layout>
    {/* <Sidebar {...props} /> */}
    <Layout>
      {/* <TopBar user={props.user} /> */}
      <Content
        style={{
          margin: '24px 16px',
          padding: 24,
          background: '#fff',
          minHeight: 280
        }}
      >
        {props.children}
      </Content>
    </Layout>
  </Layout>
)
const mapStateToProps = (state: AppStateType, ownProps: Props) => ({
  ...ownProps,
  user: state.auth.currentUser
})

const mapDispatchToProps = (dispatch: Dispatch) => ({
  logoutAction: () => dispatch(logoutUserSuccessAction())
})

export default withRouter(
  connect(
    mapStateToProps,
    mapDispatchToProps
  )(AppLayout)
)

My Route Component

class Routes extends React.Component<Props> {
  componentDidMount = () => {
    this.props.fetchFields()
    // this.props.fetchQuestions();
  }

  render() {
    return (

        <AppLayoutContainer>
          <React.Fragment>
            <Switch>
              <Route path="/" exact component={HomePageContainer} />

              <Route path="/login" exact component={LoginPageContainer} />
              {/* NEED AUTH HOC */}
              <Route path="/gerencia" component={GerenciaPageContainer} />
              <Route path="/relatorio" component={ReportPageContainer} />
              <Route path="/exportar" component={ExportPageContainer} />
            </Switch>
          </React.Fragment>
        </AppLayoutContainer>

    )
  }
}

The error i got:

Property 'logoutAction' is missing in type '{ children: Element; }' but required in type 'Readonly<Pick<Pick<Props, never> & Props, "user" | "children" | "logoutAction">>'.ts(2741)
AppLayoutContainer.tsx(20, 3): 'logoutAction' is declared here.

I'm trying to type the connect function but i'm getting other error:

interface OwnProps extends RouteComponentProps {
  children?: ReactNode
  // user?: UserType
}

interface StateProps {
  user?: UserType
}

interface DispatchProps {
  logoutAction: () => void
}

type Props = StateProps & DispatchProps & OwnProps

const AppLayout = (props: Props) => (
  <Layout>
    {/* <Sidebar {...props} /> */}
    <Layout>
      {/* <TopBar {...props} /> */}
      <Content
        style={{
          margin: '24px 16px',
          padding: 24,
          background: '#fff',
          minHeight: 280
        }}
      >
        <Button onClick={() => props.logoutAction()}>Fazer Logout</Button>
        {props.children}
      </Content>
    </Layout>
  </Layout>
)

function mapStateToProps(
  state: AppStateType,
  ownProps: OwnProps
): StateProps & OwnProps {
  // ...ownProps,
  return {
    ...ownProps,
    user: state.auth.currentUser
  }
}

const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
  logoutAction: () => dispatch(logoutUserSuccessAction())
})

export default connect<StateProps, DispatchProps, void>(
  mapStateToProps,
  mapDispatchToProps
)(AppLayout)

and i'm getting this error now:

Argument of type '(state: { auth: AuthReducerStateType; }, ownProps: OwnProps) => StateProps & OwnProps' is not assignable to parameter of type 'MapStateToPropsParam<StateProps, void, {}>'.
  Type '(state: { auth: AuthReducerStateType; }, ownProps: OwnProps) => StateProps & OwnProps' is not assignable to type 'MapStateToPropsFactory<StateProps, void, {}>'.
    Types of parameters 'state' and 'initialState' are incompatible.
      Property 'auth' is missing in type '{}' but required in type '{ auth: AuthReducerStateType; }'.ts(2345)
getReducers.ts(41, 3): 'auth' is declared here.

Body:
So logoutAction is provided by redux, not manually by you.

You've marked this prop as required. Typescript doesnt know it's redux component and it'll have this prop passed basing on mapDispatchToProps so it's complaining you didn't provide it

In such case, when some prop is provided by external lib (redux in your case) I usually mark it as optional (which makes sense because you don't really control this prop being passed)

interface Props extends RouteComponentProps {
  children?: ReactNode
  user?: UserType
  logoutAction()?: void // <<<--- ? added
}

Should solve the issue


问:
Interacting with the Chrome V8 debugger protocol through .NET (ClearScript)
I'm maintaining an enterprise C# application that provides end-user extensibility through user-defined JavaScript functions (with a select few C# types/proxies exposed) (think financial algorithms).

We evaluate those functions using ClearScript (prevously we were using another library called Noesis however we've moved away from that).

I'd like to offer a way for end-users to perform very basic debugging of the scripts (through a web interface). At a minimum - inspect variables and step over/into functions.

I've successfully connected to the ClearScript engine w/ Chrome when running the app locally and have been able to step through the scripts - however I don't think the same would make sense for end users whilst running in production for various reasons:

Might be too tricky for them to set up

Possible difficulties with port allocation

Probable firewall issues

What I'd really like is a SignalR interface to the V8 debugger - the web-app would interact with the SignalR, and SignalR would interact with the V8 debugger.

Has anyone done something along these lines before?

Are there any relevant .NET libraries I should be looking at?

Am I right in my thoughts that this seems like a fairly big piece of work?

Any other advice?

答:
If you mentioned Chrome and Nodejs, You maybe know that Nodejs, Chrome and Edge support WebSocket naturally. Chrome and Edge better with all security options. For Nodejs you can find standard libraries like socket.io
  For the server side DotNet WebSocket
WebSocket protocol is linga franka today. </p>


问:
How to get variable (const?) value in other component in ReactJS?
I starting using React. I have a main file (App.js) where all logic comes and in that file, I have added routes (, , ) which loading different page by URL from other files (only content).

In App.js constructor I added the web3 package and write that in a variable (window, global variable) because that is only one way to get that variable in other components files. I don't want to use window variables, because every user can see that. I want to use const/var variables, but get that values in every single component files, but I don't want to load same web3 library (or to connect smart contracts in every single component file). How to do that?

答:
Assuming you mean everything web3 has. On your component file

```<code>import React from 'react';
import Web3 from 'web3';

const ComponentA () => {
    // Do what ever you want with Web3 and react code here
};

export default ComponentA;

</code>```

If you want the instance of web3 you created, maybe you could initialize web3 in its own file.

your own web3_instance.js

```<code>import Web3 from 'web3';

const web3Instance = new Web3();

export default web3Instance;
</code>```

Then import it to any component.

```<code>import React from 'react';
import web3Instance from '../path/to/web3instance.js';

const ComponentA () => {
    // Do what ever you want with web3Instance and react code here
};

export default ComponentA;
</code>```

Body:
Assuming you mean everything web3 has. On your component file

import React from 'react';
import Web3 from 'web3';

const ComponentA () => {
    // Do what ever you want with Web3 and react code here
};

export default ComponentA;

If you want the instance of web3 you created, maybe you could initialize web3 in its own file.

your own web3_instance.js

import Web3 from 'web3';

const web3Instance = new Web3();

export default web3Instance;

Then import it to any component.

import React from 'react';
import web3Instance from '../path/to/web3instance.js';

const ComponentA () => {
    // Do what ever you want with web3Instance and react code here
};

export default ComponentA;


问:
clone a git repository using git init, fetch, and checkout
Introduction

I'm doing experimentations using the popular libgit2 written in C.

I'm trying to do a clone but using an un-common way. In order, the git commands:

git init

git remote add origin https://repository.git

git fetch origin

git checkout master

By using git bash and the following commands, I can get an existing repository with all its history.

Question

Now, let's see my current C++ implementation. The following code is trying to copy the behaviour of the previous written git commands.

```<code>#define url         "https://repository.git"
#define path        "./"
#define user        "user"
#define pass        "pass"

/** credential callback **/
int credentials(git_cred **cred, const char *, const char *, unsigned int, void *) {
    return git_cred_userpass_plaintext_new(cred, user, pass);
}

class Git {
public:
    Git() {
        git_libgit2_init();
    }

    ~Git() {
        git_repository_free(repository);
        git_libgit2_shutdown();
    }

    void update() {
        init();
        fetch();
        checkout();
    }

private:
    void init() {
        assertSuccess(git_repository_init(&repository, path, GIT_CVAR_FALSE));

        git_remote *remote = nullptr;
        git_remote_callbacks options = GIT_REMOTE_CALLBACKS_INIT;

        assertSuccess(git_remote_create(&remote, repository, "origin", url));

        options.credentials = credentials;
        git_remote_connect(remote, GIT_DIRECTION_FETCH, &options, nullptr, nullptr);
    }

    void fetch() {
        git_remote* remote = nullptr;
        assertSuccess(git_remote_lookup(&remote, repository, "origin"));

        git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
        options.callbacks.credentials = credentials;
        assertSuccess(git_remote_fetch(remote, nullptr, &options, nullptr));
    }

    void checkout() {
        git_checkout_options options = GIT_CHECKOUT_OPTIONS_INIT;
        options.checkout_strategy = GIT_CHECKOUT_FORCE;

        assertSuccess(git_checkout_head(repository, &options));

        assertSuccess(git_checkout_index(repository, nullptr, &options));

        assertSuccess(git_repository_set_head(repository, "refs/heads/master"));
        git_object *treeish = nullptr;
        assertSuccess(git_revparse_single(&treeish, repository, "master"));
        assertSuccess(git_checkout_tree(repository, treeish, &options));
    }

    void assertSuccess(int error) {
        if (!error) return;

        const git_error *e = giterr_last();
        std::cout << "code: " << e->klass << " error: " << e->message << std::endl;
        exit(1);
    }

private:
    git_repository *repository = nullptr;
};

int main() {
    Git git;
    git.update();
    return 0;
}
</code>```

Obviously, this does not work. Running this program (calling Git().update()), I'm getting the following error during the checkout step:

```<code>code: 4 error: reference 'refs/heads/master' not found
</code>```

The git repository has been created and I can see the remote origin that has been set successfully though git bash. I can do a manual git checkout master from git bash so I guess my current implementation of checkout is a failure.

Could someone highlight me about this error? I couldn't find enough resources nor support on all found example on internet.

EDIT

Since testing my code might help, let me give my CMakeLists.txt for compile libgit2. (source code https://github.com/libgit2/libgit2)

```<code>cmake_minimum_required(VERSION 3.13)
project(test)

include_directories(libgit/include)
LINK_DIRECTORIES(${LIBSSH2_LIBRARY_DIRS})
add_subdirectory(libgit)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE Release)

add_executable(test src/Git.h)
target_link_libraries(test git2)
</code>```

答:
The missing link is that, since you're building a repository from scratch, your repository is still unborn (ie, its HEAD points to a non-existent refs/heads/master ref). On top of that, checkout's only concern in libgit2-land is about bringing out files from the ODB, it doesn't write or update references.

Hence, you are missing the step where git checkout uses (in all likelihood) git update-ref to make master point to origin/master's OID, and you can do that via git_reference_create and friends.

Something like the following (brain-compiled):

static int setup_tracking_branch(char *branch_name, git_reference *upstream)
{
    git_reference *tracking;
    git_oid up_oid = git_reference_target_peel(upstream);
    char *ui_name;

#if 0
    /* should be constructed from `upstream`. IIRC there are some
     * git_reference accessors that can help
     * (eg. `refs/remotes/origin/heads/master` is `origin/master`).
     */
#else
    ui_name = "origin/master";
#endif

    if (git_reference_create_matching(&tracking,
                                      git_reference_owner(upstream),
                                      branch_name, up_oid, 0, NULL, "branch: created from %s", ui_name) < 0 ||
        git_branch_set_upstream(tracking, git_reference_name(upstream)) < 0) {
        printf("failed to create remote-tracking branch\n");
        return -1;
    }

cleanup:
    git_reference_free(tracking);

    return 0;
}
```

This takes the name you want the new branch to be (-b), and the remote branch to track (-t), though it is clearly not a complete reimplementation, or even correct, so YMMV.

Body:
Introduction

I'm doing experimentations using the popular libgit2 written in C.

I'm trying to do a clone but using an un-common way. In order, the git commands:

git init

git remote add origin https://repository.git

git fetch origin

git checkout master

By using git bash and the following commands, I can get an existing repository with all its history.

Question

Now, let's see my current C++ implementation. The following code is trying to copy the behaviour of the previous written git commands.

#define url         "https://repository.git"
#define path        "./"
#define user        "user"
#define pass        "pass"

/** credential callback **/
int credentials(git_cred **cred, const char *, const char *, unsigned int, void *) {
    return git_cred_userpass_plaintext_new(cred, user, pass);
}

class Git {
public:
    Git() {
        git_libgit2_init();
    }

    ~Git() {
        git_repository_free(repository);
        git_libgit2_shutdown();
    }

    void update() {
        init();
        fetch();
        checkout();
    }

private:
    void init() {
        assertSuccess(git_repository_init(&repository, path, GIT_CVAR_FALSE));

        git_remote *remote = nullptr;
        git_remote_callbacks options = GIT_REMOTE_CALLBACKS_INIT;

        assertSuccess(git_remote_create(&remote, repository, "origin", url));

        options.credentials = credentials;
        git_remote_connect(remote, GIT_DIRECTION_FETCH, &options, nullptr, nullptr);
    }

    void fetch() {
        git_remote* remote = nullptr;
        assertSuccess(git_remote_lookup(&remote, repository, "origin"));

        git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
        options.callbacks.credentials = credentials;
        assertSuccess(git_remote_fetch(remote, nullptr, &options, nullptr));
    }

    void checkout() {
        git_checkout_options options = GIT_CHECKOUT_OPTIONS_INIT;
        options.checkout_strategy = GIT_CHECKOUT_FORCE;

        assertSuccess(git_checkout_head(repository, &options));

        assertSuccess(git_checkout_index(repository, nullptr, &options));

        assertSuccess(git_repository_set_head(repository, "refs/heads/master"));
        git_object *treeish = nullptr;
        assertSuccess(git_revparse_single(&treeish, repository, "master"));
        assertSuccess(git_checkout_tree(repository, treeish, &options));
    }

    void assertSuccess(int error) {
        if (!error) return;

        const git_error *e = giterr_last();
        std::cout << "code: " << e->klass << " error: " << e->message << std::endl;
        exit(1);
    }

private:
    git_repository *repository = nullptr;
};

int main() {
    Git git;
    git.update();
    return 0;
}

Obviously, this does not work. Running this program (calling Git().update()), I'm getting the following error during the checkout step:

code: 4 error: reference 'refs/heads/master' not found

The git repository has been created and I can see the remote origin that has been set successfully though git bash. I can do a manual git checkout master from git bash so I guess my current implementation of checkout is a failure.

Could someone highlight me about this error? I couldn't find enough resources nor support on all found example on internet.

EDIT

Since testing my code might help, let me give my CMakeLists.txt for compile libgit2. (source code https://github.com/libgit2/libgit2)

cmake_minimum_required(VERSION 3.13)
project(test)

include_directories(libgit/include)
LINK_DIRECTORIES(${LIBSSH2_LIBRARY_DIRS})
add_subdirectory(libgit)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE Release)

add_executable(test src/Git.h)
target_link_libraries(test git2)

Body:
The missing link is that, since you're building a repository from scratch, your repository is still unborn (ie, its HEAD points to a non-existent refs/heads/master ref). On top of that, checkout's only concern in libgit2-land is about bringing out files from the ODB, it doesn't write or update references.

Hence, you are missing the step where git checkout uses (in all likelihood) git update-ref to make master point to origin/master's OID, and you can do that via git_reference_create and friends.

Something like the following (brain-compiled):

static int setup_tracking_branch(char *branch_name, git_reference *upstream)
{
    git_reference *tracking;
    git_oid up_oid = git_reference_target_peel(upstream);
    char *ui_name;

#if 0
    /* should be constructed from `upstream`. IIRC there are some
     * git_reference accessors that can help
     * (eg. `refs/remotes/origin/heads/master` is `origin/master`).
     */
#else
    ui_name = "origin/master";
#endif

    if (git_reference_create_matching(&tracking,
                                      git_reference_owner(upstream),
                                      branch_name, up_oid, 0, NULL, "branch: created from %s", ui_name) < 0 ||
        git_branch_set_upstream(tracking, git_reference_name(upstream)) < 0) {
        printf("failed to create remote-tracking branch\n");
        return -1;
    }

cleanup:
    git_reference_free(tracking);

    return 0;
}

This takes the name you want the new branch to be (-b), and the remote branch to track (-t), though it is clearly not a complete reimplementation, or even correct, so YMMV.


问:
Drawing a half gauge/speedometer (JavaScript Canvas or Java Swing Example needed)
has anyone a javascript canvas or java swing example?

Something like this:
http://www.fmsinc.com/microsoftaccess/controls/components/gauges/gauge-half.gif

How should i draw the "separator" lines?

答:
I recommend looking into the Raphael Javascript graphics library. It works in all browsers (including old versions of IE!), and uses vector graphics, so the graphics it produces are scalable and rotatable without loss of image quality, and it even includes animation features.

Here's a link to a guy who's used Raphael to produce some very good-looking gauges:
http://techoctave.com/c7/posts/17-jquery-dashboard-gauges-using-raphael-xhtml-and-css

But if you want to draw your own, it shouldn't be hard to do using Raphael: It has the ability to draw cicles and shapes, and to animate them. Something that looks like your example shouldn't be hard to achieve.

Here's some code I've knocked together quickly as an example:

```<code><script type="text/javascript" src="raphael.js"></script>
<script type="text/javascript">
  var gauge = Raphael('mydiv', 200, 100);
  var semicircle = gauge.circle(100, 100, 100).attr({"fill": "#FF0000"});
  var indicator = gauge.rect(0, 99, 100, 2);
  indicator.animate({rotation: "30 100 100"}, 1000, "<>");
</script>
....
<div id='mydiv'></div>
</code>```

I've tested that code, and it produces a working dial. It's not as pretty as, say, the other example I linked above, but it doesn't use any external graphics, and it's done entirely using Javascript. The only external dependancy is the Raphael library.

It'll obviously need some work to improve it to make it usable for your scenario, but it should be a fairly good start for you.

Hope that helps.

[EDIT]

The above script works for Raphael v1.5. However, Raphael v2 changes the syntax slightly.

The line to do the animation needs to use the new transform syntax rather than the deprecated rotate syntax. So the edited line would look as follows:

```<code>indicator.animate({transform: "r30,100,100"}, 1000, "<>");
</code>```

The rest of the code remains the same as above.

See the Raphael manual for more information on the syntax of the transform function.

ContentLicense: CC BY-SA 2.5

Body:
I recommend looking into the Raphael Javascript graphics library. It works in all browsers (including old versions of IE!), and uses vector graphics, so the graphics it produces are scalable and rotatable without loss of image quality, and it even includes animation features.

Here's a link to a guy who's used Raphael to produce some very good-looking gauges:
http://techoctave.com/c7/posts/17-jquery-dashboard-gauges-using-raphael-xhtml-and-css

But if you want to draw your own, it shouldn't be hard to do using Raphael: It has the ability to draw cicles and shapes, and to animate them. Something that looks like your example shouldn't be hard to achieve.

Here's some code I've knocked together quickly as an example:

<script type="text/javascript" src="raphael.js"></script>
<script type="text/javascript">
  var gauge = Raphael('mydiv', 200, 100);
  var semicircle = gauge.circle(100, 100, 100).attr({"fill": "#FF0000"});
  var indicator = gauge.rect(0, 99, 100, 2);
  indicator.animate({rotation: "30 100 100"}, 1000, "<>");
</script>
....
<div id='mydiv'></div>

I've tested that code, and it produces a working dial. It's not as pretty as, say, the other example I linked above, but it doesn't use any external graphics, and it's done entirely using Javascript. The only external dependancy is the Raphael library.

It'll obviously need some work to improve it to make it usable for your scenario, but it should be a fairly good start for you.

Hope that helps.

[EDIT]

The above script works for Raphael v1.5. However, Raphael v2 changes the syntax slightly.

The line to do the animation needs to use the new transform syntax rather than the deprecated rotate syntax. So the edited line would look as follows:

indicator.animate({transform: "r30,100,100"}, 1000, "<>");

The rest of the code remains the same as above.

See the Raphael manual for more information on the syntax of the transform function.

ContentLicense: CC BY-SA 3.0


问:
python converting a List of Tuples into a Dict with external keys
I have a list of tuples like this

```<code>[
(1,'a'),
(2,'b'),
(3,'c'),
(4,'d'),
(5,'e')
]
</code>```

The result should be a list of dictionaries

```<code>[
{'id': 1, 'label': 'a'},
{'id': 2, 'label': 'b'},
{'id': 3, 'label': 'c'},
{'id': 4, 'label': 'd'},
{'id': 5, 'label': 'e'}
]
</code>```

I'm using python 3.6

The first value in every tuple is named as 'id' and the second value
in every tuple is named as 'label'.

I want to get the above result without using loop since the data will be huge.
Is there any built-in method to achieve my result?

答:
```<code>import itertools as it     # pip install itertools
ids=[]   # lists
a=[
(1,'a'),        # input
(2,'b'),
(3,'c'),
(4,'d'),
(5,'e')
]
for i, j in a :
#    for j in i:
    di=("id", i ,"label", j)
    ids.append(dict(it.zip_longest(*[iter(di)] * 2, fillvalue="")))
print(ids)
</code>```

```<code>output :

[{'id': 5, 'label': 'e'}, {'id': 5, 'label': 'e'}, {'id': 5, 'label': 'e'}, {'id': 5, 'label': 'e'}, {'id': 5, 'label': 'e'}]

</code>```

Body:
I have a list of tuples like this

[
(1,'a'),
(2,'b'),
(3,'c'),
(4,'d'),
(5,'e')
]

The result should be a list of dictionaries

[
{'id': 1, 'label': 'a'},
{'id': 2, 'label': 'b'},
{'id': 3, 'label': 'c'},
{'id': 4, 'label': 'd'},
{'id': 5, 'label': 'e'}
]

I'm using python 3.6

The first value in every tuple is named as 'id' and the second value
in every tuple is named as 'label'.

I want to get the above result without using loop since the data will be huge.
Is there any built-in method to achieve my result?

Body:
import itertools as it     # pip install itertools
ids=[]   # lists
a=[
(1,'a'),        # input
(2,'b'),
(3,'c'),
(4,'d'),
(5,'e')
]
for i, j in a :
#    for j in i:
    di=("id", i ,"label", j)
    ids.append(dict(it.zip_longest(*[iter(di)] * 2, fillvalue="")))
print(ids)

output :

[{'id': 5, 'label': 'e'}, {'id': 5, 'label': 'e'}, {'id': 5, 'label': 'e'}, {'id': 5, 'label': 'e'}, {'id': 5, 'label': 'e'}]


问:
WebAuthn across multiple subdomain
I'm trying to set up a WebAuthn authentication flow on my website, but I'm bumping into an issue. I want my users to be able to register their devices on the main website (www.domain.com) so it's easily accessible through their user settings. Authentication itself happens on a different subdomain through an IdP (sso.domain.com). This is where trouble began.

There's a couple of things I've tried:

Registration and authentication on www.scoutswechel.be, passing 'www.scoutswechel.be' as the rp.id for both => works.

Registration on www.scoutswechel.be, authentication on sso.scoutswechel.be, passing 'www.scoutswechel.be' as the rp.id for both => the authentication step fails as authenticator doesn't return any keys.

Registration on www.scoutswechel.be, authentication on sso.scoutswechel, passing those domains respectively as the rp.id => the authentication step fails as authenticator doesn't return any keys.

Registration on www.scoutswechel.be, authentication on sso.scoutswechel.be, passing 'scoutswechel.be' as rp.id for both => registration step already fails with differing errors for different browsers (eg 'key returned something unexpected (2)' in chrome).

If I understand the spec correctly, passing 'scoutswechel.be' should actually work as both domains are subdomains of the main domain (correct me if I'm wrong here).

I prepare my challenges with PHP and pass them to the page with ajax calls. My PHP scripts returns for example following value:

{
   "publicKey":{
      "challenge":[105,107,101,103,105,49,119,115,98,108,119,109,48,109,105,53],
      "user":{
         "name":"walter",
         "displayName":"Wouter Henderickx",
         "id":[49,48,51]
      },
      "rp":{
         "id":"scoutswechel.be",
         "name":"scoutswechel.be"
      },
      "pubKeyCredParams":[
         {
            "alg":-7,
            "type":"public-key"
         }
      ],
      "authenticatorSelection":{
         "authenticatorAttachment":"cross-platform",
         "requireResidentKey":false,
         "userVerification":"preferred"
      },
      "attestation":null,
      "timeout":60000,
      "excludeCredentials":[],
      "extensions":{
         "exts":true
      }
   },
   "b64challenge":"aWtlZ2kxd3NibHdtMG1pNQ"
}```
</div>
</div>
</p>

<p>I then convert the challenge and user.id to Uint8Array and pass the publickey part to:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>navigator.credentials.create({publicKey: key.publicKey}).
 then(function (aNewCredentialInfo) {
  do.stuff()
 })</code>```

How should I go about this? What values can I pass to the rp.id to get this working across both subdomains?

答:
In the end, I figured it out. These were all implementation issues on my end:

In the library I based my project of (https://github.com/davidearl/webauthn), there was a piece of javascript that compared the value of the rp.name to the origin. Since I was passing a non-domain name, this check was blocking further execution.

I was passing 'rpid' for the relying party identifier. However, this should have been 'rpId'. Since my authenticator couldn't find any credentials without an rpid, it didn't return anything and I wasn't authenticated.

Title: WebAuthn across multiple subdomain

Body:
I'm trying to set up a WebAuthn authentication flow on my website, but I'm bumping into an issue. I want my users to be able to register their devices on the main website (www.domain.com) so it's easily accessible through their user settings. Authentication itself happens on a different subdomain through an IdP (sso.domain.com). This is where trouble began.

There's a couple of things I've tried:

Registration and authentication on www.scoutswechel.be, passing 'www.scoutswechel.be' as the rp.id for both => works.

Registration on www.scoutswechel.be, authentication on sso.scoutswechel.be, passing 'www.scoutswechel.be' as the rp.id for both => the authentication step fails as authenticator doesn't return any keys.

Registration on www.scoutswechel.be, authentication on sso.scoutswechel, passing those domains respectively as the rp.id => the authentication step fails as authenticator doesn't return any keys.

Registration on www.scoutswechel.be, authentication on sso.scoutswechel.be, passing 'scoutswechel.be' as rp.id for both => registration step already fails with differing errors for different browsers (eg 'key returned something unexpected (2)' in chrome).

If I understand the spec correctly, passing 'scoutswechel.be' should actually work as both domains are subdomains of the main domain (correct me if I'm wrong here).

I prepare my challenges with PHP and pass them to the page with ajax calls. My PHP scripts returns for example following value:

{
   "publicKey":{
      "challenge":[105,107,101,103,105,49,119,115,98,108,119,109,48,109,105,53],
      "user":{
         "name":"walter",
         "displayName":"Wouter Henderickx",
         "id":[49,48,51]
      },
      "rp":{
         "id":"scoutswechel.be",
         "name":"scoutswechel.be"
      },
      "pubKeyCredParams":[
         {
            "alg":-7,
            "type":"public-key"
         }
      ],
      "authenticatorSelection":{
         "authenticatorAttachment":"cross-platform",
         "requireResidentKey":false,
         "userVerification":"preferred"
      },
      "attestation":null,
      "timeout":60000,
      "excludeCredentials":[],
      "extensions":{
         "exts":true
      }
   },
   "b64challenge":"aWtlZ2kxd3NibHdtMG1pNQ"
}

I then convert the challenge and user.id to Uint8Array and pass the publickey part to:

navigator.credentials.create({publicKey: key.publicKey}).
 then(function (aNewCredentialInfo) {
  do.stuff()
 })

How should I go about this? What values can I pass to the rp.id to get this working across both subdomains?


问:
How can I put something in the prompt and get the output inside of a node program?
I'm trying to use the World Time API in my program. However, to use that I need to write "curl http://worldtimeapi.org/api/timezone/:area/:location[/:region]" in the prompt and receive a output. How can I write and get the output?

I tried do something with console.log but without success.

答:
You can use fetch </p>

```<code>const fetch = require('node-fetch');

fetch('http://worldtimeapi.org/api/timezone/Europe/Amsterdam')
  .then(function(response) {
    return response.json(); // converts response to json
  })
  .then(function(data) {
    // do something with data here
     console.log(data)
  });
</code>```

Body:
You can use fetch

const fetch = require('node-fetch');

fetch('http://worldtimeapi.org/api/timezone/Europe/Amsterdam')
  .then(function(response) {
    return response.json(); // converts response to json
  })
  .then(function(data) {
    // do something with data here
     console.log(data)
  });


问:
How to solve loss = Nan issue in Keras LSTM network?
I am training a LSTM network using Keras with tensorflow as backend. The network is used for energy load forecasting with the size of the dataset being (32292,24). But as the program runs, I am getting Nan values for the loss right from the first epoch. How can I solve this problem ?

PS: as far as data preprocessing is concerned, I divided each value by 100000 as initially each value is a 4 or 5 digit number. As a result my values should come in the range of (0,1).

```<code>def build_model():
    model = Sequential()
    layers = [1, 50, 100, 1]
    model.add(LSTM(input_dim=layers[0],output_dim=layers[1],return_sequenc
    es = True))
    model.add(Dropout(0.2))
    model.add(LSTM(layers[2],return_sequences = False))
    model.add(Dropout(0.2))
    model.add(Dense(output_dim=layers[3]))
    model.add(Activation("linear"))

    start = time.time()
    model.compile(loss="mse", optimizer="rmsprop")
    print "Compilation Time : ", time.time() - start
return model
def run_network():
    global_start_time = time.time()
    epochs = 5000
    model = build_model()
    try:
        model.fit(x_train, y_train,batch_size = 400, nb_epoch=epochs,validation_split=0.05)
        predicted = model.predict(x_test)
        predicted = np.reshape(predicted, (predicted.size,))
        except KeyboardInterrupt:
        print 'Training duration (s) : ', time.time() - global_start_time
    try:
        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.plot(predicted[:100])
        plt.show()
    except Exception as e:
          print str(e)
          print 'Training duration (s) : ' , time.time() -   global_start_time

return model, y_test, predicted
</code>```

答: I changed the activation function of dense layer to 'softmax' (in my case it's about a multi-class classification), and it works.</p>

Body:
I am training a LSTM network using Keras with tensorflow as backend. The network is used for energy load forecasting with the size of the dataset being (32292,24). But as the program runs, I am getting Nan values for the loss right from the first epoch. How can I solve this problem ?

PS: as far as data preprocessing is concerned, I divided each value by 100000 as initially each value is a 4 or 5 digit number. As a result my values should come in the range of (0,1).

def build_model():
    model = Sequential()
    layers = [1, 50, 100, 1]
    model.add(LSTM(input_dim=layers[0],output_dim=layers[1],return_sequenc
    es = True))
    model.add(Dropout(0.2))
    model.add(LSTM(layers[2],return_sequences = False))
    model.add(Dropout(0.2))
    model.add(Dense(output_dim=layers[3]))
    model.add(Activation("linear"))

    start = time.time()
    model.compile(loss="mse", optimizer="rmsprop")
    print "Compilation Time : ", time.time() - start
return model
def run_network():
    global_start_time = time.time()
    epochs = 5000
    model = build_model()
    try:
        model.fit(x_train, y_train,batch_size = 400, nb_epoch=epochs,validation_split=0.05)
        predicted = model.predict(x_test)
        predicted = np.reshape(predicted, (predicted.size,))
        except KeyboardInterrupt:
        print 'Training duration (s) : ', time.time() - global_start_time
    try:
        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.plot(predicted[:100])
        plt.show()
    except Exception as e:
          print str(e)
          print 'Training duration (s) : ' , time.time() -   global_start_time

return model, y_test, predicted


问:
Does any one know where the RenderAction HtmlHelper is in ASP.NET MVC in RC1
Does anyone have an alternative to the RenderAction HtmlHelper seeing as it's gone in RC1.

I need to render a user control but use a different controller to populate the user control view.

How might this work now?

答:
Use the Microsoft.Web.Mvc namespace (known as MVC Futures) found in at http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=22359

It includes a HtmlHelper method (Html.RenderAction) which calls an action on a different controller.

OwnerDisplayName: Jeremy

OwnerDisplayName: JMs


问:
Java Hashtable .containsKey(String key) is returning true even when the strings and hashcodes are different... How?
I'm currently having some issues with my Hashtable in java, where FEightPuzzle is a class which I've created.

Inside my class I have a String which is storing the key for each instance. Now during my program when I check inside the Hashtable for duplicate instances I sometimes "find" some when really the found ones are different.

Take for example when I call bol.containsKey(current.key) where bol is a HT and current is an FEightPuzzle.

When this is true I check the values of the keys and they are

```<code>current.key =
"8 14 11 0 6 12 13 1 10 4 5 9 15 2 3 7"

bol.get(current.key).key =
"12 8 4 0 13 9 5 1 14 10 6 2 15 11 7 3"
</code>```

with values

```<code>current.key.hashCode() = -950607924

bol.get(current.key).key.hashCode() = -1856769042
</code>```

I'm sorry to bother you but this problem is really getting to me, and it was the last thing I expected tonight to be honest (don't you love that)... Any hints or answers would be greatly appreciated!

答: I think perhaps you're misunderstanding what Hashtable does. It maps keys to values. So calling get(key) on your key is going to return the value you provided with put(key, value). Now if you're always putting the same value in as the key you should expect the same thing, however in that case all you need is a HashSet. If you're putting the same values in for different keys, it is going to allow that. Only the keys are unique in a Hashtable (and HashMap is the same).

Body:
I'm currently having some issues with my Hashtable in java, where FEightPuzzle is a class which I've created.

Inside my class I have a String which is storing the key for each instance. Now during my program when I check inside the Hashtable for duplicate instances I sometimes "find" some when really the found ones are different.

Take for example when I call bol.containsKey(current.key) where bol is a HT and current is an FEightPuzzle.

When this is true I check the values of the keys and they are

current.key =
"8 14 11 0 6 12 13 1 10 4 5 9 15 2 3 7"

bol.get(current.key).key =
"12 8 4 0 13 9 5 1 14 10 6 2 15 11 7 3"

with values

current.key.hashCode() = -950607924

bol.get(current.key).key.hashCode() = -1856769042

I'm sorry to bother you but this problem is really getting to me, and it was the last thing I expected tonight to be honest (don't you love that)... Any hints or answers would be greatly appreciated!


问:
Why is Bufferedimage equaling null after a few iterations?
After a few iterations through my for loop, the Bufferedimage variable just receives a null. The first 2-3 times are usually fine.

I tried different mp4 files to see if it was just the videos having issues.

```<code>public void vidimg()throws IOException{
    Java2DFrameConverter converter = new Java2DFrameConverter();
    FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(mp4Path);

    Frame frame;
    int imgNum = 0;

    frameGrabber.start();

    System.out.println("Video has " + frameGrabber.getLengthInFrames() + " frames and has frame rate of "+ frameGrabber.getFrameRate());

    try {
        for(int i=frameJump;i<=frameGrabber.getLengthInFrames();i+=frameJump){
            imgNum++;
            frameGrabber.setFrameNumber(i);
            frame = frameGrabber.grab();
            BufferedImage bi = converter.convert(frame);
            String path = imgPath + File.separator + imgNum + ".jpg";
            ImageIO.write(bi, imgType, new File(path));
        }
        frameGrabber.stop();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
</code>```

I expected to receive images every 2 frames of the video, but I received a null error for Bufferedimage.

答:
did you consider that it's an information frame that has no graphical content?

Some data streams have no graphical content as briefly mentioned here

https://en.wikipedia.org/wiki/MPEG-4_Part_14

More info can be found by looking at a better, more in-depth format specification

This SO question has better pointers and links to the specification:
MP4 File Format Specification

Body:
After a few iterations through my for loop, the Bufferedimage variable just receives a null. The first 2-3 times are usually fine.

I tried different mp4 files to see if it was just the videos having issues.

public void vidimg()throws IOException{
    Java2DFrameConverter converter = new Java2DFrameConverter();
    FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(mp4Path);

    Frame frame;
    int imgNum = 0;

    frameGrabber.start();

    System.out.println("Video has " + frameGrabber.getLengthInFrames() + " frames and has frame rate of "+ frameGrabber.getFrameRate());

    try {
        for(int i=frameJump;i<=frameGrabber.getLengthInFrames();i+=frameJump){
            imgNum++;
            frameGrabber.setFrameNumber(i);
            frame = frameGrabber.grab();
            BufferedImage bi = converter.convert(frame);
            String path = imgPath + File.separator + imgNum + ".jpg";
            ImageIO.write(bi, imgType, new File(path));
        }
        frameGrabber.stop();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

I expected to receive images every 2 frames of the video, but I received a null error for Bufferedimage.


问:
How to flter XML BI Publisher report in RTF Template
How do I combine filter conditions in an RTF Template?

Desired filter condition:

```<code>APPLICATION=('AC','LD')
AND
CATEGORY=('1001','1002')
</code>```

I tried using <?for-each-group:G_1[contains(category,'1001')];./grouping_element?>, but it is filtering with only one condition.

答:
Refer Below & change accordingly,</p>

```<code><?for-each:G_MAIN?><?if@row:(contains(TASK_NUMBER,'-00-000') or contains(TASK_NUMBER,'0000'))?>
</code>```

Body:
How do I combine filter conditions in an RTF Template?

Desired filter condition:

APPLICATION=('AC','LD')
AND
CATEGORY=('1001','1002')

I tried using <?for-each-group:G_1[contains(category,'1001')];./grouping_element?>, but it is filtering with only one condition.

Body:
Refer Below & change accordingly,

<?for-each:G_MAIN?><?if@row:(contains(TASK_NUMBER,'-00-000') or contains(TASK_NUMBER,'0000'))?>


问:
plsql works in Sql Developer, but not in a liquibase change ORA-06550 PLS-00103
I have the following code that has no issue running in SQL Developer, but when I put inside a liquibase change and run it I get an error.

```<code>DECLARE
  seqval NUMBER;
BEGIN
  SELECT MAX(id) + 1 INTO seqval FROM T_SLS_ITEMS;
  execute immediate('CREATE SEQUENCE SEQ_SLS_ITEMS MINVALUE '||seqval||'');
END;
</code>```

and the changeset for it:

```<code>     <changeSet author="Cristian Marian (cmarian)" id="2019-05-24-171101 Fix Items sequence - creting">
        <sql>
          DECLARE
            seqval NUMBER;
          BEGIN
            SELECT MAX(id) + 1 INTO seqval FROM T_SLS_ITEMS;
            execute immediate('CREATE SEQUENCE SEQ_SLS_ITEMS MINVALUE '||seqval||'');
          END;
        </sql>
    </changeSet>
</code>```

The error looks like this:

```<code>Reason: liquibase.exception.DatabaseException: ORA-06550: line 2, column 27:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

   := . ( @ % ; not null range default character
 [Failed SQL: DECLARE
              seqval NUMBER] (Liquibase Update failed.)
</code>```

答:
Normally, dynamic SQL doesn't require statement terminator. I don't know Liquibase, but it seems that it does require it.

I'm not sure I understand what you meant by concatenating an empty string at the end:

```<code>execute immediate('CREATE SEQUENCE SEQ_SLS_ITEMS MINVALUE '||seqval||'');
                                                                      ^
                                                                 empty string?
</code>```

How about concatenating a semi-colon instead, i.e.

```<code>execute immediate('CREATE SEQUENCE SEQ_SLS_ITEMS MINVALUE '||seqval||';');
                                                                      ^
                                                                 semi-colon
</code>```

Body:
I have the following code that has no issue running in SQL Developer, but when I put inside a liquibase change and run it I get an error.

DECLARE
  seqval NUMBER;
BEGIN
  SELECT MAX(id) + 1 INTO seqval FROM T_SLS_ITEMS;
  execute immediate('CREATE SEQUENCE SEQ_SLS_ITEMS MINVALUE '||seqval||'');
END;

and the changeset for it:

     <changeSet author="Cristian Marian (cmarian)" id="2019-05-24-171101 Fix Items sequence - creting">
        <sql>
          DECLARE
            seqval NUMBER;
          BEGIN
            SELECT MAX(id) + 1 INTO seqval FROM T_SLS_ITEMS;
            execute immediate('CREATE SEQUENCE SEQ_SLS_ITEMS MINVALUE '||seqval||'');
          END;
        </sql>
    </changeSet>

The error looks like this:

Reason: liquibase.exception.DatabaseException: ORA-06550: line 2, column 27:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

   := . ( @ % ; not null range default character
 [Failed SQL: DECLARE
              seqval NUMBER] (Liquibase Update failed.)

Body:
Normally, dynamic SQL doesn't require statement terminator. I don't know Liquibase, but it seems that it does require it.

I'm not sure I understand what you meant by concatenating an empty string at the end:

execute immediate('CREATE SEQUENCE SEQ_SLS_ITEMS MINVALUE '||seqval||'');
                                                                      ^
                                                                 empty string?

How about concatenating a semi-colon instead, i.e.

execute immediate('CREATE SEQUENCE SEQ_SLS_ITEMS MINVALUE '||seqval||';');
                                                                      ^
                                                                 semi-colon


问:
mod_rewrite and mod_proxy together in Apache configuration
I am using Apache server for hosting my Angular application. So I enabled the single page application support with he following configuration

```<code><Location / >
   RewriteEngine on#
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule . /index.html [L]
</Location>
</code>```

Also I have a backend. I am using mod_proxy to proxy it with Apache.

```<code>ProxyPass "/api" "http://127.0.0.1:8081/api"
ProxyPassReverse "/api" "http://127.0.0.1:8081/api"
</code>```

But when I use both these configurations, I am unable to call any APIs.
All calls return index.html.

May I know what is wrong and how to fix it?

答:
Thanks @Dusan Bajic for the comment.

Now, I have the following config, and it works.

```<code>ProxyPass "/api" "http://127.0.0.1:8081/api"
ProxyPassReverse "/api" "http://127.0.0.1:8081/api"

<Location / >
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/api
    RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png)$ [NC]
    RewriteRule . /index.html [L]
</Location>
</code>```

Body:
I am using Apache server for hosting my Angular application. So I enabled the single page application support with he following configuration

<Location / >
   RewriteEngine on#
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule . /index.html [L]
</Location>

Also I have a backend. I am using mod_proxy to proxy it with Apache.

ProxyPass "/api" "http://127.0.0.1:8081/api"
ProxyPassReverse "/api" "http://127.0.0.1:8081/api"

But when I use both these configurations, I am unable to call any APIs.
All calls return index.html.

May I know what is wrong and how to fix it?

Body:
Thanks @Dusan Bajic for the comment.

Now, I have the following config, and it works.

ProxyPass "/api" "http://127.0.0.1:8081/api"
ProxyPassReverse "/api" "http://127.0.0.1:8081/api"

<Location / >
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/api
    RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png)$ [NC]
    RewriteRule . /index.html [L]
</Location>


问:
Datatable not searchable

Issue

I am currently using DataTables to display data to the user and I would quite like to be able to filter the data that is being displayed. So I have added textboxes to the top of the table columns.

I have followed the documentation but the code doesn't seem to be working. When typing something into the textboxes the table will flash and then just display all the results again. I have tried moving the function from the $(document).ready into my populate method with no luck. I then moved it into its own method with no success either; I tried calling the method after my data has been added.

Code

HTML with the text boxes:

```<code><table id="tblGrid" class="display" cellspacing="0" width="100%">
    <thead id="tblHead">
        <tr>
            <th><input type="text" class="form-control" placeholder="Search name" name="name" id="name" /></th>
            <th><input type="text" class="form-control" placeholder="Search surname" name="surname" id="surname" /></th>
            <th><input type="text" class="form-control" placeholder="Search ID number" name="idnum" id="idnum" /></th>
            <th><input type="text" class="form-control" placeholder="Search email" name="email" id="email" /></th>
            <th><input type="text" class="form-control" placeholder="Search status" name="status" id="status" /></th>
            <th><input type="text" class="form-control" placeholder="Search xxx" name="xxx" id="xxx" /></th>
            <th><input type="text" class="form-control" placeholder="Search relation" name="relation" id="relation" /></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
        </tr>
        <tr style="text-align:left;">
            <th>Name</th>
            <th>Surname</th>
            <th>ID Number</th>
            <th>Email</th>
            <th>Status</th>
            <th>XXX</th>
            <th>Relation</th>
            <th>EDIT</th>
            <th>MANAGE</th>
            <th>SMS</th>
            <th>EMAIL</th>
        </tr>
    </thead>
    <tbody id="tBody"></tbody>
    <tfoot id="tblFoot">
        <tr style="text-align:left;">
            <th>Name</th>
            <th>Surname</th>
            <th>ID Number</th>
            <th>Email</th>
            <th>Status</th>
            <th>XXX</th>
            <th>Relation</th>
            <th>EDIT</th>
            <th>MANAGE</th>
            <th>SMS</th>
            <th>EMAIL</th>
        </tr>
    </tfoot>
</table>
</code>```

Javascript for loading data and trying to filter:

```<code>function getPage() {
        let tBody = $("#tBody");
        tBody.empty();
        let Broker = $("#ddlBroker").val();

        $('#tblGrid').dataTable({
            "processing": true,
            "serverSide": true,
            "paging": true,
            "info": true,
            "stateSave": true,
            "lengthMenu": [[10, 20, 50, 100], [10, 20, 50, 100]],
            "ajax": {
                "url": "@($"{Request.Url?.Scheme}://{Request.Url.Authority}{Url.Content("~")}")/Member/AjaxGetJsonData",
                "type": "GET",
                "data": { "BRK": Broker }
            },
            "columns": [
                { "data": "Name" },
                { "data": "Surname" },
                { "data": "IDNum" },
                { "data": "Email" },
                { "data": "Status" },
                { "data": "XXXXXX" },
                { "data": "Relation" },
                { "data": "btnEDIT", sortable: false},
                { "data": "btnMANAGE", sortable: false },
                { "data": "btnSMS", sortable: false },
                { "data": "btnEMAIL", sortable: false }
            ],
            "order": [[5, "asc"]]
        });

        addFilter();
}
function addFilter() {
    // DataTable
    var table = $('#tblGrid').DataTable();

    // Apply the search
    table.columns().every( function () {
        var that = this;

        $( 'input' ).on( 'keyup change', function () {
            if (that.search() !== this.value) {
                console.log(this.value);
                that
                    .search( this.value )
                    .draw();
            }
        } );
    } );
}
</code>```

答:
I usually use this initComplete and create the select box and append it to the footer. You can find this in datatable documentation as well and this is not the only way to do it

$(document).ready(function() {
    // DataTable
    var table = $('#example').DataTable({
    initComplete: function() {
      this.api().columns().every(function() {
        var column = this;
        var select = $('<select><option value=""></option></select>')
          .appendTo($(column.footer()).empty())
          .on('change', function() {
            var val = $.fn.dataTable.util.escapeRegex(
              $(this).val()
            );

            column
              .search(val ? '^' + val + '$' : '', true, false)
              .draw();
          });

        column.data().unique().sort().each(function(d, j) {
          select.append('<option value="' + d + '">' + d + '</option>')
        });
      });
    }
    });

} );```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<table id="example" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Tiger Nixon</td>
                <td>System Architect</td>
                <td>Edinburgh</td>
                <td>61</td>
                <td>2011/04/25</td>
                <td>$320,800</td>
            </tr>
            <tr>
                <td>Garrett Winters</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>63</td>
                <td>2011/07/25</td>
                <td>$170,750</td>
            </tr>
            <tr>
                <td>Ashton Cox</td>
                <td>Junior Technical Author</td>
                <td>San Francisco</td>
                <td>66</td>
                <td>2009/01/12</td>
                <td>$86,000</td>
            </tr>
            <tr>
                <td>Cedric Kelly</td>
                <td>Senior Javascript Developer</td>
                <td>Edinburgh</td>
                <td>22</td>
                <td>2012/03/29</td>
                <td>$433,060</td>
            </tr>
            <tr>
                <td>Airi Satou</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>33</td>
                <td>2008/11/28</td>
                <td>$162,700</td>
            </tr>
            <tr>
                <td>Brielle Williamson</td>
                <td>Integration Specialist</td>
                <td>New York</td>
                <td>61</td>
                <td>2012/12/02</td>
                <td>$372,000</td>
            </tr>
            <tr>
                <td>Herrod Chandler</td>
                <td>Sales Assistant</td>
                <td>San Francisco</td>
                <td>59</td>
                <td>2012/08/06</td>
                <td>$137,500</td>
            </tr>
            <tr>
                <td>Rhona Davidson</td>
                <td>Integration Specialist</td>
                <td>Tokyo</td>
                <td>55</td>
                <td>2010/10/14</td>
                <td>$327,900</td>
            </tr>
            <tr>
                <td>Colleen Hurst</td>
                <td>Javascript Developer</td>
                <td>San Francisco</td>
                <td>39</td>
                <td>2009/09/15</td>
                <td>$205,500</td>
            </tr>
            <tr>
                <td>Sonya Frost</td>
                <td>Software Engineer</td>
                <td>Edinburgh</td>
                <td>23</td>
                <td>2008/12/13</td>
                <td>$103,600</td>
            </tr>
            <tr>
                <td>Jena Gaines</td>
                <td>Office Manager</td>
                <td>London</td>
                <td>30</td>
                <td>2008/12/19</td>
                <td>$90,560</td>
            </tr>
            <tr>
                <td>Quinn Flynn</td>
                <td>Support Lead</td>
                <td>Edinburgh</td>
                <td>22</td>
                <td>2013/03/03</td>
                <td>$342,000</td>
            </tr>
            <tr>
                <td>Charde Marshall</td>
                <td>Regional Director</td>
                <td>San Francisco</td>
                <td>36</td>
                <td>2008/10/16</td>
                <td>$470,600</td>
            </tr>
            <tr>
                <td>Haley Kennedy</td>
                <td>Senior Marketing Designer</td>
                <td>London</td>
                <td>43</td>
                <td>2012/12/18</td>
                <td>$313,500</td>
            </tr>
            <tr>
                <td>Tatyana Fitzpatrick</td>
                <td>Regional Director</td>
                <td>London</td>
                <td>19</td>
                <td>2010/03/17</td>
                <td>$385,750</td>
            </tr>
            <tr>
                <td>Michael Silva</td>
                <td>Marketing Designer</td>
                <td>London</td>
                <td>66</td>
                <td>2012/11/27</td>
                <td>$198,500</td>
            </tr>
            <tr>
                <td>Paul Byrd</td>
                <td>Chief Financial Officer (CFO)</td>
                <td>New York</td>
                <td>64</td>
                <td>2010/06/09</td>
                <td>$725,000</td>
            </tr>
            <tr>
                <td>Gloria Little</td>
                <td>Systems Administrator</td>
                <td>New York</td>
                <td>59</td>
                <td>2009/04/10</td>
                <td>$237,500</td>
            </tr>
            <tr>
                <td>Bradley Greer</td>
                <td>Software Engineer</td>
                <td>London</td>
                <td>41</td>
                <td>2012/10/13</td>
                <td>$132,000</td>
            </tr>
            <tr>
                <td>Dai Rios</td>
                <td>Personnel Lead</td>
                <td>Edinburgh</td>
                <td>35</td>
                <td>2012/09/26</td>
                <td>$217,500</td>
            </tr>
            <tr>
                <td>Jenette Caldwell</td>
                <td>Development Lead</td>
                <td>New York</td>
                <td>30</td>
                <td>2011/09/03</td>
                <td>$345,000</td>
            </tr>
            <tr>
                <td>Yuri Berry</td>
                <td>Chief Marketing Officer (CMO)</td>
                <td>New York</td>
                <td>40</td>
                <td>2009/06/25</td>
                <td>$675,000</td>
            </tr>
            <tr>
                <td>Caesar Vance</td>
                <td>Pre-Sales Support</td>
                <td>New York</td>
                <td>21</td>
                <td>2011/12/12</td>
                <td>$106,450</td>
            </tr>
            <tr>
                <td>Doris Wilder</td>
                <td>Sales Assistant</td>
                <td>Sidney</td>
                <td>23</td>
                <td>2010/09/20</td>
                <td>$85,600</td>
            </tr>
            <tr>
                <td>Angelica Ramos</td>
                <td>Chief Executive Officer (CEO)</td>
                <td>London</td>
                <td>47</td>
                <td>2009/10/09</td>
                <td>$1,200,000</td>
            </tr>
            <tr>
                <td>Gavin Joyce</td>
                <td>Developer</td>
                <td>Edinburgh</td>
                <td>42</td>
                <td>2010/12/22</td>
                <td>$92,575</td>
            </tr>
            <tr>
                <td>Jennifer Chang</td>
                <td>Regional Director</td>
                <td>Singapore</td>
                <td>28</td>
                <td>2010/11/14</td>
                <td>$357,650</td>
            </tr>
            <tr>
                <td>Brenden Wagner</td>
                <td>Software Engineer</td>
                <td>San Francisco</td>
                <td>28</td>
                <td>2011/06/07</td>
                <td>$206,850</td>
            </tr>
            <tr>
                <td>Fiona Green</td>
                <td>Chief Operating Officer (COO)</td>
                <td>San Francisco</td>
                <td>48</td>
                <td>2010/03/11</td>
                <td>$850,000</td>
            </tr>
            <tr>
                <td>Shou Itou</td>
                <td>Regional Marketing</td>
                <td>Tokyo</td>
                <td>20</td>
                <td>2011/08/14</td>
                <td>$163,000</td>
            </tr>
            <tr>
                <td>Michelle House</td>
                <td>Integration Specialist</td>
                <td>Sidney</td>
                <td>37</td>
                <td>2011/06/02</td>
                <td>$95,400</td>
            </tr>
            <tr>
                <td>Suki Burks</td>
                <td>Developer</td>
                <td>London</td>
                <td>53</td>
                <td>2009/10/22</td>
                <td>$114,500</td>
            </tr>
            <tr>
                <td>Prescott Bartlett</td>
                <td>Technical Author</td>
                <td>London</td>
                <td>27</td>
                <td>2011/05/07</td>
                <td>$145,000</td>
            </tr>
            <tr>
                <td>Gavin Cortez</td>
                <td>Team Leader</td>
                <td>San Francisco</td>
                <td>22</td>
                <td>2008/10/26</td>
                <td>$235,500</td>
            </tr>
            <tr>
                <td>Martena Mccray</td>
                <td>Post-Sales support</td>
                <td>Edinburgh</td>
                <td>46</td>
                <td>2011/03/09</td>
                <td>$324,050</td>
            </tr>
            <tr>
                <td>Unity Butler</td>
                <td>Marketing Designer</td>
                <td>San Francisco</td>
                <td>47</td>
                <td>2009/12/09</td>
                <td>$85,675</td>
            </tr>
            <tr>
                <td>Howard Hatfield</td>
                <td>Office Manager</td>
                <td>San Francisco</td>
                <td>51</td>
                <td>2008/12/16</td>
                <td>$164,500</td>
            </tr>
            <tr>
                <td>Hope Fuentes</td>
                <td>Secretary</td>
                <td>San Francisco</td>
                <td>41</td>
                <td>2010/02/12</td>
                <td>$109,850</td>
            </tr>
            <tr>
                <td>Vivian Harrell</td>
                <td>Financial Controller</td>
                <td>San Francisco</td>
                <td>62</td>
                <td>2009/02/14</td>
                <td>$452,500</td>
            </tr>
            <tr>
                <td>Timothy Mooney</td>
                <td>Office Manager</td>
                <td>London</td>
                <td>37</td>
                <td>2008/12/11</td>
                <td>$136,200</td>
            </tr>
            <tr>
                <td>Jackson Bradshaw</td>
                <td>Director</td>
                <td>New York</td>
                <td>65</td>
                <td>2008/09/26</td>
                <td>$645,750</td>
            </tr>
            <tr>
                <td>Olivia Liang</td>
                <td>Support Engineer</td>
                <td>Singapore</td>
                <td>64</td>
                <td>2011/02/03</td>
                <td>$234,500</td>
            </tr>
            <tr>
                <td>Bruno Nash</td>
                <td>Software Engineer</td>
                <td>London</td>
                <td>38</td>
                <td>2011/05/03</td>
                <td>$163,500</td>
            </tr>
            <tr>
                <td>Sakura Yamamoto</td>
                <td>Support Engineer</td>
                <td>Tokyo</td>
                <td>37</td>
                <td>2009/08/19</td>
                <td>$139,575</td>
            </tr>
            <tr>
                <td>Thor Walton</td>
                <td>Developer</td>
                <td>New York</td>
                <td>61</td>
                <td>2013/08/11</td>
                <td>$98,540</td>
            </tr>
            <tr>
                <td>Finn Camacho</td>
                <td>Support Engineer</td>
                <td>San Francisco</td>
                <td>47</td>
                <td>2009/07/07</td>
                <td>$87,500</td>
            </tr>
            <tr>
                <td>Serge Baldwin</td>
                <td>Data Coordinator</td>
                <td>Singapore</td>
                <td>64</td>
                <td>2012/04/09</td>
                <td>$138,575</td>
            </tr>
            <tr>
                <td>Zenaida Frank</td>
                <td>Software Engineer</td>
                <td>New York</td>
                <td>63</td>
                <td>2010/01/04</td>
                <td>$125,250</td>
            </tr>
            <tr>
                <td>Zorita Serrano</td>
                <td>Software Engineer</td>
                <td>San Francisco</td>
                <td>56</td>
                <td>2012/06/01</td>
                <td>$115,000</td>
            </tr>
            <tr>
                <td>Jennifer Acosta</td>
                <td>Junior Javascript Developer</td>
                <td>Edinburgh</td>
                <td>43</td>
                <td>2013/02/01</td>
                <td>$75,650</td>
            </tr>
            <tr>
                <td>Cara Stevens</td>
                <td>Sales Assistant</td>
                <td>New York</td>
                <td>46</td>
                <td>2011/12/06</td>
                <td>$145,600</td>
            </tr>
            <tr>
                <td>Hermione Butler</td>
                <td>Regional Director</td>
                <td>London</td>
                <td>47</td>
                <td>2011/03/21</td>
                <td>$356,250</td>
            </tr>
            <tr>
                <td>Lael Greer</td>
                <td>Systems Administrator</td>
                <td>London</td>
                <td>21</td>
                <td>2009/02/27</td>
                <td>$103,500</td>
            </tr>
            <tr>
                <td>Jonas Alexander</td>
                <td>Developer</td>
                <td>San Francisco</td>
                <td>30</td>
                <td>2010/07/14</td>
                <td>$86,500</td>
            </tr>
            <tr>
                <td>Shad Decker</td>
                <td>Regional Director</td>
                <td>Edinburgh</td>
                <td>51</td>
                <td>2008/11/13</td>
                <td>$183,000</td>
            </tr>
            <tr>
                <td>Michael Bruce</td>
                <td>Javascript Developer</td>
                <td>Singapore</td>
                <td>29</td>
                <td>2011/06/27</td>
                <td>$183,000</td>
            </tr>
            <tr>
                <td>Donna Snider</td>
                <td>Customer Support</td>
                <td>New York</td>
                <td>27</td>
                <td>2011/01/25</td>
                <td>$112,000</td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
    </table></code>```

Title: Datatable not searchable

Body:
Issue

I am currently using DataTables to display data to the user and I would quite like to be able to filter the data that is being displayed. So I have added textboxes to the top of the table columns.

I have followed the documentation but the code doesn't seem to be working. When typing something into the textboxes the table will flash and then just display all the results again. I have tried moving the function from the $(document).ready into my populate method with no luck. I then moved it into its own method with no success either; I tried calling the method after my data has been added.

Code

HTML with the text boxes:

            <input type="text" class="form-control" placeholder="Search name" name="name" id="name" />
            <input type="text" class="form-control" placeholder="Search surname" name="surname" id="surname" />
            <input type="text" class="form-control" placeholder="Search ID number" name="idnum" id="idnum" />
            <input type="text" class="form-control" placeholder="Search email" name="email" id="email" />
            <input type="text" class="form-control" placeholder="Search status" name="status" id="status" />
            <input type="text" class="form-control" placeholder="Search xxx" name="xxx" id="xxx" />
            <input type="text" class="form-control" placeholder="Search relation" name="relation" id="relation" />

            Name
            Surname
            ID Number
            Email
            Status
            XXX
            Relation
            EDIT
            MANAGE
            SMS
            EMAIL

            Name
            Surname
            ID Number
            Email
            Status
            XXX
            Relation
            EDIT
            MANAGE
            SMS
            EMAIL

Javascript for loading data and trying to filter:

function getPage() {
        let tBody = $("#tBody");
        tBody.empty();
        let Broker = $("#ddlBroker").val();

        $('#tblGrid').dataTable({
            "processing": true,
            "serverSide": true,
            "paging": true,
            "info": true,
            "stateSave": true,
            "lengthMenu": [[10, 20, 50, 100], [10, 20, 50, 100]],
            "ajax": {
                "url": "@($"{Request.Url?.Scheme}://{Request.Url.Authority}{Url.Content("~")}")/Member/AjaxGetJsonData",
                "type": "GET",
                "data": { "BRK": Broker }
            },
            "columns": [
                { "data": "Name" },
                { "data": "Surname" },
                { "data": "IDNum" },
                { "data": "Email" },
                { "data": "Status" },
                { "data": "XXXXXX" },
                { "data": "Relation" },
                { "data": "btnEDIT", sortable: false},
                { "data": "btnMANAGE", sortable: false },
                { "data": "btnSMS", sortable: false },
                { "data": "btnEMAIL", sortable: false }
            ],
            "order": [[5, "asc"]]
        });

        addFilter();
}
function addFilter() {
    // DataTable
    var table = $('#tblGrid').DataTable();

    // Apply the search
    table.columns().every( function () {
        var that = this;

        $( 'input' ).on( 'keyup change', function () {
            if (that.search() !== this.value) {
                console.log(this.value);
                that
                    .search( this.value )
                    .draw();
            }
        } );
    } );
}

Body:
I usually use this initComplete and create the select box and append it to the footer. You can find this in datatable documentation as well and this is not the only way to do it

$(document).ready(function() {
    // DataTable
    var table = $('#example').DataTable({
    initComplete: function() {
      this.api().columns().every(function() {
        var column = this;
        var select = $('<select><option value=""></option></select>')
          .appendTo($(column.footer()).empty())
          .on('change', function() {
            var val = $.fn.dataTable.util.escapeRegex(
              $(this).val()
            );

            column
              .search(val ? '^' + val + '$' : '', true, false)
              .draw();
          });

        column.data().unique().sort().each(function(d, j) {
          select.append('<option value="' + d + '">' + d + '</option>')
        });
      });
    }
    });

} );

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<table id="example" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Tiger Nixon</td>
                <td>System Architect</td>
                <td>Edinburgh</td>
                <td>61</td>
                <td>2011/04/25</td>
                <td>$320,800</td>
            </tr>
            <tr>
                <td>Garrett Winters</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>63</td>
                <td>2011/07/25</td>
                <td>$170,750</td>
            </tr>
            <tr>
                <td>Ashton Cox</td>
                <td>Junior Technical Author</td>
                <td>San Francisco</td>
                <td>66</td>
                <td>2009/01/12</td>
                <td>$86,000</td>
            </tr>
            <tr>
                <td>Cedric Kelly</td>
                <td>Senior Javascript Developer</td>
                <td>Edinburgh</td>
                <td>22</td>
                <td>2012/03/29</td>
                <td>$433,060</td>
            </tr>
            <tr>
                <td>Airi Satou</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>33</td>
                <td>2008/11/28</td>
                <td>$162,700</td>
            </tr>
            <tr>
                <td>Brielle Williamson</td>
                <td>Integration Specialist</td>
                <td>New York</td>
                <td>61</td>
                <td>2012/12/02</td>
                <td>$372,000</td>
            </tr>
            <tr>
                <td>Herrod Chandler</td>
                <td>Sales Assistant</td>
                <td>San Francisco</td>
                <td>59</td>
                <td>2012/08/06</td>
                <td>$137,500</td>
            </tr>
            <tr>
                <td>Rhona Davidson</td>
                <td>Integration Specialist</td>
                <td>Tokyo</td>
                <td>55</td>
                <td>2010/10/14</td>
                <td>$327,900</td>
            </tr>
            <tr>
                <td>Colleen Hurst</td>
                <td>Javascript Developer</td>
                <td>San Francisco</td>
                <td>39</td>
                <td>2009/09/15</td>
                <td>$205,500</td>
            </tr>
            <tr>
                <td>Sonya Frost</td>
                <td>Software Engineer</td>
                <td>Edinburgh</td>
                <td>23</td>
                <td>2008/12/13</td>
                <td>$103,600</td>
            </tr>
            <tr>
                <td>Jena Gaines</td>
                <td>Office Manager</td>
                <td>London</td>
                <td>30</td>
                <td>2008/12/19</td>
                <td>$90,560</td>
            </tr>
            <tr>
                <td>Quinn Flynn</td>
                <td>Support Lead</td>
                <td>Edinburgh</td>
                <td>22</td>
                <td>2013/03/03</td>
                <td>$342,000</td>
            </tr>
            <tr>
                <td>Charde Marshall</td>
                <td>Regional Director</td>
                <td>San Francisco</td>
                <td>36</td>
                <td>2008/10/16</td>
                <td>$470,600</td>
            </tr>
            <tr>
                <td>Haley Kennedy</td>
                <td>Senior Marketing Designer</td>
                <td>London</td>
                <td>43</td>
                <td>2012/12/18</td>
                <td>$313,500</td>
            </tr>
            <tr>
                <td>Tatyana Fitzpatrick</td>
                <td>Regional Director</td>
                <td>London</td>
                <td>19</td>
                <td>2010/03/17</td>
                <td>$385,750</td>
            </tr>
            <tr>
                <td>Michael Silva</td>
                <td>Marketing Designer</td>
                <td>London</td>
                <td>66</td>
                <td>2012/11/27</td>
                <td>$198,500</td>
            </tr>
            <tr>
                <td>Paul Byrd</td>
                <td>Chief Financial Officer (CFO)</td>
                <td>New York</td>
                <td>64</td>
                <td>2010/06/09</td>
                <td>$725,000</td>
            </tr>
            <tr>
                <td>Gloria Little</td>
                <td>Systems Administrator</td>
                <td>New York</td>
                <td>59</td>
                <td>2009/04/10</td>
                <td>$237,500</td>
            </tr>
            <tr>
                <td>Bradley Greer</td>
                <td>Software Engineer</td>
                <td>London</td>
                <td>41</td>
                <td>2012/10/13</td>
                <td>$132,000</td>
            </tr>
            <tr>
                <td>Dai Rios</td>
                <td>Personnel Lead</td>
                <td>Edinburgh</td>
                <td>35</td>
                <td>2012/09/26</td>
                <td>$217,500</td>
            </tr>
            <tr>
                <td>Jenette Caldwell</td>
                <td>Development Lead</td>
                <td>New York</td>
                <td>30</td>
                <td>2011/09/03</td>
                <td>$345,000</td>
            </tr>
            <tr>
                <td>Yuri Berry</td>
                <td>Chief Marketing Officer (CMO)</td>
                <td>New York</td>
                <td>40</td>
                <td>2009/06/25</td>
                <td>$675,000</td>
            </tr>
            <tr>
                <td>Caesar Vance</td>
                <td>Pre-Sales Support</td>
                <td>New York</td>
                <td>21</td>
                <td>2011/12/12</td>
                <td>$106,450</td>
            </tr>
            <tr>
                <td>Doris Wilder</td>
                <td>Sales Assistant</td>
                <td>Sidney</td>
                <td>23</td>
                <td>2010/09/20</td>
                <td>$85,600</td>
            </tr>
            <tr>
                <td>Angelica Ramos</td>
                <td>Chief Executive Officer (CEO)</td>
                <td>London</td>
                <td>47</td>
                <td>2009/10/09</td>
                <td>$1,200,000</td>
            </tr>
            <tr>
                <td>Gavin Joyce</td>
                <td>Developer</td>
                <td>Edinburgh</td>
                <td>42</td>
                <td>2010/12/22</td>
                <td>$92,575</td>
            </tr>
            <tr>
                <td>Jennifer Chang</td>
                <td>Regional Director</td>
                <td>Singapore</td>
                <td>28</td>
                <td>2010/11/14</td>
                <td>$357,650</td>
            </tr>
            <tr>
                <td>Brenden Wagner</td>
                <td>Software Engineer</td>
                <td>San Francisco</td>
                <td>28</td>
                <td>2011/06/07</td>
                <td>$206,850</td>
            </tr>
            <tr>
                <td>Fiona Green</td>
                <td>Chief Operating Officer (COO)</td>
                <td>San Francisco</td>
                <td>48</td>
                <td>2010/03/11</td>
                <td>$850,000</td>
            </tr>
            <tr>
                <td>Shou Itou</td>
                <td>Regional Marketing</td>
                <td>Tokyo</td>
                <td>20</td>
                <td>2011/08/14</td>
                <td>$163,000</td>
            </tr>
            <tr>
                <td>Michelle House</td>
                <td>Integration Specialist</td>
                <td>Sidney</td>
                <td>37</td>
                <td>2011/06/02</td>
                <td>$95,400</td>
            </tr>
            <tr>
                <td>Suki Burks</td>
                <td>Developer</td>
                <td>London</td>
                <td>53</td>
                <td>2009/10/22</td>
                <td>$114,500</td>
            </tr>
            <tr>
                <td>Prescott Bartlett</td>
                <td>Technical Author</td>
                <td>London</td>
                <td>27</td>
                <td>2011/05/07</td>
                <td>$145,000</td>
            </tr>
            <tr>
                <td>Gavin Cortez</td>
                <td>Team Leader</td>
                <td>San Francisco</td>
                <td>22</td>
                <td>2008/10/26</td>
                <td>$235,500</td>
            </tr>
            <tr>
                <td>Martena Mccray</td>
                <td>Post-Sales support</td>
                <td>Edinburgh</td>
                <td>46</td>
                <td>2011/03/09</td>
                <td>$324,050</td>
            </tr>
            <tr>
                <td>Unity Butler</td>
                <td>Marketing Designer</td>
                <td>San Francisco</td>
                <td>47</td>
                <td>2009/12/09</td>
                <td>$85,675</td>
            </tr>
            <tr>
                <td>Howard Hatfield</td>
                <td>Office Manager</td>
                <td>San Francisco</td>
                <td>51</td>
                <td>2008/12/16</td>
                <td>$164,500</td>
            </tr>
            <tr>
                <td>Hope Fuentes</td>
                <td>Secretary</td>
                <td>San Francisco</td>
                <td>41</td>
                <td>2010/02/12</td>
                <td>$109,850</td>
            </tr>
            <tr>
                <td>Vivian Harrell</td>
                <td>Financial Controller</td>
                <td>San Francisco</td>
                <td>62</td>
                <td>2009/02/14</td>
                <td>$452,500</td>
            </tr>
            <tr>
                <td>Timothy Mooney</td>
                <td>Office Manager</td>
                <td>London</td>
                <td>37</td>
                <td>2008/12/11</td>
                <td>$136,200</td>
            </tr>
            <tr>
                <td>Jackson Bradshaw</td>
                <td>Director</td>
                <td>New York</td>
                <td>65</td>
                <td>2008/09/26</td>
                <td>$645,750</td>
            </tr>
            <tr>
                <td>Olivia Liang</td>
                <td>Support Engineer</td>
                <td>Singapore</td>
                <td>64</td>
                <td>2011/02/03</td>
                <td>$234,500</td>
            </tr>
            <tr>
                <td>Bruno Nash</td>
                <td>Software Engineer</td>
                <td>London</td>
                <td>38</td>
                <td>2011/05/03</td>
                <td>$163,500</td>
            </tr>
            <tr>
                <td>Sakura Yamamoto</td>
                <td>Support Engineer</td>
                <td>Tokyo</td>
                <td>37</td>
                <td>2009/08/19</td>
                <td>$139,575</td>
            </tr>
            <tr>
                <td>Thor Walton</td>
                <td>Developer</td>
                <td>New York</td>
                <td>61</td>
                <td>2013/08/11</td>
                <td>$98,540</td>
            </tr>
            <tr>
                <td>Finn Camacho</td>
                <td>Support Engineer</td>
                <td>San Francisco</td>
                <td>47</td>
                <td>2009/07/07</td>
                <td>$87,500</td>
            </tr>
            <tr>
                <td>Serge Baldwin</td>
                <td>Data Coordinator</td>
                <td>Singapore</td>
                <td>64</td>
                <td>2012/04/09</td>
                <td>$138,575</td>
            </tr>
            <tr>
                <td>Zenaida Frank</td>
                <td>Software Engineer</td>
                <td>New York</td>
                <td>63</td>
                <td>2010/01/04</td>
                <td>$125,250</td>
            </tr>
            <tr>
                <td>Zorita Serrano</td>
                <td>Software Engineer</td>
                <td>San Francisco</td>
                <td>56</td>
                <td>2012/06/01</td>
                <td>$115,000</td>
            </tr>
            <tr>
                <td>Jennifer Acosta</td>
                <td>Junior Javascript Developer</td>
                <td>Edinburgh</td>
                <td>43</td>
                <td>2013/02/01</td>
                <td>$75,650</td>
            </tr>
            <tr>
                <td>Cara Stevens</td>
                <td>Sales Assistant</td>
                <td>New York</td>
                <td>46</td>
                <td>2011/12/06</td>
                <td>$145,600</td>
            </tr>
            <tr>
                <td>Hermione Butler</td>
                <td>Regional Director</td>
                <td>London</td>
                <td>47</td>
                <td>2011/03/21</td>
                <td>$356,250</td>
            </tr>
            <tr>
                <td>Lael Greer</td>
                <td>Systems Administrator</td>
                <td>London</td>
                <td>21</td>
                <td>2009/02/27</td>
                <td>$103,500</td>
            </tr>
            <tr>
                <td>Jonas Alexander</td>
                <td>Developer</td>
                <td>San Francisco</td>
                <td>30</td>
                <td>2010/07/14</td>
                <td>$86,500</td>
            </tr>
            <tr>
                <td>Shad Decker</td>
                <td>Regional Director</td>
                <td>Edinburgh</td>
                <td>51</td>
                <td>2008/11/13</td>
                <td>$183,000</td>
            </tr>
            <tr>
                <td>Michael Bruce</td>
                <td>Javascript Developer</td>
                <td>Singapore</td>
                <td>29</td>
                <td>2011/06/27</td>
                <td>$183,000</td>
            </tr>
            <tr>
                <td>Donna Snider</td>
                <td>Customer Support</td>
                <td>New York</td>
                <td>27</td>
                <td>2011/01/25</td>
                <td>$112,000</td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
    </table>