问:
Call a controller method in a view
I've got an asp.net core application in Visual studio.
In a auto-created view (Events/index.cshtml) I want to call this method from the EventsController.cs

```<code>public Boolean IsInRole(string Role)
{
    Boolean roleMembership = false;

    if (HttpContext.Session.GetInt32("ID") != null)
    {
        if (HttpContext.Session.GetString("Role") == Role)
        {
            roleMembership = true;
        }
    }

    return roleMembership;
}
</code>```

My idea was to call this method at the top of the view with

```<code>@if(IsInRole("Admin")) {
    show some content
}
</code>```

How can I achieve this task?

答:
You may move that logic to a separate class. Since this code is using HttpContext.Session, it is a good idea to create an interface for your class and let this class be your concrete implementation using HttpContext.Session. You can inject the needed implementation in your controller or view using the Dependency Injection framework.

```<code>public interface IUserAccessHelper
{
    bool IsInRole(string role);
}
public class UserAccessHelper : IUserAccessHelper
{
    private readonly IHttpContextAccessor httpContextAccessor;

    public UserAccessHelper(IHttpContextAccessor httpContextAccessor)
    {
        this.httpContextAccessor = httpContextAccessor;
    }
    public Boolean IsInRole(string role)
    {
        Boolean roleMembership = false;

        if (httpContextAccessor.HttpContext.Session.GetInt32("ID") != null)
        {
            if (httpContextAccessor.HttpContext.Session.GetString("Role") == role)
            {
                roleMembership = true;
            }
        }
        return roleMembership;
    }
}
</code>```

Now make sure to to register this in the ConfigureServices method in Startup.cs

```<code>services.AddTransient<IUserAccessHelper, UserAccessHelper>();
</code>```

Now in the razor view, you can inject this dependency. Yes, DI is possible in views now :)

```<code>@inject IUserAccessHelper UserAccessHelper
@if (UserAccessHelper.IsInRole("SomeRole"))
{
    <h2>In Role</h2>
}
else
{
    <h2>Not in Role</h2>
 }
</code>```

You can inject the same IUserAccessHelper inside your controller via constructor injection.

```<code>public class HomeController : Controller
{
    private readonly IUserAccessHelper userAccessHelper;
    public HomeController(IUserAccessHelper userAccessHelper)
    {
        this.userAccessHelper = userAccessHelper;
    }
    public ActionResult Create()
    {
       // you can use this.userAccessHelper.IsInRole("abc")
       // to do  :return something
    }
}
</code>```

Since you are injecting the needed implementation via dependency injection, now you can unit test your controller method. Your controller code does not have any tight coupling to HttpContext now. You can create a MockUserAccessHelper (which does not use HttpContext) for your unit tests and use that as needed.

Title: Call a controller method in a view

Body:
I've got an asp.net core application in Visual studio.
In a auto-created view (Events/index.cshtml) I want to call this method from the EventsController.cs

public Boolean IsInRole(string Role)
{
    Boolean roleMembership = false;

    if (HttpContext.Session.GetInt32("ID") != null)
    {
        if (HttpContext.Session.GetString("Role") == Role)
        {
            roleMembership = true;
        }
    }

    return roleMembership;
}

My idea was to call this method at the top of the view with

@if(IsInRole("Admin")) {
    show some content
}

How can I achieve this task?

Body:
You may move that logic to a separate class. Since this code is using HttpContext.Session, it is a good idea to create an interface for your class and let this class be your concrete implementation using HttpContext.Session. You can inject the needed implementation in your controller or view using the Dependency Injection framework.

public interface IUserAccessHelper
{
    bool IsInRole(string role);
}
public class UserAccessHelper : IUserAccessHelper
{
    private readonly IHttpContextAccessor httpContextAccessor;

    public UserAccessHelper(IHttpContextAccessor httpContextAccessor)
    {
        this.httpContextAccessor = httpContextAccessor;
    }
    public Boolean IsInRole(string role)
    {
        Boolean roleMembership = false;

        if (httpContextAccessor.HttpContext.Session.GetInt32("ID") != null)
        {
            if (httpContextAccessor.HttpContext.Session.GetString("Role") == role)
            {
                roleMembership = true;
            }
        }
        return roleMembership;
    }
}

Now make sure to to register this in the ConfigureServices method in Startup.cs

services.AddTransient<IUserAccessHelper, UserAccessHelper>();

Now in the razor view, you can inject this dependency. Yes, DI is possible in views now :)

@inject IUserAccessHelper UserAccessHelper
@if (UserAccessHelper.IsInRole("SomeRole"))
{
    <h2>In Role</h2>
}
else
{
    <h2>Not in Role</h2>
 }

You can inject the same IUserAccessHelper inside your controller via constructor injection.

public class HomeController : Controller
{
    private readonly IUserAccessHelper userAccessHelper;
    public HomeController(IUserAccessHelper userAccessHelper)
    {
        this.userAccessHelper = userAccessHelper;
    }
    public ActionResult Create()
    {
       // you can use this.userAccessHelper.IsInRole("abc")
       // to do  :return something
    }
}

Since you are injecting the needed implementation via dependency injection, now you can unit test your controller method. Your controller code does not have any tight coupling to HttpContext now. You can create a MockUserAccessHelper (which does not use HttpContext) for your unit tests and use that as needed.


来源: stackexchange

问:
Programmatic SMS
What is the best way to programmatically send an SMS text message?

Are there any free Web Service based SMS gateways?

I know that if I happen to know the user's carrier (Sprint, AT&T, etc), I can send an SMS by emailing an address based on phone number + carrier. I would like a good solution that does not require me to know the carrier. Barring that, is there an easy way to lookup carrier given a cell phone number?

I understand that there are some services independent of the major mobile carriers that offer a per-message fee-based service, with API. What I would like to know is how such organizations tap into the SMS networks. Do they have contracts with mobile carriers to resell their services?

答:
Use http://www.twilio.com/

They have a REST interface to send SMS's and even to establish phone calls or receive phone calls.

You even get 30$ credits to try it out.

Def. the cheapest solution you will find.

ContentLicense: CC BY-SA 2.5

Title: Programmatic SMS

LastEditorDisplayName: martinatime


问:
React Native Router - Element type is invalid
I'm trying to make routes for the different pages in my React Native app. So I've created a router.js file with a new Router:

// @flow

import React, { Component } from 'react';
import View from 'react-native';
import { NativeRouter, Route, Link } from 'react-router-native'
import PropTypes from 'prop-types';

import Splash from './components/Splash';
import Home from './components/Home';

class Router extends Component {

    componentWillMount() {
        navigator = this.context.history;
    }

    /**
     * Render
     * @return {XML} JSX
     */
    render() {
        return (
            <View style={{flex: 1}}>
                <Route exact path="/" component={Splash}/>
                <Route exact path="/home" component={Home}/>
            </View>
        );
    }
}

export default Router;```
</div>
</div>
</p>

<p>And then I've imported the router in my Splash Component. From there I want a button to redirect the user to the home screen.</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>import React, { Component } from 'react';
import { View, Text, Image, Button } from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
import { NativeRouter, Route, Link, Switch } from 'react-router-native'
import Home from "./Home";
import Router from "../router";

class Splash extends Component {

    render() {
        return(
            <View style={ styles.container }>
                <Router>
                    <Button onPress={() => navigator.push('/home')}
                            title="Go to home" />
                </Router>
            </View>
        );
    }
}

export default Splash;</code>```

But I get the following error:

```<code>Invariant Violation: Element type is invalid expected a string (for built-in components) or a class/function (for composite components) but got: object

Check the render method of 'Router'
</code>```

This is my first time using React Native Router and I don't get it working. Does someone know the best solution to make a simple router to navigate between screens?

答:
It seems to be the components you are passing in. In the docs:

https://github.com/jmurzy/react-router-native

the components are just done like this:

```<code>const Detail = (props) => (
  <View style={[styles.component, { backgroundColor: '#FFFFFF' }]}>
  {props.children}</View>
);
</code>```

you seem to be importing a file and passing a reference to that in. Try doing it as per the docs above and see if that resolves it.

ContentLicense: CC BY-SA 3.0

Body:
I'm trying to make routes for the different pages in my React Native app. So I've created a router.js file with a new Router:

// @flow

import React, { Component } from 'react';
import View from 'react-native';
import { NativeRouter, Route, Link } from 'react-router-native'
import PropTypes from 'prop-types';

import Splash from './components/Splash';
import Home from './components/Home';

class Router extends Component {

    componentWillMount() {
        navigator = this.context.history;
    }

    /**
     * Render
     * @return {XML} JSX
     */
    render() {
        return (
            <View style={{flex: 1}}>
                <Route exact path="/" component={Splash}/>
                <Route exact path="/home" component={Home}/>
            </View>
        );
    }
}

export default Router;

And then I've imported the router in my Splash Component. From there I want a button to redirect the user to the home screen.

import React, { Component } from 'react';
import { View, Text, Image, Button } from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
import { NativeRouter, Route, Link, Switch } from 'react-router-native'
import Home from "./Home";
import Router from "../router";

class Splash extends Component {

    render() {
        return(
            <View style={ styles.container }>
                <Router>
                    <Button onPress={() => navigator.push('/home')}
                            title="Go to home" />
                </Router>
            </View>
        );
    }
}

export default Splash;

But I get the following error:

Invariant Violation: Element type is invalid expected a string (for built-in components) or a class/function (for composite components) but got: object

Check the render method of 'Router'

This is my first time using React Native Router and I don't get it working. Does someone know the best solution to make a simple router to navigate between screens?

Body:
It seems to be the components you are passing in. In the docs:

https://github.com/jmurzy/react-router-native

the components are just done like this:

const Detail = (props) => (
  <View style={[styles.component, { backgroundColor: '#FFFFFF' }]}>
  {props.children}</View>
);

you seem to be importing a file and passing a reference to that in. Try doing it as per the docs above and see if that resolves it.


问:
JWT Spring - user based access
I'm implementing JWT based authentication in my Spring boot application. I have an Accounts table which contains user's bank account info. Now, the user signs in using Account number and pin from that table. The problem is that after logging in, user can access anything with the token assigned to it by JWT. He can even change someone else's account info. How can I restrict the access only to the user for which the token is created?

Every user should be able to access info associated with that user only, so creating roles is not an option. Does JWT provides any such feature or do i have to check the tokens manually? I can parse the token and retrieve the account number out of it and compare it with the account number passed in controller methods, but it doesn't seem like a neat solution as this will require changing every Controller method.

答:
As security in your case depends on business logic I guess there is no way to perform such verification on the Auth provider side.

What you can do is to implement it with the help of the Spring in AOP way quite elegant. You could use spring method security  with custom securiry resolver

```<code>@PreAuthorize("@securityResolver.isOwner(#userId)")
void changeAccount(UUID userId, Request body);

@Component("securityResolver")
public class CustomSecurityResolver {

     public boolean isOwner(final String userId) {
      //TODO business check here
     }

}
</code>```

You could even pass JWT token to the security resolver method and implement custom check. In this case you can avoid changing business logic of your service and just add couple of annotations with custom resolver.

I've always implemented such checks as user could only change its own info or tenant isolation with the help of custom method security

Title: JWT Spring - user based access

Body:
As security in your case depends on business logic I guess there is no way to perform such verification on the Auth provider side.

What you can do is to implement it with the help of the Spring in AOP way quite elegant. You could use spring method security  with custom securiry resolver

@PreAuthorize("@securityResolver.isOwner(#userId)")
void changeAccount(UUID userId, Request body);

@Component("securityResolver")
public class CustomSecurityResolver {

     public boolean isOwner(final String userId) {
      //TODO business check here
     }

}

You could even pass JWT token to the security resolver method and implement custom check. In this case you can avoid changing business logic of your service and just add couple of annotations with custom resolver.

I've always implemented such checks as user could only change its own info or tenant isolation with the help of custom method security


问:
ASP.NET Core 2 all users password reset as admin
I'm looking for a possibility to reset the password for all users in a database. Is it anyhow possible? All I have found so far, was about enabling password reset for the user himself, but it's not that I need.

I need to force old user to recreate a password for our app. Maybe there are some better solutions?

答:
If you need to do a global password reset, what you should do is create a function that generates random cryptographically secure passwords and simply change each user's password to those random ones (not just one, generate a password for each user). This essentially causes a global lockout, since no user will then be able to login, since they won't know this password.

Afterwards, you should send an mass email indicating that passwords have been reset and directing users to your password reset page. They'll essentially just act as if they've forgotten their password, and go through the normal process of submitting their email, clicking the link with a token in the email that gets sent, and then setting a new password.

You should also update your sign in failure message temporarily to indicate that all users must reset their password, so if someone misses the email, they'll know why their password isn't working and what they need to do to fix it.


问:
determinate which css is loaded with jQuery
I have html page that loads different css, depending on screen width (targeting pc, tablets and phones):

```<code><meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="all" href="css/style.css" >
<link rel="stylesheet" type="text/css" media="screen and (min-width: 1200px)" href="css/desktop-style.css" >
<link rel="stylesheet" type="text/css" media="screen and (min-width: 769px) and (max-width: 1199px)" href="css/tablet-style.css" >
<link rel="stylesheet" type="text/css" media="screen and (min-width: 100px) and (max-width: 768px)" href="css/phone-style.css" >
</code>```

I heavily depend on jQuery, and functions should be chosen depending on active css. Is there a way in JavaScript of jQuery to determinate which css is active?
Or should I use jQuery to determinate browser width, and make further functions depending on width output?
Thank you.

答:
It is probably wiser to check the widh of the device. But I think you could figure out which css is used, by this little 'hack'. In each css you give a nonsense property to a hidden element.

In the example I gave #canary the animation name first-css.

In a different css file you could write

```<code>#canary {animation-name: second-css; display: none}
</code>```

You could give a unique property to a certain element in each css file. JQuery could check that property.

$(function() {
whichcss=$("#canary").css("animation-name");
$("#output").text(whichcss);
})```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#canary {animation-name: first-css; display: none}</code>```

```
</div>
</div>
</p>

<p>To be extra clear. In your css files you should include th name of the css file in this way: </p>

<p>in desktop-style.css: </p>

```#canary {animation-name: desktop-css; display: none}
```

<p>in tablet-style.css: </p>

```#canary {animation-name: tablet-css; display: none}
```

<p>in phone-style.css: </p>

```#canary {animation-name: phone-css; display: none}
```

Body:
I have html page that loads different css, depending on screen width (targeting pc, tablets and phones):

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="all" href="css/style.css" >
<link rel="stylesheet" type="text/css" media="screen and (min-width: 1200px)" href="css/desktop-style.css" >
<link rel="stylesheet" type="text/css" media="screen and (min-width: 769px) and (max-width: 1199px)" href="css/tablet-style.css" >
<link rel="stylesheet" type="text/css" media="screen and (min-width: 100px) and (max-width: 768px)" href="css/phone-style.css" >

I heavily depend on jQuery, and functions should be chosen depending on active css. Is there a way in JavaScript of jQuery to determinate which css is active?
Or should I use jQuery to determinate browser width, and make further functions depending on width output?
Thank you.

Body:
It is probably wiser to check the widh of the device. But I think you could figure out which css is used, by this little 'hack'. In each css you give a nonsense property to a hidden element.

In the example I gave #canary the animation name first-css.

In a different css file you could write

#canary {animation-name: second-css; display: none}

You could give a unique property to a certain element in each css file. JQuery could check that property.

$(function() {
whichcss=$("#canary").css("animation-name");
$("#output").text(whichcss);
})

#canary {animation-name: first-css; display: none}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="canary"></p>
<p id="output"></p>

To be extra clear. In your css files you should include th name of the css file in this way:

in desktop-style.css:

#canary {animation-name: desktop-css; display: none}

in tablet-style.css:

#canary {animation-name: tablet-css; display: none}

in phone-style.css:

#canary {animation-name: phone-css; display: none}


问:
Confidence interval for statsmodels OLS model prediction
I have a very similar problem to this question and it works for the training data. Now I´m trying to get the confidence interval for the predicted data:

```<code>from statsmodels.sandbox.regression.predstd import wls_prediction_std
#define y, X, X_forecast as pandas dataframes
regressor = sm.api.OLS(y, X).fit()
wls_prediction_std(regressor.predict(X_forecast))
</code>```

But, of course, gives an error complaining about regressor.predict being an array. How can I calculate the confidence interval for the predicted regression values?

答:
you may have put the wrong parameter.

Let's try this one :

```<code>wls_prediction_std(regressor, exog=X_forecast, weights=None, alpha=0.05)
</code>```

Body:
I have a very similar problem to this question and it works for the training data. Now I´m trying to get the confidence interval for the predicted data:

from statsmodels.sandbox.regression.predstd import wls_prediction_std
#define y, X, X_forecast as pandas dataframes
regressor = sm.api.OLS(y, X).fit()
wls_prediction_std(regressor.predict(X_forecast))

But, of course, gives an error complaining about regressor.predict being an array. How can I calculate the confidence interval for the predicted regression values?

Body:
you may have put the wrong parameter.

Let's try this one :

wls_prediction_std(regressor, exog=X_forecast, weights=None, alpha=0.05)


问:
Handle iframe in React with refs
I am trying to set the content of an iframe in a React component. I have a component in which contains a handleStatementPrint function which has to be called when the iframe finishes loading. That function must print loaded iframe content - pdf file accessed with URL this.props.pdfs.url . Already iframe content is loaded and I can see pdf file in iframe, but I need to pass iframe content with refs but don't know how to do that correctly. I know that I need to use componentDidMount, but don't know that to write in here.

Component which must have iframe content:

```<code>import React, { Component } from 'react'

import IframeComponent from './components/Iframe';

class MainComponent extends Component {

  handleStatementPrint = () => {
    const iframePdf = this.iframePdf.contentWindow;
    if (this.iframePdf !== undefined) {
       const iframePdf = this.iframePdf.contentWindow;
       iframePdf.print();
    }
  }

  render () {
    return (
      <div className="container">

        {
          this.props.pdfs &&
            <iframe
              ref={(frame) => { this.iframePdf = frame }}
              src={this.props.pdfs.url}
              title="iFramePdf"
              type="application/pdf"
              >
            </iframe>
        }

      </div>
    );
  }
};

export default Statement;
</code>```

Iframe component:

```<code>import React, { Component } from 'react'

class IframeComponent extends Component {

  componentDidMount() {
    // Load iframe content
  }

  render () {
    return (
      <div>

         <Iframe />

      </div>
    );
  }
};

export default Iframe;
</code>```

I'm tried this examples:

Basic react iframe with onLoad handler

Handling of iframes in React

Iframe content is coming from fetch API, but I can access iframe and can see that content is perfectly loaded using ref. Problem: need to load that content in componentDidMount method before calling handleStatementPrint function from another component which can print loaded iframe content.

Questions:

So how to pass correctly iframe content with refs to load content in componentDidMountmethod?

How to pass loaded content from componentDidMount method in MainComponent functions, to do actions with loaded content?

答:
This is how refs works:

```<code><MyComponent ref={(c) => { this.myComponent = c; }} />
</code>```

After component is MOUNTED you gain access to the component itself and its method:

```<code>this.myComponent.myMethod();
</code>```

ContentLicense: CC BY-SA 4.0

Title: Handle iframe in React with refs

Body:
I am trying to set the content of an iframe in a React component. I have a component in which contains a handleStatementPrint function which has to be called when the iframe finishes loading. That function must print loaded iframe content - pdf file accessed with URL this.props.pdfs.url . Already iframe content is loaded and I can see pdf file in iframe, but I need to pass iframe content with refs but don't know how to do that correctly. I know that I need to use componentDidMount, but don't know that to write in here.

Component which must have iframe content:

import React, { Component } from 'react'

import IframeComponent from './components/Iframe';

class MainComponent extends Component {

  handleStatementPrint = () => {
    const iframePdf = this.iframePdf.contentWindow;
    if (this.iframePdf !== undefined) {
       const iframePdf = this.iframePdf.contentWindow;
       iframePdf.print();
    }
  }

  render () {
    return (

        {
          this.props.pdfs &&
             { this.iframePdf = frame }}
              src={this.props.pdfs.url}
              title="iFramePdf"
              type="application/pdf"
              >

        }

    );
  }
};

export default Statement;

Iframe component:

import React, { Component } from 'react'

class IframeComponent extends Component {

  componentDidMount() {
    // Load iframe content
  }

  render () {
    return (

    );
  }
};

export default Iframe;

I'm tried this examples:

Basic react iframe with onLoad handler

Handling of iframes in React

Iframe content is coming from fetch API, but I can access iframe and can see that content is perfectly loaded using ref. Problem: need to load that content in componentDidMount method before calling handleStatementPrint function from another component which can print loaded iframe content.

Questions:

So how to pass correctly iframe content with refs to load content in componentDidMountmethod?

How to pass loaded content from componentDidMount method in MainComponent functions, to do actions with loaded content?

Body:
This is how refs works:

<MyComponent ref={(c) => { this.myComponent = c; }} />

After component is MOUNTED you gain access to the component itself and its method:

this.myComponent.myMethod();


问:
Looping through elements not working
I want to check if this element has a matching data attribute value to all other elements, but the loop doesn't always work.

Stripped down code below.

HTML

```<code><div class="list">
   <div class="target" data-post-id="1"></div>
   <div class="target" data-post-id="2"></div>
   <div class="target" data-post-id="1"></div>
   <div class="target" data-post-id="1"></div>
</div>
</code>```

JS (event is tied to the target class):

```<code>if ($(this).data("post-id") == $(this).closest('.list').find('.target').data("post-id")) {
   // do stuff
}
</code>```

Clearly, I don't know how to loop through it properly. What's the solution?

答:
I have an answer in pure javascript. Try this,

var divs = document.getElementsByClassName('list')[0].children;
function divClick(element) {
 Array.from(divs).forEach(div => {
  if(element != div) {
    if (element.dataset.postId == div.dataset.postId) {
      console.log("equal");
    } else {
      console.log("not equal");
    }
    }
  });
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="list">
   <div class="target" onclick="divClick(this)" data-post-id="1">One</div>
   <div class="target" onclick="divClick(this)" data-post-id="2">Two</div>
   <div class="target" onclick="divClick(this)" data-post-id="1">Three</div>
   <div class="target" onclick="divClick(this)" data-post-id="1">Four</div>
</div></code>```

.siblings() in jquery will be helpful in this case,

$(document).ready(function(){
  $('.target').click(function(){
     $.each($(this).siblings(), (div, element) => {
         if($(element).data("post-id") == $(this).data("post-id")) {
              console.log("Equal");
            } else {
              console.log("Not Equal");
            }
        })
    });
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="list">
   <div class="target" data-post-id="1">One</div>
   <div class="target" data-post-id="2">Two</div>
   <div class="target" data-post-id="1">Three</div>
   <div class="target" data-post-id="1">Four</div>
</div></code>```

Title: Looping through elements not working

Body:
I want to check if this element has a matching data attribute value to all other elements, but the loop doesn't always work.

Stripped down code below.

HTML

JS (event is tied to the target class):

if ($(this).data("post-id") == $(this).closest('.list').find('.target').data("post-id")) {
   // do stuff
}

Clearly, I don't know how to loop through it properly. What's the solution?

Body:
I have an answer in pure javascript. Try this,

var divs = document.getElementsByClassName('list')[0].children;
function divClick(element) {
 Array.from(divs).forEach(div => {
  if(element != div) {
    if (element.dataset.postId == div.dataset.postId) {
      console.log("equal");
    } else {
      console.log("not equal");
    }
    }
  });
}

<div class="list">
   <div class="target" onclick="divClick(this)" data-post-id="1">One</div>
   <div class="target" onclick="divClick(this)" data-post-id="2">Two</div>
   <div class="target" onclick="divClick(this)" data-post-id="1">Three</div>
   <div class="target" onclick="divClick(this)" data-post-id="1">Four</div>
</div>

.siblings() in jquery will be helpful in this case,

$(document).ready(function(){
  $('.target').click(function(){
     $.each($(this).siblings(), (div, element) => {
         if($(element).data("post-id") == $(this).data("post-id")) {
              console.log("Equal");
            } else {
              console.log("Not Equal");
            }
        })
    });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="list">
   <div class="target" data-post-id="1">One</div>
   <div class="target" data-post-id="2">Two</div>
   <div class="target" data-post-id="1">Three</div>
   <div class="target" data-post-id="1">Four</div>
</div>


问:
The page has expired due to inactivity - in Production
I have no problems of this sort during development but after pushing to production, keep getting the error message "The page has expired due to inactivity".

I tried clearing cache and all that...

composer dump-autoload && php artisan optimize && php artisan cache:clear && php artisan config:clear && php artisan route:clear && php artisan view:clear

But it doesn't seem to help

The quick fix right now is turn off one of the application servers, but both of them running causes the page expired error. And as previously noted, this only happens in production after every push

答:
Do you have the application key set in the .env file?

Try running php artisan key:generate

Also: Do you have some sort of error log from the server itself? Maybe you get more info from that.


问:
Unable to launch new slave in jenkins
Im trying to launch a new slave to my jenkins master and im getting the following error:

```<code>Linux ip-172-31-40-67 4.9.58-18.55.amzn1.x86_64 #1 SMP Thu Nov 2 04:38:47
UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Installing JDK jdk-8u144-oth-JPR
Downloading JDK from http://download.oracle.com/otn/java/jdk/8u144-
b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz
java.io.IOException: Could not find any known supported java version in [java, /usr/bin/java, /usr/java/default/bin/java, /usr/java/latest/bin/java, /usr/local/bin/java, /usr/local/java/bin/java, /home/ec2-user/jdk/bin/java, /usr/bin/java/bin/java], and we also failed to install JDK as a fallback
at hudson.plugins.sshslaves.SSHLauncher.resolveJava(SSHLauncher.java:918)
at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:809)
at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:793)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Unable to find the login form
at hudson.tools.JDKInstaller.locate(JDKInstaller.java:465)
at hudson.plugins.sshslaves.SSHLauncher.attemptToInstallJDK(SSHLauncher.java:1039)
at hudson.plugins.sshslaves.SSHLauncher.resolveJava(SSHLauncher.java:916)
... 6 more
[11/15/17 10:10:09] Launch failed - cleaning up connection
</code>```

I think the main issue is the line:
Caused by: java.io.IOException: Unable to find the login form.
However I cant seem to find anything online about this issue..
I have both JDK and JRE installed on the slave however when I launch the slave it stills trying to download JDK, I have no idea why..

答:
This is related to
New Oracle website prevents the JDKInstaller to download binaries from archives.
Oracle changed their website a while ago.

You have to download Java and install it separately on your slave.
(For example: sudo apt-get install default-jre)

This will do the trick :-D.

Title: Unable to launch new slave in jenkins

Body:
Im trying to launch a new slave to my jenkins master and im getting the following error:

Linux ip-172-31-40-67 4.9.58-18.55.amzn1.x86_64 #1 SMP Thu Nov 2 04:38:47
UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Installing JDK jdk-8u144-oth-JPR
Downloading JDK from http://download.oracle.com/otn/java/jdk/8u144-
b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz
java.io.IOException: Could not find any known supported java version in [java, /usr/bin/java, /usr/java/default/bin/java, /usr/java/latest/bin/java, /usr/local/bin/java, /usr/local/java/bin/java, /home/ec2-user/jdk/bin/java, /usr/bin/java/bin/java], and we also failed to install JDK as a fallback
at hudson.plugins.sshslaves.SSHLauncher.resolveJava(SSHLauncher.java:918)
at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:809)
at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:793)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Unable to find the login form
at hudson.tools.JDKInstaller.locate(JDKInstaller.java:465)
at hudson.plugins.sshslaves.SSHLauncher.attemptToInstallJDK(SSHLauncher.java:1039)
at hudson.plugins.sshslaves.SSHLauncher.resolveJava(SSHLauncher.java:916)
... 6 more
[11/15/17 10:10:09] Launch failed - cleaning up connection

I think the main issue is the line:
Caused by: java.io.IOException: Unable to find the login form.
However I cant seem to find anything online about this issue..
I have both JDK and JRE installed on the slave however when I launch the slave it stills trying to download JDK, I have no idea why..


问:
calling parent() from QWidget in PyQT results in NoneType
I have a custom widget class (in PyQT 5.9) as a child in a QMainWindow that needs to access variables and functions from the MainWindow. I'm settings it up with a test variable imaginatively called self.test. However when I use self.parent().test in the child class, I get and error:

File "D:/test.py", line 390, in  mainWin = MainWindow()

File "D:/test.py", line 158, in init self.leftPane = FastaAnalysisWidget('left')

File "D:/test.py", line 26, in init print(self.parent().test)

AttributeError: 'NoneType' object has no attribute 'test'

This is the simplified child class:

```<code>class FastaAnalysisWidget(QWidget):
    def __init__(self, name, parent=None):
        super(FastaAnalysisWidget, self).__init__(parent)
        print(self.parent().test)
</code>```

And this is the simplified parent MainWindow:

```<code>class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.test = 'blabla'
        self.leftPane = FastaAnalysisWidget('left')
</code>```

The main looks like this:

```<code>app = QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit(app.exec_())
</code>```

I'm quite new to PyQT and I didn't play around with parent-child relations in Python before starting PyQT. The code I use here for the init I have used successfully before with a QTabWidget where the tabs were separate classes. Am I missing something obvious?

答:
When you create the FastaAnalysisWidget, you are omitting the parent argument, which defaults to None, so the code does exactly what you tell it to.

You need to initialize it like this in the MainWindowclass:

```<code>self.leftPane = FastaAnalysisWidget('left', parent=self)
</code>```

Then, the parent correctly points to the MainWindow.

Body:
I have a custom widget class (in PyQT 5.9) as a child in a QMainWindow that needs to access variables and functions from the MainWindow. I'm settings it up with a test variable imaginatively called self.test. However when I use self.parent().test in the child class, I get and error:

File "D:/test.py", line 390, in  mainWin = MainWindow()

File "D:/test.py", line 158, in init self.leftPane = FastaAnalysisWidget('left')

File "D:/test.py", line 26, in init print(self.parent().test)

AttributeError: 'NoneType' object has no attribute 'test'

This is the simplified child class:

class FastaAnalysisWidget(QWidget):
    def __init__(self, name, parent=None):
        super(FastaAnalysisWidget, self).__init__(parent)
        print(self.parent().test)

And this is the simplified parent MainWindow:

class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.test = 'blabla'
        self.leftPane = FastaAnalysisWidget('left')

The main looks like this:

app = QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit(app.exec_())

I'm quite new to PyQT and I didn't play around with parent-child relations in Python before starting PyQT. The code I use here for the init I have used successfully before with a QTabWidget where the tabs were separate classes. Am I missing something obvious?

Body:
When you create the FastaAnalysisWidget, you are omitting the parent argument, which defaults to None, so the code does exactly what you tell it to.

You need to initialize it like this in the MainWindowclass:

self.leftPane = FastaAnalysisWidget('left', parent=self)

Then, the parent correctly points to the MainWindow.


问:
Find and print exact match from a file, notify in print if a match could not be found
I am using the following Perl script to search multiple files, and print out the entire text line when a particular number in that line is matched:

```<code>#!/perl/bin/perl

use strict;
use warnings;

my @files = <c:/perl64/myfiles/*>;

foreach my $file (@files) {
  open my $file_h, '<', $file
   or die "Can't open $file: $!";

  while (<$file_h>) {
print "$file $_" if /\b1203\b/;
print "$file $_" if /\b1204\b/;
print "$file $_" if /\b1207\b/;
  } }
</code>```

The script works very well to match and print each time the number exists on a line in one or more of the files. My question is that I would like to be able to identify when there is no match at all for that number in any of the files.

We are parsing multiple files with thousands of lines so to find the delta's (i.e. NO MATCH of this number in any of the files) is very time consuming.

To clarify,  I still need to match and print every time the number is matched in every file, not just if it was matched once. also the line output where it matches is critical to be printed.

ultimately this is just to show if the number was not matched anywhere in any of the files.

Source edited for readability

```<code>#!/perl/bin/perl

use strict;
use warnings;

my @files = <c:/perl64/myfiles/*>;

foreach my $file ( @files ) {

    open my $file_h, '<', $file or die "Can't open $file: $!";

    while ( <$file_h> ) {

        print "$file $_" if /\b1203\b/;
        print "$file $_" if /\b1204\b/;
        print "$file $_" if /\b1207\b/;
    }
}
</code>```

答:
I would like to be able to identify when there is no match at all for that number in any of the files

Since you are going over several files, you need to remember that you saw a certain number once. A hash for counting is very useful here, and a common approach to this kind of problem.

It makes sense to at the same time move the numbers (or patterns) into an array. That way you only need to list them once in your code, and the overall code becomes less cluttered.

```<code>my @numbers = (1203, 1204, 1205);
my %seen;
foreach my $file (@files) {
    # ...
    while (<$file_h>) {
        foreach my $number (@numbers) {
            if (/\b$number\b/) {
                print "$file $_";
                $seen{$number} = 1; # we don't care how many, just that we saw it
             }
        }
    }
}

# At this point, %seen contains a key for every number that was seen at least once.
# If a number was not seen, it will not have a key.

# output numbers that were not seen
foreach my $number (@numbers) {
    print "no match: $_\n" unless exists $seen{$number};
}
</code>```

Body:
I am using the following Perl script to search multiple files, and print out the entire text line when a particular number in that line is matched:

#!/perl/bin/perl

use strict;
use warnings;

my @files = <c:/perl64/myfiles/*>;

foreach my $file (@files) {
  open my $file_h, '<', $file
   or die "Can't open $file: $!";

  while (<$file_h>) {
print "$file $_" if /\b1203\b/;
print "$file $_" if /\b1204\b/;
print "$file $_" if /\b1207\b/;
  } }

The script works very well to match and print each time the number exists on a line in one or more of the files. My question is that I would like to be able to identify when there is no match at all for that number in any of the files.

We are parsing multiple files with thousands of lines so to find the delta's (i.e. NO MATCH of this number in any of the files) is very time consuming.

To clarify,  I still need to match and print every time the number is matched in every file, not just if it was matched once. also the line output where it matches is critical to be printed.

ultimately this is just to show if the number was not matched anywhere in any of the files.

Source edited for readability

#!/perl/bin/perl

use strict;
use warnings;

my @files = <c:/perl64/myfiles/*>;

foreach my $file ( @files ) {

    open my $file_h, '<', $file or die "Can't open $file: $!";

    while ( <$file_h> ) {

        print "$file $_" if /\b1203\b/;
        print "$file $_" if /\b1204\b/;
        print "$file $_" if /\b1207\b/;
    }
}

Body:
I would like to be able to identify when there is no match at all for that number in any of the files

Since you are going over several files, you need to remember that you saw a certain number once. A hash for counting is very useful here, and a common approach to this kind of problem.

It makes sense to at the same time move the numbers (or patterns) into an array. That way you only need to list them once in your code, and the overall code becomes less cluttered.

my @numbers = (1203, 1204, 1205);
my %seen;
foreach my $file (@files) {
    # ...
    while (<$file_h>) {
        foreach my $number (@numbers) {
            if (/\b$number\b/) {
                print "$file $_";
                $seen{$number} = 1; # we don't care how many, just that we saw it
             }
        }
    }
}

# At this point, %seen contains a key for every number that was seen at least once.
# If a number was not seen, it will not have a key.

# output numbers that were not seen
foreach my $number (@numbers) {
    print "no match: $_\n" unless exists $seen{$number};
}


问:
Set margins in cardview programmatically
here is the code

```<code>CardView.LayoutParams layoutParams = new CardView.LayoutParams(
                CardView.LayoutParams.WRAP_CONTENT, CardView.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(100,100,100,100);
        CardView cv = new CardView(this);
        cv.setLayoutParams(layoutParams);
</code>```

Where ever, from xml its working-

```<code>android:layout_marginLeft="100dp"
</code>```

what can be the reason? am i missing something!

i need margin for elevation of cardview

Thanks

答:
You can try this chunk as per your requirement.

```<code>parentCardView.setLayoutParams(new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT, (int) Utility.pxFromDp(getActivity(), 300)));

                ViewGroup.MarginLayoutParams layoutParams =
                        (ViewGroup.MarginLayoutParams) binding.parentCard.getLayoutParams();
                layoutParams.setMargins(16, 0, 16, 0);
                binding.parentCard.requestLayout();
</code>```

This will set lay out height, width and then will put margin values over card view.

Body:
here is the code

CardView.LayoutParams layoutParams = new CardView.LayoutParams(
                CardView.LayoutParams.WRAP_CONTENT, CardView.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(100,100,100,100);
        CardView cv = new CardView(this);
        cv.setLayoutParams(layoutParams);

Where ever, from xml its working-

android:layout_marginLeft="100dp"

what can be the reason? am i missing something!

i need margin for elevation of cardview

Thanks

Body:
You can try this chunk as per your requirement.

parentCardView.setLayoutParams(new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT, (int) Utility.pxFromDp(getActivity(), 300)));

                ViewGroup.MarginLayoutParams layoutParams =
                        (ViewGroup.MarginLayoutParams) binding.parentCard.getLayoutParams();
                layoutParams.setMargins(16, 0, 16, 0);
                binding.parentCard.requestLayout();

This will set lay out height, width and then will put margin values over card view.


问:
How to activate the sbt DockerPlugin in scala?
I have two scala projects, one is already defined to build its docker container through the sbt docker plugin. The other one I want to dockerify as well.

The working one has in its build.sbt the following lines relevant to the docker config:

```<code>organization := "com.namespace"
name := "dockerized-app"
version := sys.env.getOrElse("PIPELINE_VERSION", "0.1.0_local")
scalaVersion := "2.12.4"
enablePlugins(JavaAppPackaging)
enablePlugins(DockerPlugin)
packageName in Docker := packageName.value
dockerRepository := Some("our-docker.io:5001")
dockerExposedPorts := Seq(8080)
</code>```

I thought that I could copy paste the relevant lines to the new project, change the name, and make it work.

Yet when I add the line to the about to be dockerified scala project:

```<code>enablePlugins(DockerPlugin)
</code>```

I get the error:

```<code> Cannot resolve symbol DockerPlugin
</code>```

I've looked through the prexisting projects libraryDependencies, yet it doesn't seem to be configured that way. In the the pre-configured project, IntellJ somehow knows the plugin, I can track that the DockerPlugin comes from com.typesafe.sbt.packager.docker. This made me assume that sbt comes shipped with it by default.

Yet apparently I have to activate it somehow.

Digging deeper I also tried adding this to my plugins.sbt to no avail:

```<code>addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.2")
</code>```

How to activate DockerPlugin using sbt in scala?

答:
In order to make it working properly you need to add the following line:

```<code>addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.2")
</code>```

in your project/plugins.sbt file.

Then refresh your project and it should work.

For further information, please check the Sbt Native Packager documentation.

Body:
I have two scala projects, one is already defined to build its docker container through the sbt docker plugin. The other one I want to dockerify as well.

The working one has in its build.sbt the following lines relevant to the docker config:

organization := "com.namespace"
name := "dockerized-app"
version := sys.env.getOrElse("PIPELINE_VERSION", "0.1.0_local")
scalaVersion := "2.12.4"
enablePlugins(JavaAppPackaging)
enablePlugins(DockerPlugin)
packageName in Docker := packageName.value
dockerRepository := Some("our-docker.io:5001")
dockerExposedPorts := Seq(8080)

I thought that I could copy paste the relevant lines to the new project, change the name, and make it work.

Yet when I add the line to the about to be dockerified scala project:

enablePlugins(DockerPlugin)

I get the error:

 Cannot resolve symbol DockerPlugin

I've looked through the prexisting projects libraryDependencies, yet it doesn't seem to be configured that way. In the the pre-configured project, IntellJ somehow knows the plugin, I can track that the DockerPlugin comes from com.typesafe.sbt.packager.docker. This made me assume that sbt comes shipped with it by default.

Yet apparently I have to activate it somehow.

Digging deeper I also tried adding this to my plugins.sbt to no avail:

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.2")

How to activate DockerPlugin using sbt in scala?

Body:
In order to make it working properly you need to add the following line:

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.2")

in your project/plugins.sbt file.

Then refresh your project and it should work.

For further information, please check the Sbt Native Packager documentation.


问:
exportSVG in jsfl run as a command in adobe animate doesn't work
In Adobe Animate and with a .fla file (after importing a swf file, import to stage), I run this script

```<code>var exportFileName = 'file:///C|/temp/files/a.svg';
fl.getDocumentDOM().exportSVG(exportFileName, true, true);
</code>```

it doesn't seem to do anything at all...no svg file is created at all.  If I change exportSVG to exportPNG with the same parameters it does seem to work.  I have found a couple of examples online using this exportSVG function but I can't find any official documentation (no documentation for exportPNG either).

Does anyone know how to make this work, know if it should work or at least might be able to point me to some documenation?

As additional info, if I add trace statements that the content of the output panel is wiped clean as soon as the exportSVG line gets hit.  I've also played around with the parameters of exportSVG and nothing seems to work.  If I use the file menu 'export (legacy)' and choose svg, I am able to export it manually

Using Adobe Animate CC v18.0 Build 107

答:
All it needs is to set the svg properties in the publish settings dialog.

Make sure you check the 'SVG Image' option in the publish settings dialog and save the .fla file (this can all be done via script but I had a default .fla file that I then imported into, delete layers, save, then export svg)

Body:
In Adobe Animate and with a .fla file (after importing a swf file, import to stage), I run this script

var exportFileName = 'file:///C|/temp/files/a.svg';
fl.getDocumentDOM().exportSVG(exportFileName, true, true);

it doesn't seem to do anything at all...no svg file is created at all.  If I change exportSVG to exportPNG with the same parameters it does seem to work.  I have found a couple of examples online using this exportSVG function but I can't find any official documentation (no documentation for exportPNG either).

Does anyone know how to make this work, know if it should work or at least might be able to point me to some documenation?

As additional info, if I add trace statements that the content of the output panel is wiped clean as soon as the exportSVG line gets hit.  I've also played around with the parameters of exportSVG and nothing seems to work.  If I use the file menu 'export (legacy)' and choose svg, I am able to export it manually

Using Adobe Animate CC v18.0 Build 107


问:
Simple LINQ to SQL extension method
How would I write a simple LINQ to SQL extension method called "IsActive" which would contain a few basic criteria checks of a few different fields, so that I could reuse this "IsActive" logic all over the place without duplicating the logic.

For example, I would like to be able to do something like this:

```<code>return db.Listings.Where(x => x.IsActive())
</code>```

And IsActive would be something like:

```<code>public bool IsActive(Listing SomeListing)
{
    if(SomeListing.Approved==true && SomeListing.Deleted==false)
        return true;
    else
        return false;
}
</code>```

Otherwise, I am going to have to duplicate the same old where criteria in a million different queries right throughout my system.

Note: method must render in SQL..

答:
Good question, there is a clear need to be able to define a re-useable filtering expression to avoid redundantly specifying logic in disparate queries.

This method will generate a filter you can pass to the Where method.

```<code>public Expression<Func<Listing, bool>> GetActiveFilter()
{
  return someListing => someListing.Approved && !someListing.Deleted;
}
</code>```

Then later, call it by:

```<code>Expression<Func<Filter, bool>> filter = GetActiveFilter()
return db.Listings.Where(filter);
</code>```

Since an Expression<Func<T, bool>> is used, there will be no problem translating to sql.

Here's an extra way to do this:

```<code>public static IQueryable<Filter> FilterToActive(this IQueryable<Filter> source)
{
  var filter = GetActiveFilter()
  return source.Where(filter);
}
</code>```

Then later,

```<code>return db.Listings.FilterToActive();
</code>```

Title: Simple LINQ to SQL extension method

Body:
How would I write a simple LINQ to SQL extension method called "IsActive" which would contain a few basic criteria checks of a few different fields, so that I could reuse this "IsActive" logic all over the place without duplicating the logic.

For example, I would like to be able to do something like this:

return db.Listings.Where(x => x.IsActive())

And IsActive would be something like:

public bool IsActive(Listing SomeListing)
{
    if(SomeListing.Approved==true && SomeListing.Deleted==false)
        return true;
    else
        return false;
}

Otherwise, I am going to have to duplicate the same old where criteria in a million different queries right throughout my system.

Note: method must render in SQL..

Body:
Good question, there is a clear need to be able to define a re-useable filtering expression to avoid redundantly specifying logic in disparate queries.

This method will generate a filter you can pass to the Where method.

public Expression<Func<Listing, bool>> GetActiveFilter()
{
  return someListing => someListing.Approved && !someListing.Deleted;
}

Then later, call it by:

Expression<Func<Filter, bool>> filter = GetActiveFilter()
return db.Listings.Where(filter);

Since an Expression<Func<T, bool>> is used, there will be no problem translating to sql.

Here's an extra way to do this:

public static IQueryable<Filter> FilterToActive(this IQueryable<Filter> source)
{
  var filter = GetActiveFilter()
  return source.Where(filter);
}

Then later,

return db.Listings.FilterToActive();


问:
How to place the last
 on the right side of my page?
I want to move the last li to right side but my CSS is not working.

.gCountryFlag {
    margin-left: 0;
    padding-left: 0;
}
ul li {
    list-style: none;

}
.navbar-collapse ul li:last-child {
     float: right;
}
.gCountryFlag li {
    float: left;
    display: inline-block;
    margin: 5px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li>Home</li>
                <li>About</li>
                <li>Contact</li>
                <li>
                    <div class="flagChangeCountry">
                        <asp:Image CssClass="topFlag" runat="server" ID="currentCultureFlagImage" />
                        <%--<asp:Literal runat="server" Text="<%$Resources:LocalisedText, ChangeCountryText %>" />--%>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</div></code>```

i want to move this image to right side which is in div. here it is.

```<code><li>
    <div class="flagChangeCountry">
        <asp:Image CssClass="topFlag" runat="server" ID="currentCultureFlagImage" />
        <%--<asp:Literal runat="server" Text="<%$Resources:LocalisedText, ChangeCountryText %>" />--%>
    </div>
</li>
</code>```

Also, I want to align the flag image with other text in same line. Here is screenshot for how the flag is looking which is not right side and also which is not aligned with other text.

答:
Try add this in class .navbar-nav

```<code>.navbar-nav {
    width: 100%;
}

.navbar-collapse ul li:last-child {
    float: right;
}
</code>```

This is because bootstrap.css has overwritten your css file.

Title: How to place the last <li> on the right side of my page?

Body:
I want to move the last li to right side but my CSS is not working.

.gCountryFlag {
    margin-left: 0;
    padding-left: 0;
}
ul li {
    list-style: none;

}
.navbar-collapse ul li:last-child {
     float: right;
}
.gCountryFlag li {
    float: left;
    display: inline-block;
    margin: 5px;
}

            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">

            </button>

Home

About

Contact

                        <asp:Image CssClass="topFlag" runat="server" ID="currentCultureFlagImage" />
                        <%--<asp:Literal runat="server" Text="<%$Resources:LocalisedText, ChangeCountryText %>" />--%>

i want to move this image to right side which is in div. here it is.

        <asp:Image CssClass="topFlag" runat="server" ID="currentCultureFlagImage" />
        <%--<asp:Literal runat="server" Text="<%$Resources:LocalisedText, ChangeCountryText %>" />--%>

Also, I want to align the flag image with other text in same line. Here is screenshot for how the flag is looking which is not right side and also which is not aligned with other text.

Body:
Try add this in class .navbar-nav

.navbar-nav {
    width: 100%;
}

.navbar-collapse ul li:last-child {
    float: right;
}

This is because bootstrap.css has overwritten your css file.


问:
Unable to run Perl code generated from wxGlade
I am trying to run Perl code generated using wxGlade but I am receiving this error

.

In text

Can't load 'C:/Perl/site/lib/auto/Wx/Wx.dll' for module Wx: load_file:The specified module could not be found at C:/Perl/lib/Dynaloader.pm line 191.

Ultimately, I want to rearrange widgets using the code generated from wxGlade. I don't have the *.wxg file, I only have the Perl code.

If this is not possible, I want to see the widgets when the Perl code runs then I will re-create the widgets in wxGlade.

I'm using ActivePerl 5.16.3 Build 1604 on Windows 10. I have installed wxPerl Version 0.9921.

Here's the result of where perl

```<code>C:\Windows\system32>where perl
C:\Perl\bin\perl.exe
C:\strawberry\perl\bin\perl.exe
</code>```

Below is the result of the cpan Wx command.

```<code>C:\Windows\system32>cpan Wx
Set up gcc environment - 4.4.3
CPAN: Term::ANSIColor loaded ok (v4.02)
CPAN: Storable loaded ok (v2.45)
Reading 'C:\Perl\cpan\Metadata'
  Database was generated on Mon, 04 Dec 2017 06:54:07 GMT
Running install for module 'Wx'
Running make for M/MD/MDOOTSON/Wx-0.9932.tar.gz
CPAN: Digest::SHA loaded ok (v5.85)
CPAN: Compress::Zlib loaded ok (v2.063)
Checksum for C:\Perl\cpan\sources\authors\id\M\MD\MDOOTSON\Wx-0.9932.tar.gz ok
CPAN: Archive::Tar loaded ok (v1.96)
Wx-0.9932/
Wx-0.9932/build/
Wx-0.9932/build/Wx/
Wx-0.9932/build/Wx/build/
Wx-0.9932/build/Wx/build/MakeMaker/
Wx-0.9932/build/Wx/build/MakeMaker/Any_OS.pm
Wx-0.9932/build/Wx/build/MakeMaker/Any_wx_config.pm
Wx-0.9932/build/Wx/build/MakeMaker/Core.pm
Wx-0.9932/build/Wx/build/MakeMaker/Hacks.pm
Wx-0.9932/build/Wx/build/MakeMaker/MacOSX_GCC.pm

Wx-0.9932/XS/SVGFileDC.xsp
Wx-0.9932/XS/TaskBarIcon.xs
Wx-0.9932/XS/TextAttr.xsp
Wx-0.9932/XS/TextCtrl.xsp
Wx-0.9932/XS/TextCtrlIface.xsp
Wx-0.9932/XS/TextEntryDialog.xs
Wx-0.9932/XS/Timer.xs
Wx-0.9932/XS/ToggleButton.xs
Wx-0.9932/XS/ToolBar.xs
Wx-0.9932/XS/Toolbook.xsp
Wx-0.9932/XS/ToolTip.xs
Wx-0.9932/XS/TopLevelWindow.xsp
Wx-0.9932/XS/Treebook.xsp
Wx-0.9932/XS/TreeCtrl.xs
Wx-0.9932/XS/Utils.xs
Wx-0.9932/XS/Validators.xs
Wx-0.9932/XS/VarHScrollHelper.xsp
Wx-0.9932/XS/VarHVScrollHelper.xsp
Wx-0.9932/XS/Variant.xsp
Wx-0.9932/XS/VarScrollHelperBase.xsp
Wx-0.9932/XS/VarVScrollHelper.xsp
Wx-0.9932/XS/VListBox.xsp
Wx-0.9932/XS/VScrolledWindow.xsp
Wx-0.9932/XS/Wave.xs
Wx-0.9932/XS/Window.xsp
Wx-0.9932/XS/Wizard.xs
CPAN: File::Temp loaded ok (v0.2304)
CPAN: Parse::CPAN::Meta loaded ok (v1.4409)
CPAN: CPAN::Meta loaded ok (v2.132830)
---- Unsatisfied dependencies detected during ----
----         MDOOTSON/Wx-0.9932.tar.gz        ----
    Alien::wxWidgets [build_requires]
Running make test
  Make had some problems, won't test
  Delayed until after prerequisites
Running make install
  Make had some problems, won't install
  Delayed until after prerequisites
Running install for module 'Alien::wxWidgets'
Running make for M/MD/MDOOTSON/Alien-wxWidgets-0.69.tar.gz
Checksum for C:\Perl\cpan\sources\authors\id\M\MD\MDOOTSON\Alien-wxWidgets-0.69.tar.gz ok
Alien-wxWidgets-0.69
Alien-wxWidgets-0.69/Build.PL
Alien-wxWidgets-0.69/Changes
Alien-wxWidgets-0.69/MANIFEST
Alien-wxWidgets-0.69/META.json

Alien-wxWidgets-0.69/patches/wxMac-2.8.10-fontdlg.patch
Alien-wxWidgets-0.69/patches/wxMac-2.8.3-brokengcc.patch
Alien-wxWidgets-0.69/patches/wxMac-2.9.0-textctrl.patch
Alien-wxWidgets-0.69/patches/wxWidgets-2.8.0-magic.patch
Alien-wxWidgets-0.69/patches/wxWidgets-2.8.10-gsocket.patch
Alien-wxWidgets-0.69/patches/wxWidgets-2.9.0-magic.patch
Alien-wxWidgets-0.69/patches/wxWidgets-2.9.0-msgdlg.patch
Alien-wxWidgets-0.69/patches/wxWidgets-2.9.4-plugin.patch
Alien-wxWidgets-0.69/patches/wxWidgets-3.0.2-webkit.patch
Alien-wxWidgets-0.69/script
Alien-wxWidgets-0.69/script/make_ppm.pl
Alien-wxWidgets-0.69/t
Alien-wxWidgets-0.69/t/01_load.t
Alien-wxWidgets-0.69/t/zy_pod_coverage.t
Alien-wxWidgets-0.69/t/zz_pod.t
CPAN: Module::CoreList loaded ok (v3.03)
CPAN: Module::Build loaded ok (v0.4203)

  CPAN.pm: Building M/MD/MDOOTSON/Alien-wxWidgets-0.69.tar.gz
    gmake: *** [gcc_mswudll\coredll_gdiplus.o] Error 1
    system: gmake -f makefile.gcc all  UNICODE=1 MSLU=0 BUILD=release SHARED=1  DEBUG_INFO=default DEBUG_FLAG=1 LDFLAGS=" -m32" CPPFLAGS="-m32 -D_USE_32BIT_TIME_T": 512 at inc/My/Build/Win32.pm line 284.
    dmake.exe:  Error code 130, while making 'all'
      MDOOTSON/Alien-wxWidgets-0.69.tar.gz
      C:\STRAWB~1\c\bin\dmake.exe -- NOT OK
    CPAN: YAML::XS loaded ok (v0.41)
    Running make test
      Can't test without successful make
    Running make install
      Make had returned bad status, install seems impossible
    Running make for M/MD/MDOOTSON/Wx-0.9932.tar.gz
    Warning: Prerequisite 'Alien::wxWidgets => 0.25' for 'MDOOTSON/Wx-0.9932.tar.gz' failed when processing 'MDOOTSON/Alien-wxWidgets-0.69.tar.gz' with 'make => NO'. Continuing, but chances to succeed are limited.
    CPAN: Time::HiRes loaded ok (v1.9726)

      CPAN.pm: Building M/MD/MDOOTSON/Wx-0.9932.tar.gz

    Set up gcc environment - 4.4.3
    Checking if your kit is complete...
    Looks good
    Warning: prerequisite Alien::wxWidgets 0.25 not found.
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Socket
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DND
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::FS
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Grid
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Help
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Html
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::MDI
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Print
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::XRC
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::STC
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DocView
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Calendar
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DateTime
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Media
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::RichText
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::AUI
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DataView
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::PropertyGrid
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Ribbon
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::WebView
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::PerlTest
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::IPC
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl::SplashFast
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl::Carp
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl::TextValidator
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx
    Writing MYMETA.yml and MYMETA.json

    ======================================================================
    wxWidgets minimum supported version 2.007001 is missing.
    You will need to re-run Makefile.PL after it is installed.
    You must install wxWidgets using Alien::wxWidgets.
    ======================================================================

    ======================================================================
    For installation instructions and further help please see
    docs/INSTALL.pod

    For command line switches help use:
    perl Makefile.PL --help
    ======================================================================

    Warning: Prerequisite 'Alien::wxWidgets => 0.25' for 'MDOOTSON/Wx-0.9932.tar.gz' failed when processing 'MDOOTSON/Alien-wxWidgets-0.69.tar.gz' with 'make => NO'. Continuing, but chances to succeed are limited.
    Makefile out-of-date with respect to alien_wxwidgets_missing
    Cleaning current config before rebuilding Makefile...
    C:\STRAWB~1\c\bin\dmake.exe -f Makefile.old clean > NUL
    C:\Perl\bin\perl.exe Makefile.PL "INSTALLDIRS=site"
    Set up gcc environment - 4.4.3
    Checking if your kit is complete...
    Looks good
    Warning: prerequisite Alien::wxWidgets 0.25 not found.
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Socket
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DND
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::FS
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Grid
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Help
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Html
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::MDI
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Print
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::XRC
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::STC
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DocView
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Calendar
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DateTime
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Media
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::RichText
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::AUI
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DataView
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::PropertyGrid
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Ribbon
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::WebView
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::PerlTest
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::IPC
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl::SplashFast
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl::Carp
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl::TextValidator
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx
    Writing MYMETA.yml and MYMETA.json

    ======================================================================
    wxWidgets minimum supported version 2.007001 is missing.
    You will need to re-run Makefile.PL after it is installed.
    You must install wxWidgets using Alien::wxWidgets.
    ======================================================================

    ======================================================================
    For installation instructions and further help please see
    docs/INSTALL.pod

    For command line switches help use:
    perl Makefile.PL --help
    ======================================================================

    ==> Your Makefile has been rebuilt. <==
    ==> Please rerun the C:\STRAWB~1\c\bin\dmake.exe command.  <==
    C:\Perl\bin\perl.exe  -e "exit 1" --
    dmake.exe:  Error code 129, while making 'Makefile'
      MDOOTSON/Wx-0.9932.tar.gz
      C:\STRAWB~1\c\bin\dmake.exe -- NOT OK
    Running make test
      Can't test without successful make
    Running make install
      Make had returned bad status, install seems impossible
</code>```

I removed ActivePerl and used Strawberry Perl. I issued cpan Wx then I got the error below.

Can't locate Wx/Mini.pm in .@INC (.@INC contains:

  C:\Program Files\ActiveState Komodo IDE 9\lib\support\dbgp\perllib

  C:/strawberry/perl/site/lib/MSWin32-x86-multi-thread

  C:/strawberry/perl/site/lib

  C:/strawberry/perl/vendor/lib

  C:/strawberry/perl/lib .)

  at C:/strawberry/perl/lib/Wx.pm line 100.

  BEGIN failed--compilation aborted at C:/strawberry/perl/lib/Wx.pm line 100.

mini.pm can be found in C:\strawberry\cpan\build\Wx-0.9932-zlzpbD\lib\Wx

答:
Your log shows

Make had returned bad status, install seems impossible
```

<p>so the installation failed and you have no <code>Wx</code>. You will also see that the build is trying to use both <code>dmake</code> (Strawberry Perl) and <code>gmake</code> (Active Perl), and it references <em>both</em> perl instances here</p>

<pre class="lang-none prettyprint-override"><code>C:\STRAWB~1\c\bin\dmake.exe -f Makefile.old clean > NUL
C:\Perl\bin\perl.exe Makefile.PL "INSTALLDIRS=site"
</code>```

so it's getting mightily confused

You need to remove one or the other to be safe, as Windows' behaviour is affected both by file associations and the PATH environment variable, unlike Linux.

You could take a look at berrybrew but I don't know whether it will work with ActivePerl.

I generally prefer Strawberry Perl for Windows as it is less tied to proprietary systems.

Body:
I am trying to run Perl code generated using wxGlade but I am receiving this error

.

In text

Can't load 'C:/Perl/site/lib/auto/Wx/Wx.dll' for module Wx: load_file:The specified module could not be found at C:/Perl/lib/Dynaloader.pm line 191.

Ultimately, I want to rearrange widgets using the code generated from wxGlade. I don't have the *.wxg file, I only have the Perl code.

If this is not possible, I want to see the widgets when the Perl code runs then I will re-create the widgets in wxGlade.

I'm using ActivePerl 5.16.3 Build 1604 on Windows 10. I have installed wxPerl Version 0.9921.

Here's the result of where perl

C:\Windows\system32>where perl
C:\Perl\bin\perl.exe
C:\strawberry\perl\bin\perl.exe

Below is the result of the cpan Wx command.

C:\Windows\system32>cpan Wx
Set up gcc environment - 4.4.3
CPAN: Term::ANSIColor loaded ok (v4.02)
CPAN: Storable loaded ok (v2.45)
Reading 'C:\Perl\cpan\Metadata'
  Database was generated on Mon, 04 Dec 2017 06:54:07 GMT
Running install for module 'Wx'
Running make for M/MD/MDOOTSON/Wx-0.9932.tar.gz
CPAN: Digest::SHA loaded ok (v5.85)
CPAN: Compress::Zlib loaded ok (v2.063)
Checksum for C:\Perl\cpan\sources\authors\id\M\MD\MDOOTSON\Wx-0.9932.tar.gz ok
CPAN: Archive::Tar loaded ok (v1.96)
Wx-0.9932/
Wx-0.9932/build/
Wx-0.9932/build/Wx/
Wx-0.9932/build/Wx/build/
Wx-0.9932/build/Wx/build/MakeMaker/
Wx-0.9932/build/Wx/build/MakeMaker/Any_OS.pm
Wx-0.9932/build/Wx/build/MakeMaker/Any_wx_config.pm
Wx-0.9932/build/Wx/build/MakeMaker/Core.pm
Wx-0.9932/build/Wx/build/MakeMaker/Hacks.pm
Wx-0.9932/build/Wx/build/MakeMaker/MacOSX_GCC.pm

Wx-0.9932/XS/SVGFileDC.xsp
Wx-0.9932/XS/TaskBarIcon.xs
Wx-0.9932/XS/TextAttr.xsp
Wx-0.9932/XS/TextCtrl.xsp
Wx-0.9932/XS/TextCtrlIface.xsp
Wx-0.9932/XS/TextEntryDialog.xs
Wx-0.9932/XS/Timer.xs
Wx-0.9932/XS/ToggleButton.xs
Wx-0.9932/XS/ToolBar.xs
Wx-0.9932/XS/Toolbook.xsp
Wx-0.9932/XS/ToolTip.xs
Wx-0.9932/XS/TopLevelWindow.xsp
Wx-0.9932/XS/Treebook.xsp
Wx-0.9932/XS/TreeCtrl.xs
Wx-0.9932/XS/Utils.xs
Wx-0.9932/XS/Validators.xs
Wx-0.9932/XS/VarHScrollHelper.xsp
Wx-0.9932/XS/VarHVScrollHelper.xsp
Wx-0.9932/XS/Variant.xsp
Wx-0.9932/XS/VarScrollHelperBase.xsp
Wx-0.9932/XS/VarVScrollHelper.xsp
Wx-0.9932/XS/VListBox.xsp
Wx-0.9932/XS/VScrolledWindow.xsp
Wx-0.9932/XS/Wave.xs
Wx-0.9932/XS/Window.xsp
Wx-0.9932/XS/Wizard.xs
CPAN: File::Temp loaded ok (v0.2304)
CPAN: Parse::CPAN::Meta loaded ok (v1.4409)
CPAN: CPAN::Meta loaded ok (v2.132830)
---- Unsatisfied dependencies detected during ----
----         MDOOTSON/Wx-0.9932.tar.gz        ----
    Alien::wxWidgets [build_requires]
Running make test
  Make had some problems, won't test
  Delayed until after prerequisites
Running make install
  Make had some problems, won't install
  Delayed until after prerequisites
Running install for module 'Alien::wxWidgets'
Running make for M/MD/MDOOTSON/Alien-wxWidgets-0.69.tar.gz
Checksum for C:\Perl\cpan\sources\authors\id\M\MD\MDOOTSON\Alien-wxWidgets-0.69.tar.gz ok
Alien-wxWidgets-0.69
Alien-wxWidgets-0.69/Build.PL
Alien-wxWidgets-0.69/Changes
Alien-wxWidgets-0.69/MANIFEST
Alien-wxWidgets-0.69/META.json

Alien-wxWidgets-0.69/patches/wxMac-2.8.10-fontdlg.patch
Alien-wxWidgets-0.69/patches/wxMac-2.8.3-brokengcc.patch
Alien-wxWidgets-0.69/patches/wxMac-2.9.0-textctrl.patch
Alien-wxWidgets-0.69/patches/wxWidgets-2.8.0-magic.patch
Alien-wxWidgets-0.69/patches/wxWidgets-2.8.10-gsocket.patch
Alien-wxWidgets-0.69/patches/wxWidgets-2.9.0-magic.patch
Alien-wxWidgets-0.69/patches/wxWidgets-2.9.0-msgdlg.patch
Alien-wxWidgets-0.69/patches/wxWidgets-2.9.4-plugin.patch
Alien-wxWidgets-0.69/patches/wxWidgets-3.0.2-webkit.patch
Alien-wxWidgets-0.69/script
Alien-wxWidgets-0.69/script/make_ppm.pl
Alien-wxWidgets-0.69/t
Alien-wxWidgets-0.69/t/01_load.t
Alien-wxWidgets-0.69/t/zy_pod_coverage.t
Alien-wxWidgets-0.69/t/zz_pod.t
CPAN: Module::CoreList loaded ok (v3.03)
CPAN: Module::Build loaded ok (v0.4203)

  CPAN.pm: Building M/MD/MDOOTSON/Alien-wxWidgets-0.69.tar.gz
    gmake: *** [gcc_mswudll\coredll_gdiplus.o] Error 1
    system: gmake -f makefile.gcc all  UNICODE=1 MSLU=0 BUILD=release SHARED=1  DEBUG_INFO=default DEBUG_FLAG=1 LDFLAGS=" -m32" CPPFLAGS="-m32 -D_USE_32BIT_TIME_T": 512 at inc/My/Build/Win32.pm line 284.
    dmake.exe:  Error code 130, while making 'all'
      MDOOTSON/Alien-wxWidgets-0.69.tar.gz
      C:\STRAWB~1\c\bin\dmake.exe -- NOT OK
    CPAN: YAML::XS loaded ok (v0.41)
    Running make test
      Can't test without successful make
    Running make install
      Make had returned bad status, install seems impossible
    Running make for M/MD/MDOOTSON/Wx-0.9932.tar.gz
    Warning: Prerequisite 'Alien::wxWidgets => 0.25' for 'MDOOTSON/Wx-0.9932.tar.gz' failed when processing 'MDOOTSON/Alien-wxWidgets-0.69.tar.gz' with 'make => NO'. Continuing, but chances to succeed are limited.
    CPAN: Time::HiRes loaded ok (v1.9726)

      CPAN.pm: Building M/MD/MDOOTSON/Wx-0.9932.tar.gz

    Set up gcc environment - 4.4.3
    Checking if your kit is complete...
    Looks good
    Warning: prerequisite Alien::wxWidgets 0.25 not found.
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Socket
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DND
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::FS
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Grid
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Help
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Html
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::MDI
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Print
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::XRC
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::STC
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DocView
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Calendar
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DateTime
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Media
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::RichText
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::AUI
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DataView
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::PropertyGrid
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Ribbon
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::WebView
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::PerlTest
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::IPC
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl::SplashFast
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl::Carp
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl::TextValidator
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx
    Writing MYMETA.yml and MYMETA.json

    ======================================================================
    wxWidgets minimum supported version 2.007001 is missing.
    You will need to re-run Makefile.PL after it is installed.
    You must install wxWidgets using Alien::wxWidgets.
    ======================================================================

    ======================================================================
    For installation instructions and further help please see
    docs/INSTALL.pod

    For command line switches help use:
    perl Makefile.PL --help
    ======================================================================

    Warning: Prerequisite 'Alien::wxWidgets => 0.25' for 'MDOOTSON/Wx-0.9932.tar.gz' failed when processing 'MDOOTSON/Alien-wxWidgets-0.69.tar.gz' with 'make => NO'. Continuing, but chances to succeed are limited.
    Makefile out-of-date with respect to alien_wxwidgets_missing
    Cleaning current config before rebuilding Makefile...
    C:\STRAWB~1\c\bin\dmake.exe -f Makefile.old clean > NUL
    C:\Perl\bin\perl.exe Makefile.PL "INSTALLDIRS=site"
    Set up gcc environment - 4.4.3
    Checking if your kit is complete...
    Looks good
    Warning: prerequisite Alien::wxWidgets 0.25 not found.
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Socket
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DND
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::FS
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Grid
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Help
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Html
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::MDI
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Print
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::XRC
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::STC
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DocView
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Calendar
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DateTime
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Media
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::RichText
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::AUI
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::DataView
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::PropertyGrid
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Ribbon
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::WebView
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::PerlTest
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::IPC
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl::SplashFast
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl::Carp
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl::TextValidator
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx::Perl
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx
    Writing MYMETA.yml and MYMETA.json
    Generating a dmake-style Makefile
    Writing Makefile for Wx
    Writing MYMETA.yml and MYMETA.json

    ======================================================================
    wxWidgets minimum supported version 2.007001 is missing.
    You will need to re-run Makefile.PL after it is installed.
    You must install wxWidgets using Alien::wxWidgets.
    ======================================================================

    ======================================================================
    For installation instructions and further help please see
    docs/INSTALL.pod

    For command line switches help use:
    perl Makefile.PL --help
    ======================================================================

    ==> Your Makefile has been rebuilt. <==
    ==> Please rerun the C:\STRAWB~1\c\bin\dmake.exe command.  <==
    C:\Perl\bin\perl.exe  -e "exit 1" --
    dmake.exe:  Error code 129, while making 'Makefile'
      MDOOTSON/Wx-0.9932.tar.gz
      C:\STRAWB~1\c\bin\dmake.exe -- NOT OK
    Running make test
      Can't test without successful make
    Running make install
      Make had returned bad status, install seems impossible

I removed ActivePerl and used Strawberry Perl. I issued cpan Wx then I got the error below.

Can't locate Wx/Mini.pm in .@INC (.@INC contains:

  C:\Program Files\ActiveState Komodo IDE 9\lib\support\dbgp\perllib

  C:/strawberry/perl/site/lib/MSWin32-x86-multi-thread

  C:/strawberry/perl/site/lib

  C:/strawberry/perl/vendor/lib

  C:/strawberry/perl/lib .)

  at C:/strawberry/perl/lib/Wx.pm line 100.

  BEGIN failed--compilation aborted at C:/strawberry/perl/lib/Wx.pm line 100.

mini.pm can be found in C:\strawberry\cpan\build\Wx-0.9932-zlzpbD\lib\Wx

Body:
Your log shows

Make had returned bad status, install seems impossible

so the installation failed and you have no Wx. You will also see that the build is trying to use both dmake (Strawberry Perl) and gmake (Active Perl), and it references both perl instances here

C:\STRAWB~1\c\bin\dmake.exe -f Makefile.old clean > NUL
C:\Perl\bin\perl.exe Makefile.PL "INSTALLDIRS=site"

so it's getting mightily confused

You need to remove one or the other to be safe, as Windows' behaviour is affected both by file associations and the PATH environment variable, unlike Linux.

You could take a look at berrybrew but I don't know whether it will work with ActivePerl.

I generally prefer Strawberry Perl for Windows as it is less tied to proprietary systems.


问:
Have PyCharm extract code in a Python function to a nested function
I have had PyCharm 2017.3 extract some code inside a top-level function to another top-level function, and it does a good job.

However, sometimes I would like to not put the extracted function on top level, but rather it should become a function nested inside the existing function. The rationale is re-using code that is only used inside a function, but several times there. I think that this "sub-function" should ideally not be accessible outside of the original function.

How can I do this? I have not seen any options in the refactoring dialog.

Example

a) Original code:

```<code>def foo():
    a = ''
    if a == '':
        b = 'empty'
    else:
        b = 'not empty'
    return b
</code>```

b) What extracting does:

```<code>def foo():
    a = ''
    b = bar(a)
    return b

def bar(a):
    if a == '':
        b = 'empty'
    else:
        b = 'not empty'
    return b
</code>```

c) What I would like to have:

```<code>def foo():
    def bar():
        if a == '':
            b = 'empty'
        else:
            b = 'not empty'
        return b

    a = ''
    b = bar(a)
    return b
</code>```

I am aware that bar's b will shadow foo's b unless it is renamed in the process. I also thought about completely accepting the shadowing by not returning or requesting b and just modifying it inside bar.

Please also hint me if what I want is not a good thing for any reason.

答:
It is considered good practice to keep function boundaries isolated: get data as parameters and spit data as return values with as little side-effects as possible. That said, there are a few special cases where you break this rule; many of them when using closures. Closures are not as idiomatic in Python as they are in Javascript - personally I think it is good but many people disagree.

There is one place were closures are absolutely idiomatic in Python: decorators. For other cases where you would use a closure in order to avoid use of global variables and provide some form of data hiding there are other alternatives in Python. Although some people advocates using closure instead of a class when it has just one method, a plain function combined with functools.partial can be even better.

This is my guess about why there is no such feature in Pycharm: we almost never do it in Python, instead we tend to keep the function signature as foo(x) even when we can get x from the enclosing scope. Hell, in Python our methods receive self explicitly where most languages have an implicit this. If you write code this way then Pycharm already does everything that is needed when refactoring: it fixes the indentation when you cut & paste.

If you catch yourself doing this kind of refactoring a lot I guess you are coming from a language where closures are more idiomatic like Javascript or Lisp.

So my point is: this "nested to global" or "global to nested" function refactoring feature does not exist in Pycharm because nested functions relying on the enclosing scopes are not idiomatic in Python unless for closures - and even closures are not that idiomatic outside of decorators.

If you care enough go ahead and fill a feature request at their issue tracker or upvote some related tickets like #PY-12802 and #PY-2701 - as you can see those have not attracted a lot of attention possibly because of the reasons above.

Body:
I have had PyCharm 2017.3 extract some code inside a top-level function to another top-level function, and it does a good job.

However, sometimes I would like to not put the extracted function on top level, but rather it should become a function nested inside the existing function. The rationale is re-using code that is only used inside a function, but several times there. I think that this "sub-function" should ideally not be accessible outside of the original function.

How can I do this? I have not seen any options in the refactoring dialog.

Example

a) Original code:

def foo():
    a = ''
    if a == '':
        b = 'empty'
    else:
        b = 'not empty'
    return b

b) What extracting does:

def foo():
    a = ''
    b = bar(a)
    return b

def bar(a):
    if a == '':
        b = 'empty'
    else:
        b = 'not empty'
    return b

c) What I would like to have:

def foo():
    def bar():
        if a == '':
            b = 'empty'
        else:
            b = 'not empty'
        return b

    a = ''
    b = bar(a)
    return b

I am aware that bar's b will shadow foo's b unless it is renamed in the process. I also thought about completely accepting the shadowing by not returning or requesting b and just modifying it inside bar.

Please also hint me if what I want is not a good thing for any reason.


问:
How to specify paths in .gitignore?
I am developing a Ruby on Rails application, using git for synchronising code between stakeholders. The application has the ability to send emails. Each stakeholder has his own SMTP provider which is defined in config/initializers/smtp.rb during installation.

```<code>ActionMailer::Base.smtp_settings = {
    address: "smtp.emailme.com",
    port: 587,
    domain: "emailme.com",
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: "me@emailme.com",
    password: "Password"
    }
</code>```

The .gitignore file is defined as:

```<code>*.rbc
capybara-*.html
.rspec
/log
/tmp
/public/system
/coverage/
/spec/tmp
**.orig
rerun.txt
pickle-email-*.html

## Environment normalization:
/.bundle
/vendor/bundle

# these should all be checked in to normalize the environment:
# Gemfile.lock, .ruby-version, .ruby-gemset
Gemfile~

config/initializers/smtp.rb
</code>```

.gitignore files are identical on Github and on my computer. I tried to specify

config/initializers/smtp.rb

or

/config/initializers/smtp.rb

But whatever, the smtp.rb file on my computer gets overwritten with the file on Github. And it's the same the other way round.
What did I miss?

答:
As mentioned by @oliver, the file should not exist on git. You can remove the file from git by doing

```<code>git rm --cached config/initializers/smtp.rb
git commit -m "Removed config file from repo"
git push
</code>```

Please do note --cached, it is very important otherwise you can lose the file from you local directory. This option will remove the file only from repo.

See: Remove directory from remote repository after adding them to .gitignore if you want to Add directory to .gitignore

Thanks!

Title: How to specify paths in .gitignore?

Body:
I am developing a Ruby on Rails application, using git for synchronising code between stakeholders. The application has the ability to send emails. Each stakeholder has his own SMTP provider which is defined in config/initializers/smtp.rb during installation.

ActionMailer::Base.smtp_settings = {
    address: "smtp.emailme.com",
    port: 587,
    domain: "emailme.com",
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: "me@emailme.com",
    password: "Password"
    }

The .gitignore file is defined as:

*.rbc
capybara-*.html
.rspec
/log
/tmp
/public/system
/coverage/
/spec/tmp
**.orig
rerun.txt
pickle-email-*.html

## Environment normalization:
/.bundle
/vendor/bundle

# these should all be checked in to normalize the environment:
# Gemfile.lock, .ruby-version, .ruby-gemset
Gemfile~

config/initializers/smtp.rb

.gitignore files are identical on Github and on my computer. I tried to specify

config/initializers/smtp.rb

or

/config/initializers/smtp.rb

But whatever, the smtp.rb file on my computer gets overwritten with the file on Github. And it's the same the other way round.
What did I miss?

Body:
As mentioned by @oliver, the file should not exist on git. You can remove the file from git by doing

git rm --cached config/initializers/smtp.rb
git commit -m "Removed config file from repo"
git push

Please do note --cached, it is very important otherwise you can lose the file from you local directory. This option will remove the file only from repo.

See: Remove directory from remote repository after adding them to .gitignore if you want to Add directory to .gitignore

Thanks!


问:
getHostServices(); Method not found.
I want to open pdf files using the code below, but method getHostServices(); is not found even though i have the right imports.</p>

```<code>import javafx.application.HostServices;

ClinicFiles clinicFiles = (ClinicFiles) listViewClinic.getSelectionModel().getSelectedItem();
HostServices hostServices = getHostServices();
hostServices.showDocument(clinicFiles.getAbsolutePath());
</code>```

答:
Probably, your class is not extending from javafx.application.Application:

For example:

```<code>import javafx.application.Application;
import javafx.application.HostServices;

public class App extends Application {
    public void method(String[] args) {
        ClinicFiles clinicFiles = (ClinicFiles) listViewClinic.getSelectionModel().getSelectedItem();
        HostServices hostServices = getHostServices();
        hostServices.showDocument(clinicFiles.getAbsolutePath());
    }
}
</code>```

Title: getHostServices(); Method not found.

Body:
I want to open pdf files using the code below, but method getHostServices(); is not found even though i have the right imports.

import javafx.application.HostServices;

ClinicFiles clinicFiles = (ClinicFiles) listViewClinic.getSelectionModel().getSelectedItem();
HostServices hostServices = getHostServices();
hostServices.showDocument(clinicFiles.getAbsolutePath());

Body:
Probably, your class is not extending from javafx.application.Application:

For example:

import javafx.application.Application;
import javafx.application.HostServices;

public class App extends Application {
    public void method(String[] args) {
        ClinicFiles clinicFiles = (ClinicFiles) listViewClinic.getSelectionModel().getSelectedItem();
        HostServices hostServices = getHostServices();
        hostServices.showDocument(clinicFiles.getAbsolutePath());
    }
}