答:
Okay, so a person on Reddit helped me resolve the issue, and essentially what I had to do was create a method inside of the class in the view1.js file and place my d3 code inside of that method, like so

```<code>import AbstracView from "./AbstractView.js"

export default class extends AbstracView {

    constructor() {
        super();
        this.setTitle("D3 Chart - View1");
    }

    loadChart() {
        // My D3 code here
    }

    async getHtml() {
        return `
            <h1>D3 Chart</h1>
            <div class="chart-area"></div>
        `;
    }
}
</code>```

Later, I just had to call it, like so in my router file

```<code>const view = new match.route.view(getParams(match));

document.querySelector("#app").innerHTML = await view.getHtml();

view.loadChart?.(); // runs the method after the HTML corresponding to the view has been added to the base HTML.
</code>```

Title: <script> tag only works on page refresh (Single Page Application)

Body:
I'm building a single-page application using plain Javascript + express-JS. I have two views linked to two anchor links so that I can toggle between the views. The problem is, one of the views (the default view) displays a d3 chart, and it only displays it when the site initially loads or on page refresh. If I just click on its own anchor link, theoretically it should do nothing and still display the chart but the chart vanishes but all the other html elements corresponding to that view stay. I'm making sure my script tag for that file is getting loaded into the base html file after all of my content is being loaded in, but still the issue persists. Can someone point out what's going wrong here?.

var tag = document.createElement("script");

function scriptLoad() {
    tag.src = "static/js/d3chart.js";
    tag.id = "d3chart"
    document.getElementsByTagName('head')[0].appendChild(tag);
};

document.addEventListener("DOMContentLoaded", () => {
    document.body.addEventListener("click", e => {
        if (e.target.matches("[data-link]")) {
            e.preventDefault();
            navigateTo(e.target.href);
        }
        scriptLoad();
    });
    router();
});

HTML anchor links in base html file

View 1
View 2

Whole Code

import view1 from "./views/view1.js"
import view2 from "./views/view2.js"

const pathToRegex = path => new RegExp("^" + path.replace(/\//g, "\\/").replace(/:\w+/g, "(.+)") + "$");

const getParams = match => {
    const values = match.result.slice(1);
    const keys = Array.from(match.route.path.matchAll(/:(\w+)/g)).map(result => result[1]);

    return Object.fromEntries(keys.map((key, i) => {
        return [key, values[i]];
    }));
};

const navigateTo = url => {
    history.pushState(null, null, url);
    router();
};

const router = async () => {
    const routes = [
        { path: "/", view: view1 },
        { path: "/view2", view: view2 }
    ];

    // Test each route for potential match
    const potentialMatches = routes.map(route => {
        return {
            route: route,
            result: location.pathname.match(pathToRegex(route.path))
        };
    });

    let match = potentialMatches.find(potentialMatch => potentialMatch.result !== null);

    if (!match) {
        match = {
            route: routes[0],
            result: [location.pathname]
        };
    }

    const view = new match.route.view(getParams(match));

    document.querySelector("#app").innerHTML = await view.getHtml();

};

window.addEventListener("popstate", router);

var tag = document.createElement("script");

function scriptLoad () {
    tag.src = "static/js/d3chart.js";
    tag.id = "d3chart"
    document.getElementsByTagName('body')[0].appendChild(tag);
}

document.addEventListener("DOMContentLoaded", () => {
    document.body.addEventListener("click", e => {
        if (e.target.matches("[data-link]")) {
            e.preventDefault();
            navigateTo(e.target.href);
        }
        scriptLoad();
    });
    router();
});

view1.js file - the default view on start (chart view)

import AbstracView from "./AbstractView.js"

export default class extends AbstracView {

    constructor() {
        super();
        this.setTitle("D3 Chart - View1");
    }

    async getHtml() {
        return `

D3 Chart

        `;
    }
}

Body:
Okay, so a person on Reddit helped me resolve the issue, and essentially what I had to do was create a method inside of the class in the view1.js file and place my d3 code inside of that method, like so

import AbstracView from "./AbstractView.js"

export default class extends AbstracView {

    constructor() {
        super();
        this.setTitle("D3 Chart - View1");
    }

    loadChart() {
        // My D3 code here
    }

    async getHtml() {
        return `
            <h1>D3 Chart</h1>
            <div class="chart-area"></div>
        `;
    }
}

Later, I just had to call it, like so in my router file

const view = new match.route.view(getParams(match));

document.querySelector("#app").innerHTML = await view.getHtml();

view.loadChart?.(); // runs the method after the HTML corresponding to the view has been added to the base HTML.


来源: stackexchange

问:
Visual Studio 2019 Not Showing .NET 6 Framework
I've been struggling to change an asp.net core web api project's target framework to .NET 6 which was started using target framework .net5. I've already tried a few options but couldn't find the .NET 6 framework listed in the target dropdown.

I am using Microsoft Visual Studio Enterprise 2019 Version 16.11.3.

I've installed .NET 6.0.0-rc.2.21480.5. which is verified through dotnet --version.

Enabled "Use previews of the .NET Core SDK", and restarted the program.

restarted workstation several times & still no luck.

Looking forward to availing of community help!

答: .NET 6.0 is coming with VS 2022 ,install the new visual studio version and proceed</p>

ContentLicense: CC BY-SA 4.0


问:
How to properly display a Snackbar in Flutter?
I am trying to show a Snackbar on click of a floatingActionbutton. But when I click on the floatingactionbutton it's not showing anything. Here is my code. I am using a StatefulWidget. I debugged and checked that the onPressed function is also getting executed but somehow the Snackbar is not visible. What can be the root cause of the issue? I feel the BuildContext I am passing has some issue.

```<code>class MyApp extends StatefulWidget{
  @override
  MyAppState createState() {
    // TODO: implement createState
    return new MyAppState();
  }

}

class MyAppState extends State<MyApp>{
  File _image;
  String _text;

  Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.camera);
    _image = image;
    final FirebaseVisionImage visionImage = FirebaseVisionImage.fromFile(_image);
    final TextRecognizer textRecognizer = FirebaseVision.instance.textRecognizer();
    final VisionText visionText = await textRecognizer.processImage(visionImage);

    String detectedText = visionText.text;

    setState(() {
      _image = image;
      _text = detectedText;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: new AppBar(
          title: new Text('Image Picker Example'),
        ),
        body: new Center(
          child: _image == null
              ? new Text('No image selected.')
              : new Image.file(_image),
        ),
        floatingActionButton: new FloatingActionButton(
          onPressed: (){
            showSnackBar(context);
//            getImage();
          },
          tooltip: 'Pick Image',
          child: new Icon(Icons.add_a_photo),
        ),
      ),
    );
  }

  void showSnackBar(BuildContext context) {
    final scaffold = Scaffold.of(context);
    final snackBarContent = SnackBar(
      content: Text("sagar"),
      action: SnackBarAction(
          label: 'UNDO', onPressed: scaffold.hideCurrentSnackBar),
    );
    scaffold.showSnackBar(snackBarContent);
  }

}
</code>```

答:
I faced this issue when trying to showSnackbar() in StatfulWidget from second level child of the parent Parent() => childLevel1 => childOfLevel1(){showing the snackbar here}

I implemented @Epizon answer but .currentState.showSnackBar(snackBarContent); was deprecated, According to flutter:

The SnackBar API within the Scaffold is now handled by the ScaffoldMessenger
read  full document

so replacing this line in @Epizon answer:
_scaffoldKey.currentState!.showSnackBar(_snackBarContent);

to this:
ScaffoldMessenger.of(_scaffoldKey.currentState!.context) .showSnackBar(_snackBarContent);

will solve the deprecation issue

here is the code

```<code>final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();

    void _showSnack(String msg) {
      final _snackBarContent = SnackBar(content: Text(msg));
      ScaffoldMessenger.of(_scaffoldKey.currentState!.context)
          .showSnackBar(_snackBarContent);
    }

return MaterialApp(
      home: Scaffold(
        //resizeToAvoidBottomInset: true,
        key: _scaffoldKey,
      body: Center(
child: ElevatedButton(
child: Text("show snackbar"),
onPressed(){_showSnack("im located in the btn's onPressed");},
);
);
</code>```

Body:
I am trying to show a Snackbar on click of a floatingActionbutton. But when I click on the floatingactionbutton it's not showing anything. Here is my code. I am using a StatefulWidget. I debugged and checked that the onPressed function is also getting executed but somehow the Snackbar is not visible. What can be the root cause of the issue? I feel the BuildContext I am passing has some issue.

class MyApp extends StatefulWidget{
  @override
  MyAppState createState() {
    // TODO: implement createState
    return new MyAppState();
  }

}

class MyAppState extends State<MyApp>{
  File _image;
  String _text;

  Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.camera);
    _image = image;
    final FirebaseVisionImage visionImage = FirebaseVisionImage.fromFile(_image);
    final TextRecognizer textRecognizer = FirebaseVision.instance.textRecognizer();
    final VisionText visionText = await textRecognizer.processImage(visionImage);

    String detectedText = visionText.text;

    setState(() {
      _image = image;
      _text = detectedText;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: new AppBar(
          title: new Text('Image Picker Example'),
        ),
        body: new Center(
          child: _image == null
              ? new Text('No image selected.')
              : new Image.file(_image),
        ),
        floatingActionButton: new FloatingActionButton(
          onPressed: (){
            showSnackBar(context);
//            getImage();
          },
          tooltip: 'Pick Image',
          child: new Icon(Icons.add_a_photo),
        ),
      ),
    );
  }

  void showSnackBar(BuildContext context) {
    final scaffold = Scaffold.of(context);
    final snackBarContent = SnackBar(
      content: Text("sagar"),
      action: SnackBarAction(
          label: 'UNDO', onPressed: scaffold.hideCurrentSnackBar),
    );
    scaffold.showSnackBar(snackBarContent);
  }

}

Body:
I faced this issue when trying to showSnackbar() in StatfulWidget from second level child of the parent Parent() => childLevel1 => childOfLevel1(){showing the snackbar here}

I implemented @Epizon answer but .currentState.showSnackBar(snackBarContent); was deprecated, According to flutter:

The SnackBar API within the Scaffold is now handled by the ScaffoldMessenger
read  full document

so replacing this line in @Epizon answer:
_scaffoldKey.currentState!.showSnackBar(_snackBarContent);

to this:
ScaffoldMessenger.of(_scaffoldKey.currentState!.context) .showSnackBar(_snackBarContent);

will solve the deprecation issue

here is the code

final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();

    void _showSnack(String msg) {
      final _snackBarContent = SnackBar(content: Text(msg));
      ScaffoldMessenger.of(_scaffoldKey.currentState!.context)
          .showSnackBar(_snackBarContent);
    }

return MaterialApp(
      home: Scaffold(
        //resizeToAvoidBottomInset: true,
        key: _scaffoldKey,
      body: Center(
child: ElevatedButton(
child: Text("show snackbar"),
onPressed(){_showSnack("im located in the btn's onPressed");},
);
);


问:
Prevent bootstrap modal closing on postback in ASP.NET
I have a bootstrap modal I want to show in order to perform a search and select funcionality in a ASP.NET Web form. The problem is when the user clicks on "Search" button, the modal closes. I want the modal keeps open to show search results on GridView below and closes when the user selects any GridView item.

I've tried other solutions mentioned in other threads but nothing seems to work. I'm using a WebForm with a Master page, I don't know if it can be causin me the issue.

This is my modal code:

```<code><div class="modal fade" id="modSearchByAccount" role="dialog">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">×</button>
            <h4 class="modal-title">Search by Account</h4>
        </div>
        <div class="modal-body">
            <div class="row">
                <div class="col-md-8">
                    <asp:TextBox ID="txtSearchText" runat="server" CssClass="form-control" placeholder="Account name"></asp:TextBox>
                </div>
                <div class="col-md-4">
                     <asp:Button ID="btnSearchAccount" runat="server" OnClick="btnSearchAccount_Click" Text="Buscar" CssClass="btn btn-default" />
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                     <asp:Panel ID="pnlSearchResults" runat="server" ScrollBars="Vertical" Height="200px" Width="100%">
                        <asp:GridView ID="gvSearchResults" runat="server" AutoGenerateColumns="False" DataKeyNames="ACCOUNT_ID" OnSelectedIndexChanged="gvSearchResults_SelectedIndexChanged" CssClass="table table-striped table-hover">
                            <Columns>
                                <asp:BoundField DataField="ACCOUNT_ID" HeaderText="ID" />
                                <asp:BoundField DataField="ACCOUNT_NAME" HeaderText="Name" />
                                <asp:CommandField ShowSelectButton ="true" />
                            </Columns>
                        </asp:GridView>
                    </asp:Panel>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
    </div>
 </div>
</code>```

Any ideas? Can I use an UpdatePanel somewhere here?

Thanks in advance!

答: Put your Modal outside the updatepanel, if the modal inside the updatepanel the modal will close automatically when postback or asp button clicked.</p>

ContentLicense: CC BY-SA 3.0

Body:
I have a bootstrap modal I want to show in order to perform a search and select funcionality in a ASP.NET Web form. The problem is when the user clicks on "Search" button, the modal closes. I want the modal keeps open to show search results on GridView below and closes when the user selects any GridView item.

I've tried other solutions mentioned in other threads but nothing seems to work. I'm using a WebForm with a Master page, I don't know if it can be causin me the issue.

This is my modal code:

            <button type="button" class="close" data-dismiss="modal">×</button>

Search by Account

                    <asp:TextBox ID="txtSearchText" runat="server" CssClass="form-control" placeholder="Account name"></asp:TextBox>

                     <asp:Button ID="btnSearchAccount" runat="server" OnClick="btnSearchAccount_Click" Text="Buscar" CssClass="btn btn-default" />

                     <asp:Panel ID="pnlSearchResults" runat="server" ScrollBars="Vertical" Height="200px" Width="100%">
                        <asp:GridView ID="gvSearchResults" runat="server" AutoGenerateColumns="False" DataKeyNames="ACCOUNT_ID" OnSelectedIndexChanged="gvSearchResults_SelectedIndexChanged" CssClass="table table-striped table-hover">
                            <Columns>
                                <asp:BoundField DataField="ACCOUNT_ID" HeaderText="ID" />
                                <asp:BoundField DataField="ACCOUNT_NAME" HeaderText="Name" />
                                <asp:CommandField ShowSelectButton ="true" />
                            </Columns>
                        </asp:GridView>
                    </asp:Panel>

            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

Any ideas? Can I use an UpdatePanel somewhere here?

Thanks in advance!


问:
Golang: `dial tcp 172.20.0.7:8081: connect: connection refused`, error at random times between docker containers / services
I've a docker-compose file with contents like this

```<code># Docker Compose file Reference (https://docs.docker.com/compose/compose-file/)

version: '3'

services:

  john:
    build:
      context: .
      dockerfile: Dockerfiles/cowboys/John/Dockerfile
      args:
        - COWBOY_NAME_JOHN
        - CONTAINER_PORT_JOHN
    ports:
      - "8081:8081" # Forward the exposed port on the container to port on the host machine
    restart: unless-stopped
    networks:
      - fullstack
    depends_on:
      db:
        condition: service_healthy
    links:
      - db

  philip:
    build:
      context: .
      dockerfile: Dockerfiles/cowboys/Philip/Dockerfile
      args:
        - COWBOY_NAME_PHILIP
        - CONTAINER_PORT_PHILIP
    ports:
      - "8085:8085"
    restart: unless-stopped
    networks:
      - fullstack
    depends_on:
      db:
        condition: service_healthy
    links:
      - db

  db:
    build:
      context: Dockerfiles/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
    restart: on-failure
    networks:
      - fullstack
    ports:
      - "3306:3306"
    healthcheck:
      test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD

networks:
  fullstack:
    driver: bridge
</code>```

When I run docker-compose up --build ( or docker-compose up --build --force-recreate to reinitialise db on next run), I get an error like this

sam_1     | panic: Put "http://john:8081/shoot": dial tcp 172.20.0.7:8081: connect: connection refused

john is one of the services name under services. Here is complete screenshot:

Link to repository where all details could be seen including environment variables & relevant Dockerfile(s) - https://github.com/sitetester/distributed-cowboys

Could anyone please explain how to get rid of this error ? It just happens/occurs at random time. Not sure how to fix it. Thanks in advance!

答: Solved: removing existing containers/images and pruning docker volumes fixed the issue.

Body:
I've a docker-compose file with contents like this

# Docker Compose file Reference (https://docs.docker.com/compose/compose-file/)

version: '3'

services:

  john:
    build:
      context: .
      dockerfile: Dockerfiles/cowboys/John/Dockerfile
      args:
        - COWBOY_NAME_JOHN
        - CONTAINER_PORT_JOHN
    ports:
      - "8081:8081" # Forward the exposed port on the container to port on the host machine
    restart: unless-stopped
    networks:
      - fullstack
    depends_on:
      db:
        condition: service_healthy
    links:
      - db

  philip:
    build:
      context: .
      dockerfile: Dockerfiles/cowboys/Philip/Dockerfile
      args:
        - COWBOY_NAME_PHILIP
        - CONTAINER_PORT_PHILIP
    ports:
      - "8085:8085"
    restart: unless-stopped
    networks:
      - fullstack
    depends_on:
      db:
        condition: service_healthy
    links:
      - db

  db:
    build:
      context: Dockerfiles/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
    restart: on-failure
    networks:
      - fullstack
    ports:
      - "3306:3306"
    healthcheck:
      test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD

networks:
  fullstack:
    driver: bridge

When I run docker-compose up --build ( or docker-compose up --build --force-recreate to reinitialise db on next run), I get an error like this

sam_1     | panic: Put "http://john:8081/shoot": dial tcp 172.20.0.7:8081: connect: connection refused

john is one of the services name under services. Here is complete screenshot:

Link to repository where all details could be seen including environment variables & relevant Dockerfile(s) - https://github.com/sitetester/distributed-cowboys

Could anyone please explain how to get rid of this error ? It just happens/occurs at random time. Not sure how to fix it. Thanks in advance!


问:
How to change order of x-axis in ggplot
I am trying to reverse the order of my x-axis(specificities) so that my data starts from 1 instead of 0. Any advice on this?

```<code>ggplot(x, aes(x=specificities, y=sensitivities)) +
  geom_line()
</code>```

Title: How to change order of x-axis in ggplot

Body:
I am trying to reverse the order of my x-axis(specificities) so that my data starts from 1 instead of 0. Any advice on this?

ggplot(x, aes(x=specificities, y=sensitivities)) +
  geom_line()

Body:
Here is one way to solve your task:

library(ggplot2)

ggplot(df, aes(x=specificities, y=sensitivities)) +
  geom_line() +
  scale_x_reverse(limits = c(1,0))

data:

df <- structure(list(sensitivities = c(1, 1, 1, 1, 1, 1, 0.9897959,
0.9693878, 0.9540816, 0.9540816, 0.9438776, 0.9336735, 0.9081633,
0.877551, 0.877551, 0.877551, 0.877551, 0.877551, 0.877551, 0.872449,
0.872449, 0.8622449), specificities = c(0, 0.01020408, 0.04081633,
0.12244898, 0.25, 0.32142857, 0.37244898, 0.43367347, 0.4744898,
0.5255102, 0.59183673, 0.67346939, 0.7755102, 0.82142857, 0.87244898,
0.88265306, 0.89285714, 0.89795918, 0.90306122, 0.92346939, 0.93367347,
0.93367347)), class = "data.frame", row.names = c(NA, -22L))


问:
Visual Studio Code: Intellisense not working
My Visual Studio Code's Intellisense is not working properly. Every time I try to use it with Ctrl + Shift, it only displays a loading message. I'm using Python (with Django) and have installed ms-python.python. I also have Djaneiro. It is still not working.

What seems to be the problem here?

答:
For me, what fixed it was reinstalling the default Python extension and setting the  python language server in the seetings to Default.

Steps

Open the commands window by simultaneously pressing CTRL/CMD + Shift + P. Now search for install extensions.

Select Python and install it (uninstall first if already installed).

Python is the default Python extension in VSCode and it installs Pylance by default.

Open the commands window again and search this time for Settings. Select Prefernces: Open settings (JSON).

In the JSON file search (CTRL/CMD + F) for python.languageServer and set the value to Default or Pylance as the default is currently Pylance (mine was somehow set to None!).

Once you save the file, a prompt will ask you if you want to reload vscode for the changes to take effect, click Yes!

That's it, intelliSense should be working now using Pylance!


问:
How i can use filter function in python?
I want to delete unwanted characters in dictionary like:$&@“”’’!?,#%*=…

I just want number ,alphabet and underline.

答:
If you want to sanitize a string so that it has all special characters removed, try this function:</p>
```<code>def sanitize(string):
  outstr = ""
  for char in string:
    if char.isalpha() or char.isdigit() or char == "_":
      outstr += char
  return outstr
</code>```

Body:
If you want to sanitize a string so that it has all special characters removed, try this function:

def sanitize(string):
  outstr = ""
  for char in string:
    if char.isalpha() or char.isdigit() or char == "_":
      outstr += char
  return outstr


答:
you could do a lambda that returns True if the text isn't in punctuation symbols (that you don't want), except for '_' that we will remove with .replace("_",""), and then using the filter function to apply that to a list, then to join with '':

```<code>from string import punctuation
string_to_parse = "a$ ehl! th!s i$ "
parse=lambda letter:letter not in punctuation.replace("_",'')
stringcompleted = ''.join(filter(parse,string_to_parse))
print(stringcompleted)
</code>```

output:

```<code>'a ehl ths i '
</code>```

You could wrap this into a function, like this:

```<code>>>> def parses(string_to_parse):
...     parse=lambda letter:letter not in __import__("string").punctuation.replace("_",'')
...     return ''.join(filter(parse,string_to_parse))
...
>>> parses("s/)+(=i;~q8cze%]*'y:|,f")
'siq8czeyf'
</code>```

but this uses dynamic importing, witch from my test, results in double the time of the other so i suggest normal importing:

```<code>>>> def parses(string_to_parse):
...    from string import punctuation
...    parse=lambda letter:letter not in punctuation.replace("_",'')
...    return ''.join(filter(parse,string_to_parse))
>>> parses("s/)+(=i;~q8cze%]*'y:|,f")
'siq8czeyf'
</code>```

Title: How i can use filter function in python?

Body:
I want to delete unwanted characters in dictionary like:$&@“”’’!?,#%*=…

I just want number ,alphabet and underline.

Body:
you could do a lambda that returns True if the text isn't in punctuation symbols (that you don't want), except for '_' that we will remove with .replace("_",""), and then using the filter function to apply that to a list, then to join with '':

from string import punctuation
string_to_parse = "a$ ehl! th!s i$ "
parse=lambda letter:letter not in punctuation.replace("_",'')
stringcompleted = ''.join(filter(parse,string_to_parse))
print(stringcompleted)

output:

'a ehl ths i '

You could wrap this into a function, like this:

>>> def parses(string_to_parse):
...     parse=lambda letter:letter not in __import__("string").punctuation.replace("_",'')
...     return ''.join(filter(parse,string_to_parse))
...
>>> parses("s/)+(=i;~q8cze%]*'y:|,f")
'siq8czeyf'

but this uses dynamic importing, witch from my test, results in double the time of the other so i suggest normal importing:

>>> def parses(string_to_parse):
...    from string import punctuation
...    parse=lambda letter:letter not in punctuation.replace("_",'')
...    return ''.join(filter(parse,string_to_parse))
>>> parses("s/)+(=i;~q8cze%]*'y:|,f")
'siq8czeyf'


问:
Not able to add JSON Data inside forEach loop using if condition on elements
Hi I am trying to add few conditional data from one JSON object to another.I am trying below code.Data is having JSON object.I am not getting any one in Data though i am getting correct value in Temp</p>
```<code>const userData= data.rows;
    const claimsB = claimsB;
    let Temp = '';
    let Data = '';
    userData.forEach((element) => {
        if (element.value.A == claimsB.B){
            Temp = element;
            Data += Temp;
        }
        console.log(Temp);
    });
   console.log(Data);
</code>```

答:
Perhaps you want to replace

Data += Temp;

with

Data += JSON.stringify(Temp);

Body:
Hi I am trying to add few conditional data from one JSON object to another.I am trying below code.Data is having JSON object.I am not getting any one in Data though i am getting correct value in Temp

const userData= data.rows;
    const claimsB = claimsB;
    let Temp = '';
    let Data = '';
    userData.forEach((element) => {
        if (element.value.A == claimsB.B){
            Temp = element;
            Data += Temp;
        }
        console.log(Temp);
    });
   console.log(Data);


问:
Password decryption not supported on .NET Core for Windows?
I recently converted a private NuGet repository to require authentication.

To build a project that uses that repository, I added the authentication to the local NuGet.Config with NuGet Sources add -name [repo_name] -Source [source_url] -UserName [username] -Password [password].

I now get the following error when I try running dotnet restore:

Password decryption is not supported on .NET Core for this platform. The following feed uses an encrypted password: 'nuget-sdet'. You can use a clear text password as a workaround.

I know that this isn't supported on linux, but I'm running this on Windows Server 2012 R2.

This is running on a very old version of .NET Core: 1.0.0-preview2-003121.

Is password decryption supported on Windows for newer versions of .NET Core?

Or am I stuck between either storing the password in clear text or re-enabling anonymous access to the feed?

答:
In non windows OS you should add the suffix of --store-password-in-clear-text
to your add command.

As specified in the dotnet nuget add source article here

--store-password-in-clear-text

Enables storing portable package source credentials by disabling password encryption.


问:
Bash history without line numbers
The bash history command is very cool. I understand why it shows the line numbers, but is there a way I can invoke the history command and suppress the line numbers?

The point here is to use the history command, so please don't reply cat ~/.bash_history

Current Output:

```<code>  529 man history
  530 ls
  531 ll
  532 clear
  533 cd ~
  534 histor<em>y</em></code>```

Historical graphic source.

Desired Output:

```<code>man history
ls
ll
clear
cd ~
histor<em>y</em></code>```

Historical graphic source.

Thanks to everyone for your great solutions. Paul's is the simplest and will work for me for because my bash history size is set at 2000.

I also wanted to share a cool article I found this morning. It has a couple good options that I am now using, like keeping duplicate entries out of the bash history and making sure multiple bash sessions don't overwrite the history file: http://blog.macromates.com/2008/working-with-history-in-bash/

答:
Try this:</p>

```<code>$ history | cut -c 8-
</code>```

Title: Bash history without line numbers

Body:
The bash history command is very cool. I understand why it shows the line numbers, but is there a way I can invoke the history command and suppress the line numbers?

The point here is to use the history command, so please don't reply cat ~/.bash_history

Current Output:

  529 man history
  530 ls
  531 ll
  532 clear
  533 cd ~
  534 history

Historical graphic source.

Desired Output:

man history
ls
ll
clear
cd ~
history

Historical graphic source.

Thanks to everyone for your great solutions. Paul's is the simplest and will work for me for because my bash history size is set at 2000.

I also wanted to share a cool article I found this morning. It has a couple good options that I am now using, like keeping duplicate entries out of the bash history and making sure multiple bash sessions don't overwrite the history file: http://blog.macromates.com/2008/working-with-history-in-bash/

Body:
Try this:

$ history | cut -c 8-


问:
Python tkinter not detecting mouse click on tops of lables?
so I'm creating chess in tkinter, I would like to detect the mouse coords when clicked.

But it appears it won't detect clicks through a label.
So when I bind to the main window, it works.

```<code>self.board = Canvas(self.window,width=768,height=768)
self.backgroundimage = PhotoImage(file="chessboard.png")
self.window.bind('<Button-1>',self.func)
</code>```

However, it detects mouse clicks when clicked off the board. I want it to only detect mouse clicks inside the board frame.

When I do this

```<code>self.board.bind('<Button-1>',self.func)
</code>```

it no longer detects mouse clicks :/  UNLESS, I remove the lable. So it won't detects clicks through labels or images, unless it's bound to the main window. I want the coords/pixles to be relative to the frame I'm clicking inside of, because obviously I'll have a Board frame, and another frame on the side for actions like request takeback, resign, etc..

答:
You can replace the labels and images with buttons

For Label self.testbuttonwithtext = tk.Button(text='your text', border=0, function=self.func)

For Images self.testbuttonwithimage = tk.Button(border=0, image='the path of your image here, function=self.func)

I Hope this help you and feel free to ask again if this didn't help you.

Body:
so I'm creating chess in tkinter, I would like to detect the mouse coords when clicked.

But it appears it won't detect clicks through a label.
So when I bind to the main window, it works.

self.board = Canvas(self.window,width=768,height=768)
self.backgroundimage = PhotoImage(file="chessboard.png")
self.window.bind('<Button-1>',self.func)

However, it detects mouse clicks when clicked off the board. I want it to only detect mouse clicks inside the board frame.

When I do this

self.board.bind('<Button-1>',self.func)

it no longer detects mouse clicks :/  UNLESS, I remove the lable. So it won't detects clicks through labels or images, unless it's bound to the main window. I want the coords/pixles to be relative to the frame I'm clicking inside of, because obviously I'll have a Board frame, and another frame on the side for actions like request takeback, resign, etc..


问:
What is time complexity of this algorithm ? (inner loop changes due to outer loop)
```<code>Algorithm(n):
   i = 1 , k = 0
   while i <= n {

    for (j = 1  to n/i){
        k = k+1
       }
    i = i * 2
   }

</code>```

I understand outer loop works logn, i'm not sure but for inner loop it is working like n/i + n/i/2 .. n/i/2^n  . (it is not logn because We are updating i in outer loop)

i don't know how to combine them, because time complexity of inner loop changes at every loop.

Can anyone help me about this? What is the time complexity

答:
Actually i did some maths on this and it gave me the answer.

lets say n %2 = 0 and lets say 2^x = n and x is int.

for i = 1 -> n/i

for i = 2 -> n/2i

for i = 4 -> n/4i

for i = n -> n/ni

n/i ( 1 + 1/2 + 1/4 + .. + 1/n)  and  [1/2 + 1/4 ... 1/2^n] --> 1

n * 2/i --> n>i so the answer is O(n)

Body:
Algorithm(n):
   i = 1 , k = 0
   while i <= n {

    for (j = 1  to n/i){
        k = k+1
       }
    i = i * 2
   }

I understand outer loop works logn, i'm not sure but for inner loop it is working like n/i + n/i/2 .. n/i/2^n  . (it is not logn because We are updating i in outer loop)

i don't know how to combine them, because time complexity of inner loop changes at every loop.

Can anyone help me about this? What is the time complexity


问:
"Docker Desktop stopped..." message after installation
Installed docker desktop for windows, after having installed the linux kernel update package and changing to wsl 2 version (virtualization is enabled) but i get the message "Docker Desktop stopped..." as shown below.

Tried:

uninstalling and reinstalling again

run application as administrator

答: I also get the same problem after updating my Docker version from 4.4.4 to 4.5. It was crashed when I want to run my container today. I try to reinstall with 4.5 version and get the error "Docker Desktop stopped...". Then, I try to reinstall with 4.4.4 version, and now it just run perfectly fine like before.</p>


问:
Sell me on unit testing
I've been a .Net developer for a long time and am trying to wrap my head around real, practical unit testing.

Most specifically, I'm looking at unit testing ASP.Net MVC 3 projects.

I've read a decent amount about it, and believe I understand it at the academic level (i.e. basically ensures that changes you make aren't going to break other stuff).  However, all of the tests I've seen written in examples are trivially stupid things that would be a pretty obvious catch anyway (does this controller return a view with this name?).

So, maybe I'm missing something, or just haven't seen any really good test examples or something, but it really looks like a crap ton of extra work and complexity with mocking, ioc, etc and I'm just not seeing the counter-balancing gains.

Teach me, please :)

答:
basically ensures that changes you make aren't going to break other stuff

This is not unit testing, but regression testing. Unit testing is used to test the smallest pieces of code individually (Usually at the class level). This is not very useful in situations where the projects are small, or there are not may classes.

There are many instances where some form of unit testing (mixed in with other forms usually, I like to use mock testing if I have time, for example) is very useful. Say you have a large project with about 20+ classes, and you are getting an error in one of them. You may need to go thorough each class, and make sure that their methods return the correct information. This is unit testing.

In short, unit testing is used when you need to test a specific class, or specific methods, to make sure they are functional. It is a lot easier to find the issue with a program when you are working with the smallest units, and not walking through a whole program to find out what method isn't working right

Title: Sell me on unit testing


问:
scale a svg element which is inside an other svg
I would like to scale up on hover 3 svgs nested in an other svg. These 3 svgs are planets visible on the first graph at this address : http://68.183.74.150:3000/planet.
So, to sum up, the code looks like this :

```<code><svg id="a">
<g>
...
</g>
<g>
<svg id="b"></svg>
</g>
</svg>
</code>```

I tried the code below but it doesn't work as b is nested inside a. It works if I apply this code to the "a" svg.

```<code>svg#b:hover  {
  transform: scale(3);
}
svg#b {
  transition: all 1s;
  transform-origin: 50% 50%;
}
</code>```

How would you solve this ?

答:
Apparently chromium seems to have issues with scaling nested svg elements.

/* example layout */

.wrap {
  display: inline-block;
  width: 20em;
}

.svgParent {
  width: 10em;
  border: 2px solid #ccc;
}

.svgParent:hover {
  border: 2px solid green;
}

/* set transformorigin */

.svgChild,
.childNodes {
  transition: 0.3s;
  transform-origin: center;
}

/* ensure scaled element don't get cropped when scaled */

.svgChild {
  overflow: visible;
}

.hoverElement:hover {
  transform: scale(1.3);
  opacity: 0.5;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="wrap">
  <p>Scale nested svg on hover –<br />not working in chrome</p>
  <svg class="svgParent" viewBox="0 0 100 100">
    <svg class="svgChild hoverElement" x="20" y="20" width="48" height="48" viewBox="0 0 24 24">
      <circle cx="12" cy="12" r="12" fill="#ccc" />
    </svg>
  </svg>
</div>
<div class="wrap">
  <p>Scale group in nested svg on hover</p>
  <svg class="svgParent" viewBox="0 0 100 100">
    <svg class="svgChild" x="20" y="20" width="48" height="48" viewBox="0 0 24 24">
      <g class="childNodes hoverElement">
        <circle cx="12" cy="12" r="12" fill="#ccc" />
      </g>
    </svg>
  </svg>
</div></code>```

For a consistent display in both firefox and chromium you could wrap your planets' child elements an additional group like so:

```<code><svg x="129.2" y="62.1" width="26" height="26" viewBox="0 0 36 36">
  <g class="planetwrap">
    <circle fill="#88C9F9" cx="18" cy="18" r="18" />
    <path fill="#5C913B" d="M25.716 1.756c-1.022.568-1.872 1.528-3.028 1.181-1.875-.562-4.375-1.812-6-.25s-2 3 0 2.938 3.375-2.438 4.375-1.438.749 1.813-1.625 2.125S14.5 7 13.125 7s-1.688.812-.75 1.688-.563.937-2.125 1.812.375 1.25 1.688 2 2.312-.188 2.875-1.438 2.981-2.75 3.99-2.562c1.01.188 1.01.688.822 1.562s.75.625.812-.375 1.188-1.75 2.062-1.812 1.625 1.188.625 1.812-2 1.125-.75 1.438 2.125 1.938.688 2.625-3.937 1.125-5.062.562-3.688-1.375-4.375-.938-1.062.89-1.875 1.195c-.812.305-4.125 1.805-4.188 3.743S7.438 22.438 8.75 22.5s4.5-.812 5.5-1.625 2.375-.625 2.812.312.125 1.5-.312 3 .286 2.25.987 3.562c.701 1.312 1.263 2.062 1.263 3s1 1.875 2.5.312 2.875-4.625 3.5-5.75 1.125-3.625 1.875-4.125 1.938-1.688 1.062-1.5-2.625-.062-3.062-1.312-2.312-3.625-1.438-3.875 1.875 1.39 2.25 2.164c.375.774.875 1.711 1.625 1.961s2.375-1.673 2.875-1.961c.5-.289.125-1.476-.875-1.351s-2.312 0-2.312-.624 1.25-1.438 2.25-1.25 1.75.5 2.375 1.25 1.875 2.125 2.375 3 .875 1 1.125-.562c.166-1.038.387-1.609.59-2.222-1.013-5.829-4.82-10.683-9.999-13.148z" />
  </g>
</svg>
</code>```

Example grouped

If you can't optimize and save your tweaked planet assets statically you could use some js to do the wrapping job.

let planets = document.querySelectorAll('.recharts-reference-dot svg');

// wrap planet svg elements
planets.forEach(function(planet, i){
   planet.innerHTML = '<g class="planetwrap">'+ planet.innerHTML +'</g>';
})```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.recharts-reference-dot svg{
  overflow:visible;
}

.planetwrap{
  transform-origin:center;
  transition: 0.3s transform
}

.planetwrap:hover{
  transform:scale(1.5)
}</code>```

<svg id="masse_distance" class="recharts-surface" width="899" height="199.77777777777777" viewBox="0 0 899 199.77777777777777" version="1.1">
    <defs>
      <clipPath id="masse_distance-clip">
        <rect x="70" y="20" height="139.77777777777777" width="809"></rect>
      </clipPath>
    </defs>
    <g class="recharts-layer recharts-cartesian-axis recharts-xAxis xAxis">
      <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-line" stroke="#666" fill="none" x1="70" y1="159.77777777777777" x2="879" y2="159.77777777777777"></line>
      <g class="recharts-cartesian-axis-ticks">
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="231.8" y1="165.77777777777777" x2="231.8" y2="159.77777777777777"></line><text name="masse" type="number" orientation="bottom" width="809" height="30" x="231.8" y="167.77777777777777" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="middle">
            <tspan x="231.8" dy="0.71em">0.01 Mjup</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="308.99821901364135" y1="165.77777777777777" x2="308.99821901364135" y2="159.77777777777777"></line><text name="masse" type="number" orientation="bottom" width="809" height="30" x="308.99821901364135" y="167.77777777777777" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="middle">
            <tspan x="308.99821901364135" dy="0.71em">0.03 Mjup</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="393.6" y1="165.77777777777777" x2="393.6" y2="159.77777777777777"></line><text name="masse" type="number" orientation="bottom" width="809" height="30" x="393.6" y="167.77777777777777" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="middle">
            <tspan x="393.6" dy="0.71em">0.1 Mjup</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="555.4" y1="165.77777777777777" x2="555.4" y2="159.77777777777777"></line><text name="masse" type="number" orientation="bottom" width="809" height="30" x="555.4" y="167.77777777777777" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="middle">
            <tspan x="555.4" dy="0.71em">1 Mjup</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="717.2" y1="165.77777777777777" x2="717.2" y2="159.77777777777777"></line><text name="masse" type="number" orientation="bottom" width="809" height="30" x="717.2" y="167.77777777777777" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="middle">
            <tspan x="717.2" dy="0.71em">10 Mjup</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="879" y1="165.77777777777777" x2="879" y2="159.77777777777777"></line><text name="masse" type="number" orientation="bottom" width="809" height="30" x="873.265625" y="167.77777777777777" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="middle">
            <tspan x="873.265625" dy="0.71em">100 Mjup</tspan>
          </text>
        </g>
      </g>
    </g>
    <g class="recharts-layer recharts-cartesian-axis recharts-yAxis yAxis">
      <line name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="10" y="20" class="recharts-cartesian-axis-line" stroke="#666" fill="none" x1="70" y1="20" x2="70" y2="159.77777777777777"></line>
      <g class="recharts-cartesian-axis-ticks">
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="10" y="20" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="64" y1="124.83333333333333" x2="70" y2="124.83333333333333"></line><text name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="62" y="124.83333333333333" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="end">
            <tspan x="62" dy="0.355em">1 jour</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="10" y="20" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="64" y1="89.88888888888887" x2="70" y2="89.88888888888887"></line><text name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="62" y="89.88888888888887" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="end">
            <tspan x="62" dy="0.355em">100 jour</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="10" y="20" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="64" y1="61.208688458136685" x2="70" y2="61.208688458136685"></line><text name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="62" y="61.208688458136685" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="end">
            <tspan x="62" dy="0.355em">4380 jour</tspan>
          </text>
        </g>
      </g>
    </g>
    <g class="recharts-layer recharts-reference-dot">
      <g>
        <svg x="129.19821901364134" y="62.06438300713549" width="26" height="26" viewBox="0 0 36 36">
          <circle fill="#88C9F9" cx="18" cy="18" r="18"></circle>
          <path fill="#5C913B" d="M25.716 1.756c-1.022.568-1.872 1.528-3.028 1.181-1.875-.562-4.375-1.812-6-.25s-2 3 0 2.938 3.375-2.438 4.375-1.438.749 1.813-1.625 2.125S14.5 7 13.125 7s-1.688.812-.75 1.688-.563.937-2.125 1.812.375 1.25 1.688 2 2.312-.188 2.875-1.438 2.981-2.75 3.99-2.562c1.01.188 1.01.688.822 1.562s.75.625.812-.375 1.188-1.75 2.062-1.812 1.625 1.188.625 1.812-2 1.125-.75 1.438 2.125 1.938.688 2.625-3.937 1.125-5.062.562-3.688-1.375-4.375-.938-1.062.89-1.875 1.195c-.812.305-4.125 1.805-4.188 3.743S7.438 22.438 8.75 22.5s4.5-.812 5.5-1.625 2.375-.625 2.812.312.125 1.5-.312 3 .286 2.25.987 3.562c.701 1.312 1.263 2.062 1.263 3s1 1.875 2.5.312 2.875-4.625 3.5-5.75 1.125-3.625 1.875-4.125 1.938-1.688 1.062-1.5-2.625-.062-3.062-1.312-2.312-3.625-1.438-3.875 1.875 1.39 2.25 2.164c.375.774.875 1.711 1.625 1.961s2.375-1.673 2.875-1.961c.5-.289.125-1.476-.875-1.351s-2.312 0-2.312-.624 1.25-1.438 2.25-1.25 1.75.5 2.375 1.25 1.875 2.125 2.375 3 .875 1 1.125-.562c.166-1.038.387-1.609.59-2.222-1.013-5.829-4.82-10.683-9.999-13.148z"></path>
        </svg>
        </g><text x="167.19821901364134" y="70.06438300713549">Terre</text>
    </g>

  </svg>
```

Body:
I would like to scale up on hover 3 svgs nested in an other svg. These 3 svgs are planets visible on the first graph at this address : http://68.183.74.150:3000/planet.
So, to sum up, the code looks like this :

<svg id="a">
<g>
...
</g>
<g>
<svg id="b"></svg>
</g>
</svg>

I tried the code below but it doesn't work as b is nested inside a. It works if I apply this code to the "a" svg.

svg#b:hover  {
  transform: scale(3);
}
svg#b {
  transition: all 1s;
  transform-origin: 50% 50%;
}

How would you solve this ?

Body:
Apparently chromium seems to have issues with scaling nested svg elements.

/* example layout */

.wrap {
  display: inline-block;
  width: 20em;
}

.svgParent {
  width: 10em;
  border: 2px solid #ccc;
}

.svgParent:hover {
  border: 2px solid green;
}

/* set transformorigin */

.svgChild,
.childNodes {
  transition: 0.3s;
  transform-origin: center;
}

/* ensure scaled element don't get cropped when scaled */

.svgChild {
  overflow: visible;
}

.hoverElement:hover {
  transform: scale(1.3);
  opacity: 0.5;
}

<div class="wrap">
  <p>Scale nested svg on hover –<br />not working in chrome</p>
  <svg class="svgParent" viewBox="0 0 100 100">
    <svg class="svgChild hoverElement" x="20" y="20" width="48" height="48" viewBox="0 0 24 24">
      <circle cx="12" cy="12" r="12" fill="#ccc" />
    </svg>
  </svg>
</div>
<div class="wrap">
  <p>Scale group in nested svg on hover</p>
  <svg class="svgParent" viewBox="0 0 100 100">
    <svg class="svgChild" x="20" y="20" width="48" height="48" viewBox="0 0 24 24">
      <g class="childNodes hoverElement">
        <circle cx="12" cy="12" r="12" fill="#ccc" />
      </g>
    </svg>
  </svg>
</div>

For a consistent display in both firefox and chromium you could wrap your planets' child elements an additional group like so:

<svg x="129.2" y="62.1" width="26" height="26" viewBox="0 0 36 36">
  <g class="planetwrap">
    <circle fill="#88C9F9" cx="18" cy="18" r="18" />
    <path fill="#5C913B" d="M25.716 1.756c-1.022.568-1.872 1.528-3.028 1.181-1.875-.562-4.375-1.812-6-.25s-2 3 0 2.938 3.375-2.438 4.375-1.438.749 1.813-1.625 2.125S14.5 7 13.125 7s-1.688.812-.75 1.688-.563.937-2.125 1.812.375 1.25 1.688 2 2.312-.188 2.875-1.438 2.981-2.75 3.99-2.562c1.01.188 1.01.688.822 1.562s.75.625.812-.375 1.188-1.75 2.062-1.812 1.625 1.188.625 1.812-2 1.125-.75 1.438 2.125 1.938.688 2.625-3.937 1.125-5.062.562-3.688-1.375-4.375-.938-1.062.89-1.875 1.195c-.812.305-4.125 1.805-4.188 3.743S7.438 22.438 8.75 22.5s4.5-.812 5.5-1.625 2.375-.625 2.812.312.125 1.5-.312 3 .286 2.25.987 3.562c.701 1.312 1.263 2.062 1.263 3s1 1.875 2.5.312 2.875-4.625 3.5-5.75 1.125-3.625 1.875-4.125 1.938-1.688 1.062-1.5-2.625-.062-3.062-1.312-2.312-3.625-1.438-3.875 1.875 1.39 2.25 2.164c.375.774.875 1.711 1.625 1.961s2.375-1.673 2.875-1.961c.5-.289.125-1.476-.875-1.351s-2.312 0-2.312-.624 1.25-1.438 2.25-1.25 1.75.5 2.375 1.25 1.875 2.125 2.375 3 .875 1 1.125-.562c.166-1.038.387-1.609.59-2.222-1.013-5.829-4.82-10.683-9.999-13.148z" />
  </g>
</svg>

Example grouped

If you can't optimize and save your tweaked planet assets statically you could use some js to do the wrapping job.

let planets = document.querySelectorAll('.recharts-reference-dot svg');

// wrap planet svg elements
planets.forEach(function(planet, i){
   planet.innerHTML = '<g class="planetwrap">'+ planet.innerHTML +'</g>';
})

.recharts-reference-dot svg{
  overflow:visible;
}

.planetwrap{
  transform-origin:center;
  transition: 0.3s transform
}

.planetwrap:hover{
  transform:scale(1.5)
}

<div class="recharts-wrapper" style="position: relative; cursor: default; width: 899px; height: 199.778px;"><svg id="masse_distance" class="recharts-surface" width="899" height="199.77777777777777" viewBox="0 0 899 199.77777777777777" version="1.1">
    <defs>
      <clipPath id="masse_distance-clip">
        <rect x="70" y="20" height="139.77777777777777" width="809"></rect>
      </clipPath>
    </defs>
    <g class="recharts-layer recharts-cartesian-axis recharts-xAxis xAxis">
      <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-line" stroke="#666" fill="none" x1="70" y1="159.77777777777777" x2="879" y2="159.77777777777777"></line>
      <g class="recharts-cartesian-axis-ticks">
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="231.8" y1="165.77777777777777" x2="231.8" y2="159.77777777777777"></line><text name="masse" type="number" orientation="bottom" width="809" height="30" x="231.8" y="167.77777777777777" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="middle">
            <tspan x="231.8" dy="0.71em">0.01 Mjup</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="308.99821901364135" y1="165.77777777777777" x2="308.99821901364135" y2="159.77777777777777"></line><text name="masse" type="number" orientation="bottom" width="809" height="30" x="308.99821901364135" y="167.77777777777777" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="middle">
            <tspan x="308.99821901364135" dy="0.71em">0.03 Mjup</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="393.6" y1="165.77777777777777" x2="393.6" y2="159.77777777777777"></line><text name="masse" type="number" orientation="bottom" width="809" height="30" x="393.6" y="167.77777777777777" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="middle">
            <tspan x="393.6" dy="0.71em">0.1 Mjup</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="555.4" y1="165.77777777777777" x2="555.4" y2="159.77777777777777"></line><text name="masse" type="number" orientation="bottom" width="809" height="30" x="555.4" y="167.77777777777777" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="middle">
            <tspan x="555.4" dy="0.71em">1 Mjup</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="717.2" y1="165.77777777777777" x2="717.2" y2="159.77777777777777"></line><text name="masse" type="number" orientation="bottom" width="809" height="30" x="717.2" y="167.77777777777777" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="middle">
            <tspan x="717.2" dy="0.71em">10 Mjup</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="masse" type="number" orientation="bottom" width="809" height="30" x="70" y="159.77777777777777" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="879" y1="165.77777777777777" x2="879" y2="159.77777777777777"></line><text name="masse" type="number" orientation="bottom" width="809" height="30" x="873.265625" y="167.77777777777777" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="middle">
            <tspan x="873.265625" dy="0.71em">100 Mjup</tspan>
          </text>
        </g>
      </g>
    </g>
    <g class="recharts-layer recharts-cartesian-axis recharts-yAxis yAxis">
      <line name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="10" y="20" class="recharts-cartesian-axis-line" stroke="#666" fill="none" x1="70" y1="20" x2="70" y2="159.77777777777777"></line>
      <g class="recharts-cartesian-axis-ticks">
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="10" y="20" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="64" y1="124.83333333333333" x2="70" y2="124.83333333333333"></line><text name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="62" y="124.83333333333333" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="end">
            <tspan x="62" dy="0.355em">1 jour</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="10" y="20" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="64" y1="89.88888888888887" x2="70" y2="89.88888888888887"></line><text name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="62" y="89.88888888888887" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="end">
            <tspan x="62" dy="0.355em">100 jour</tspan>
          </text>
        </g>
        <g class="recharts-layer recharts-cartesian-axis-tick">
          <line name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="10" y="20" class="recharts-cartesian-axis-tick-line" stroke="#666" fill="none" x1="64" y1="61.208688458136685" x2="70" y2="61.208688458136685"></line><text name="periode orbitale" type="number" orientation="left" width="60" height="139.77777777777777" x="62" y="61.208688458136685" stroke="none" fill="#666" class="recharts-text recharts-cartesian-axis-tick-value" text-anchor="end">
            <tspan x="62" dy="0.355em">4380 jour</tspan>
          </text>
        </g>
      </g>
    </g>
    <g class="recharts-layer recharts-reference-dot">
      <g>
        <svg x="129.19821901364134" y="62.06438300713549" width="26" height="26" viewBox="0 0 36 36">
          <circle fill="#88C9F9" cx="18" cy="18" r="18"></circle>
          <path fill="#5C913B" d="M25.716 1.756c-1.022.568-1.872 1.528-3.028 1.181-1.875-.562-4.375-1.812-6-.25s-2 3 0 2.938 3.375-2.438 4.375-1.438.749 1.813-1.625 2.125S14.5 7 13.125 7s-1.688.812-.75 1.688-.563.937-2.125 1.812.375 1.25 1.688 2 2.312-.188 2.875-1.438 2.981-2.75 3.99-2.562c1.01.188 1.01.688.822 1.562s.75.625.812-.375 1.188-1.75 2.062-1.812 1.625 1.188.625 1.812-2 1.125-.75 1.438 2.125 1.938.688 2.625-3.937 1.125-5.062.562-3.688-1.375-4.375-.938-1.062.89-1.875 1.195c-.812.305-4.125 1.805-4.188 3.743S7.438 22.438 8.75 22.5s4.5-.812 5.5-1.625 2.375-.625 2.812.312.125 1.5-.312 3 .286 2.25.987 3.562c.701 1.312 1.263 2.062 1.263 3s1 1.875 2.5.312 2.875-4.625 3.5-5.75 1.125-3.625 1.875-4.125 1.938-1.688 1.062-1.5-2.625-.062-3.062-1.312-2.312-3.625-1.438-3.875 1.875 1.39 2.25 2.164c.375.774.875 1.711 1.625 1.961s2.375-1.673 2.875-1.961c.5-.289.125-1.476-.875-1.351s-2.312 0-2.312-.624 1.25-1.438 2.25-1.25 1.75.5 2.375 1.25 1.875 2.125 2.375 3 .875 1 1.125-.562c.166-1.038.387-1.609.59-2.222-1.013-5.829-4.82-10.683-9.999-13.148z"></path>
        </svg>
        </g><text x="167.19821901364134" y="70.06438300713549">Terre</text>
    </g>

  </svg></div>


问:
flutter GridView.builder rotation
I have gridview with horizontal direction. Currently builder create elements top to bottom but i want gridview create an elements to start from the bottom.

```<code> GridView.builder(
                                reverse: false,
                                gridDelegate:
                                    new SliverGridDelegateWithFixedCrossAxisCount(
                                  crossAxisCount: 5,
                                  crossAxisSpacing: 8,
                                  mainAxisSpacing: 15,
                                ),

                                //dragStartBehavior: DragStartBehavior.start,
                                itemCount: koltuklar.length,
                                shrinkWrap: true,
                                primary: false,
                                scrollDirection: Axis.horizontal,
                                //dragStartBehavior: DragStartBehavior.start,
                                itemBuilder: (BuildContext ctx, index) {
                                  return Container(
                                      alignment: Alignment.center,
                                      child: Text(koltuklar[index]
                                          .nKoltukNo
                                          .toString()));
                                }),
</code>```

Thanks for your help

答:
You can't do it with GridView.builder constructor but you can simply hack. You can use RotatedBox to hack, I made an example for you.

SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: RotatedBox(
              quarterTurns: 3,
              child: GridView.builder(
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 5,
                  crossAxisSpacing: 8,
                  mainAxisSpacing: 15,
                ),
                itemCount: koltuklar.length,
                scrollDirection: Axis.vertical,
                physics: NeverScrollableScrollPhysics(),
                itemBuilder: (context, index) {
                  return Container(
                      alignment: Alignment.center,
                      child: Text(koltuklar[index]
                          .nKoltukNo
                          .toString()));
                },
              ),
            ),
          )
```

Title: flutter GridView.builder rotation

Body:
I have gridview with horizontal direction. Currently builder create elements top to bottom but i want gridview create an elements to start from the bottom.

 GridView.builder(
                                reverse: false,
                                gridDelegate:
                                    new SliverGridDelegateWithFixedCrossAxisCount(
                                  crossAxisCount: 5,
                                  crossAxisSpacing: 8,
                                  mainAxisSpacing: 15,
                                ),

                                //dragStartBehavior: DragStartBehavior.start,
                                itemCount: koltuklar.length,
                                shrinkWrap: true,
                                primary: false,
                                scrollDirection: Axis.horizontal,
                                //dragStartBehavior: DragStartBehavior.start,
                                itemBuilder: (BuildContext ctx, index) {
                                  return Container(
                                      alignment: Alignment.center,
                                      child: Text(koltuklar[index]
                                          .nKoltukNo
                                          .toString()));
                                }),

Thanks for your help


答:
The variable i in the outer loop takes on the values

```<code>i = 1, 2, 4, 8, ... X
</code>```

where X is the smallest power of 2 larger than n (so X <= 2n).

For example, when n = 32:

```<code>i = 1, 2, 4, 8, 16, 32, 64.
</code>```

Your inner loop runs n/i times (this might be rounded up or down, which is inconsequential here).

For example, when n = 32, the inner loop will run:

```<code>32/1 + 32/2 + 32/4 + 32/8 + 32/16 + 32/32 + 32/64
=
32 + 16 + 8 + 4 + 2 + 1 + 0
= 63 times
</code>```

If you reverse the sum, you get the sum of all powers of 2 less than or equal to n, which is Theta(n) (at most 2n).

Title: What is time complexity of this algorithm ? (inner loop changes due to outer loop)

Body:
The variable i in the outer loop takes on the values

i = 1, 2, 4, 8, ... X

where X is the smallest power of 2 larger than n (so X <= 2n).

For example, when n = 32:

i = 1, 2, 4, 8, 16, 32, 64.

Your inner loop runs n/i times (this might be rounded up or down, which is inconsequential here).

For example, when n = 32, the inner loop will run:

32/1 + 32/2 + 32/4 + 32/8 + 32/16 + 32/32 + 32/64
=
32 + 16 + 8 + 4 + 2 + 1 + 0
= 63 times

If you reverse the sum, you get the sum of all powers of 2 less than or equal to n, which is Theta(n) (at most 2n).


问:
A value 'window' cannot be determined statically
In my Angular 12 app I have a module like

```<code>@NgModule({
  imports:      [ window.config.myConfXY ? ModuleX : ModuleY ],
  providers:    [ ... ],
  declarations: [ ]
})
export class AppModule { }
</code>```

but the compiler complains with: "A value for 'window' cannot be determined statically, as it is an external declaration."

I am trying to deploy the app in an nginx container passing in some environment variables. A generated "env.js" is referenced in index.html and defines the window.config.

What does the error mean and how can I fix that? Unfortunately, I found nothing useful regarding the error description on the web.

答:
As per my understanding, this is not possible.

The Angular compiler needs to evaluate the NgModule imports during the build time itself i.e it needs to statically evaluate the conditions. It needs to know the value during the compilation and cannot wait to evaluate these until runtime. There is no way for the compiler to know about window object values during the compile time.

Considering we are not declaring window object ourselves within the application and Angular not being able to determine its value at compile time, hence the below error:

A value for 'window' cannot be determined statically, as it is an external declaration.
```

One possible solution would be to make use of the environment files. We have fileReplacements in angular.json file and so we can define a config property within an environment file. Since we can have multiple files based on the different environments, during the build the compiler should be able to evaluate the environment config property value statically.

Resources:

Conditional Module imports

How the Angular Compiler Works

Configure target-specific file replacements

Body:
In my Angular 12 app I have a module like

@NgModule({
  imports:      [ window.config.myConfXY ? ModuleX : ModuleY ],
  providers:    [ ... ],
  declarations: [ ]
})
export class AppModule { }

but the compiler complains with: "A value for 'window' cannot be determined statically, as it is an external declaration."

I am trying to deploy the app in an nginx container passing in some environment variables. A generated "env.js" is referenced in index.html and defines the window.config.

What does the error mean and how can I fix that? Unfortunately, I found nothing useful regarding the error description on the web.

Body:
As per my understanding, this is not possible.

The Angular compiler needs to evaluate the NgModule imports during the build time itself i.e it needs to statically evaluate the conditions. It needs to know the value during the compilation and cannot wait to evaluate these until runtime. There is no way for the compiler to know about window object values during the compile time.

Considering we are not declaring window object ourselves within the application and Angular not being able to determine its value at compile time, hence the below error:

A value for 'window' cannot be determined statically, as it is an external declaration.

One possible solution would be to make use of the environment files. We have fileReplacements in angular.json file and so we can define a config property within an environment file. Since we can have multiple files based on the different environments, during the build the compiler should be able to evaluate the environment config property value statically.

Resources:

Conditional Module imports

How the Angular Compiler Works

Configure target-specific file replacements


问:
Pivot the aggregate: getting wrong result
Table 1:

```<code>CREATE TABLE Main (patient VARCHAR(5), surgery_date date);
INSERT INTO Main VALUES
   ('P01','2018-01-01'),
   ('P02','2019-01-02'),
   ('P03','2019-01-03'),
   ('P04','2020-07-07');
</code>```

Table 2:

```<code>CREATE TABLE Additional (patient VARCHAR(5), record_date date, bpm integer);
INSERT INTO Additional VALUES
   ('P01','2018-01-01',60),
   ('P01','2018-02-01',49),
   ('P01','2018-02-10',52),
   ('P01','2018-03-10',57),
   ('P01','2018-04-10',57),
   ('P02','2019-01-02',46),
   ('P02','2019-02-02',55),
   ('P02','2019-03-02',55),
   ('P03','2019-01-03',60),
   ('P03','2019-02-03',49),
   ('P03','2019-03-03',49),
   ('P04','2021-07-07',71),
   ('P04','2021-08-07',49),
   ('P04','2021-09-07',49);
</code>```

First table has surgery date and second table has bpm readings post surgery......I want to have % of patient having avg bpm (averaged over calendar month) of > 50 in first and second calendar month post surgery. (need to ignore all data after second calendar month of surgery)

This is my attempt:

```<code>SELECT
   FORMAT(surgery_date,'yyyy-MM') as [Month],
   count(*) as [New_Surgery],
   (100*SUM(COALESCE(CASE WHEN b1.bpm>50 THEN 1 ELSE 0 END,0))) as [Month1_percentage],
   (100*SUM(COALESCE(CASE WHEN b2.bpm>50 THEN 1 ELSE 0 END,0))) as [Month2_percentage]
FROM Main a
LEFT JOIN Additional b1 On b1.patient=a.patient and b1.record_date=a.surgery_date
LEFT JOIN Additional b2 On b2.patient=a.patient and b2.record_date=DATEADD(M,1,a.surgery_date)
GROUP BY FORMAT(surgery_date,'yyyy-MM')
</code>```

But this is not giving me what it should.

My expectation is:

```<code>Month   New_Surgery Month1_percentage   Month2_percentage
2018-01 1   100 100
2019-01 2   50  50
2020-07 1   100 0
</code>```

答:
I have a feeling I've over-complicated this by breaking into several stages using a couple of CTEs, by first limiting rows to just those required and then pivoting the bpm column before calculating the percentages, however it does return your desired results.

Your main table is - for these results - superfluous since all the data exists in the Additional table; you can of course join with the main table if there are additional columns to retrieve that are omitted here.

```<code>with d as (
  select *,
    First_Value(record_date) over(partition by patient order by record_date) Sdate,
    Avg(bpm) over(partition by patient, Year(record_date), Month(record_date)) av
    from Additional
), m as (
    select patient, record_date, Format(sdate,'yyyy-MM') [Month],
      case when Month(record_date)=Month(sdate) and av >= 50 then av end m1,
      case when Month(record_date)>Month(sdate) and av >= 50 then av end m2
    from d
    where DateDiff(month, sdate, record_date) < 2
), p as (
    select Min([Month])[Month],
      Count(m1) * 1.0 / Count(*) * 100 M1Percent,
      Count(m2) * 1.0 / Count(*) * 100 M2Percent,
      Count(distinct patient) [New_Surgery]
    from m
    group by Year(record_date), Month(record_date)
)
select [month], Max([New_Surgery]) [New_Surgery],
    Max(M1Percent) Month1_Percentage,
    Max(M2Percent) Month2_Percentage
from p
group by [Month]
order by [Month]
</code>```

Working DB<>Fiddle

Body:
Table 1:

CREATE TABLE Main (patient VARCHAR(5), surgery_date date);
INSERT INTO Main VALUES
   ('P01','2018-01-01'),
   ('P02','2019-01-02'),
   ('P03','2019-01-03'),
   ('P04','2020-07-07');

Table 2:

CREATE TABLE Additional (patient VARCHAR(5), record_date date, bpm integer);
INSERT INTO Additional VALUES
   ('P01','2018-01-01',60),
   ('P01','2018-02-01',49),
   ('P01','2018-02-10',52),
   ('P01','2018-03-10',57),
   ('P01','2018-04-10',57),
   ('P02','2019-01-02',46),
   ('P02','2019-02-02',55),
   ('P02','2019-03-02',55),
   ('P03','2019-01-03',60),
   ('P03','2019-02-03',49),
   ('P03','2019-03-03',49),
   ('P04','2021-07-07',71),
   ('P04','2021-08-07',49),
   ('P04','2021-09-07',49);

First table has surgery date and second table has bpm readings post surgery......I want to have % of patient having avg bpm (averaged over calendar month) of > 50 in first and second calendar month post surgery. (need to ignore all data after second calendar month of surgery)

This is my attempt:

SELECT
   FORMAT(surgery_date,'yyyy-MM') as [Month],
   count(*) as [New_Surgery],
   (100*SUM(COALESCE(CASE WHEN b1.bpm>50 THEN 1 ELSE 0 END,0))) as [Month1_percentage],
   (100*SUM(COALESCE(CASE WHEN b2.bpm>50 THEN 1 ELSE 0 END,0))) as [Month2_percentage]
FROM Main a
LEFT JOIN Additional b1 On b1.patient=a.patient and b1.record_date=a.surgery_date
LEFT JOIN Additional b2 On b2.patient=a.patient and b2.record_date=DATEADD(M,1,a.surgery_date)
GROUP BY FORMAT(surgery_date,'yyyy-MM')

But this is not giving me what it should.

My expectation is:

Month   New_Surgery Month1_percentage   Month2_percentage
2018-01 1   100 100
2019-01 2   50  50
2020-07 1   100 0

Body:
I have a feeling I've over-complicated this by breaking into several stages using a couple of CTEs, by first limiting rows to just those required and then pivoting the bpm column before calculating the percentages, however it does return your desired results.

Your main table is - for these results - superfluous since all the data exists in the Additional table; you can of course join with the main table if there are additional columns to retrieve that are omitted here.

with d as (
  select *,
    First_Value(record_date) over(partition by patient order by record_date) Sdate,
    Avg(bpm) over(partition by patient, Year(record_date), Month(record_date)) av
    from Additional
), m as (
    select patient, record_date, Format(sdate,'yyyy-MM') [Month],
      case when Month(record_date)=Month(sdate) and av >= 50 then av end m1,
      case when Month(record_date)>Month(sdate) and av >= 50 then av end m2
    from d
    where DateDiff(month, sdate, record_date) < 2
), p as (
    select Min([Month])[Month],
      Count(m1) * 1.0 / Count(*) * 100 M1Percent,
      Count(m2) * 1.0 / Count(*) * 100 M2Percent,
      Count(distinct patient) [New_Surgery]
    from m
    group by Year(record_date), Month(record_date)
)
select [month], Max([New_Surgery]) [New_Surgery],
    Max(M1Percent) Month1_Percentage,
    Max(M2Percent) Month2_Percentage
from p
group by [Month]
order by [Month]

Working DB<>Fiddle


问:
Problem in docker images it is not starting
I made in my project nginx, mysql, phpMyadmin, encore and php images.
Just php and encore dosent work, they are successed built, but the are with red color.

The directory of the project:

that is my docker-compose.yml:

```<code>version: '3.3'
services:
 database:
   container_name: database
   image: mysql:8.0
   restart: always
   command: --default-authentication-plugin=mysql_native_password
   environment:
     MYSQL_ROOT_PASSWORD: alsbls
     MYSQL_DATABASE: infoSystem
     MYSQL_USER: alsbls
     MYSQL_PASSWORD: alsbls
   ports:
     - '4306:3306'
   volumes:
     - ./mysql:/var/lib/mysql

 php:
   container_name: php
   restart: always
   build:
     context: ./php
   ports:
     - '9000:9000'
   volumes:
     - ./app:/var/www/infoSystem

   depends_on:
     - database

 nginx:
   container_name: nginx
   image: nginx:stable-alpine
   restart: always
   ports:
     - '8080:80'
   volumes:
     - ./app:/var/www/infoSystem
     - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
   depends_on:
     - php
     - database

 phpmyadmin:
   image: phpmyadmin/phpmyadmin:latest
   restart: always
   environment:
     PMA_HOST: database
     PMA_USER: alsbls_root
     PMA_PASSWORD: alsbls_root
   ports:
     - "8081:81"

 encore:
   container_name: encore
   restart: always
   build:
     context: ./php
   volumes:
       - ./:/var/www/html
</code>```

That is my Dockerfile:

```<code>FROM php:8.0-fpm

RUN apt update   \
            && apt install -y zlib1g-dev g++ git libicu-dev zip libzip-dev zip \
            && docker-php-ext-install intl opcache pdo pdo_mysql \
            && pecl install apcu \
            && docker-php-ext-enable apcu \
            && docker-php-ext-configure zip \
            && docker-php-ext-install zip
WORKDIR /var/www/infoSystem
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN curl -sS https://get.symfony.com/cli/installer | bash
RUN mv /root/.symfony/bin/symfony /usr/local/bin/symfony
RUN git config --global user.email "devojob97@gmail.com" \
        && git config --global user.name  "alsbls"

FROM node:12.10.0
WORKDIR /var/www/html
COPY entrypoint.sh /usr/local/bin/entrypoint
RUN ["chmod", "+x", "/usr/local/bin/entrypoint"]
ENTRYPOINT ["/usr/local/bin/entrypoint"]
USER node
</code>```

that is the entrypoint.sh in the same dir of Dockerfile:

```<code>#!/bin/bash
# Prevent container from shutting down
while true; do sleep 3600; done
</code>```

I didn't receive any error message on the terminal.
Maybe some one now the issues.

Best regards

答:
I saw in the docker log of the encore image the following error:

```<code>standard_init_linux.go:190: exec user process caused "no such file or directory" - Docker
</code>```

And then I tried to use the following command outside of the container:

```<code>dos2unix your-file.sh
</code>```

This tutorial helped me to solve it:

Body:
I made in my project nginx, mysql, phpMyadmin, encore and php images.
Just php and encore dosent work, they are successed built, but the are with red color.

The directory of the project:

that is my docker-compose.yml:

version: '3.3'
services:
 database:
   container_name: database
   image: mysql:8.0
   restart: always
   command: --default-authentication-plugin=mysql_native_password
   environment:
     MYSQL_ROOT_PASSWORD: alsbls
     MYSQL_DATABASE: infoSystem
     MYSQL_USER: alsbls
     MYSQL_PASSWORD: alsbls
   ports:
     - '4306:3306'
   volumes:
     - ./mysql:/var/lib/mysql

 php:
   container_name: php
   restart: always
   build:
     context: ./php
   ports:
     - '9000:9000'
   volumes:
     - ./app:/var/www/infoSystem

   depends_on:
     - database

 nginx:
   container_name: nginx
   image: nginx:stable-alpine
   restart: always
   ports:
     - '8080:80'
   volumes:
     - ./app:/var/www/infoSystem
     - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
   depends_on:
     - php
     - database

 phpmyadmin:
   image: phpmyadmin/phpmyadmin:latest
   restart: always
   environment:
     PMA_HOST: database
     PMA_USER: alsbls_root
     PMA_PASSWORD: alsbls_root
   ports:
     - "8081:81"

 encore:
   container_name: encore
   restart: always
   build:
     context: ./php
   volumes:
       - ./:/var/www/html

That is my Dockerfile:

FROM php:8.0-fpm

RUN apt update   \
            && apt install -y zlib1g-dev g++ git libicu-dev zip libzip-dev zip \
            && docker-php-ext-install intl opcache pdo pdo_mysql \
            && pecl install apcu \
            && docker-php-ext-enable apcu \
            && docker-php-ext-configure zip \
            && docker-php-ext-install zip
WORKDIR /var/www/infoSystem
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN curl -sS https://get.symfony.com/cli/installer | bash
RUN mv /root/.symfony/bin/symfony /usr/local/bin/symfony
RUN git config --global user.email "devojob97@gmail.com" \
        && git config --global user.name  "alsbls"

FROM node:12.10.0
WORKDIR /var/www/html
COPY entrypoint.sh /usr/local/bin/entrypoint
RUN ["chmod", "+x", "/usr/local/bin/entrypoint"]
ENTRYPOINT ["/usr/local/bin/entrypoint"]
USER node

that is the entrypoint.sh in the same dir of Dockerfile:

#!/bin/bash
# Prevent container from shutting down
while true; do sleep 3600; done

I didn't receive any error message on the terminal.
Maybe some one now the issues.

Best regards

Body:
I saw in the docker log of the encore image the following error:

standard_init_linux.go:190: exec user process caused "no such file or directory" - Docker

And then I tried to use the following command outside of the container:

dos2unix your-file.sh

This tutorial helped me to solve it:


问:
Exiting all long trades when entering short trade
I use pyramiding. Lets say I have now 3 long trades open and then short trade condiction appears. Short trade entries, but at the same moment all opposite trades (in this example long trades) close.

How to have both long and short trades being open simultaneously?

答: I think, you can use same strategy twice, one is just for long, the other is just for short.</p>


问:
ImportError while importing pandas: gettz not built
Suddenly my python file won't run anymore due to an ImportError. I already tried updating/reinstalling pandas via conda but this didn't change anything.

```<code>  File "/p/tmp/user/env/lib/python3.7/site-packages/pandas/__init__.py", line 29, in <module>
    from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
  File "/p/tmp/user/env/lib/python3.7/site-packages/pandas/_libs/__init__.py", line 13, in <module>
    from pandas._libs.interval import Interval
  File "pandas/_libs/interval.pyx", line 1, in init pandas._libs.interval
  File "pandas/_libs/hashtable.pyx", line 1, in init pandas._libs.hashtable
  File "pandas/_libs/missing.pyx", line 1, in init pandas._libs.missing
  File "/p/tmp/user/env/lib/python3.7/site-packages/pandas/_libs/tslibs/__init__.py", line 30, in <module>
    from .conversion import OutOfBoundsTimedelta, localize_pydatetime
  File "pandas/_libs/tslibs/conversion.pyx", line 1, in init pandas._libs.tslibs.conversion
  File "pandas/_libs/tslibs/timezones.pyx", line 7, in init pandas._libs.tslibs.timezones
ImportError: cannot import name gettz

srun: error: cs-g14c06b11: task 0: Exited with exit code 1
srun: Terminating job step 19094047.0
The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/p/tmp/user/file_name.py", line 3, in <module>
    import pandas as pd
  File "/p/tmp/user/env/lib/python3.7/site-packages/pandas/__init__.py", line 37, in <module>
    ) from e
ImportError: C extension: gettz not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --force' to build the C extensions first.
</code>```

What could I try to fix this?

答:
step1: run pip uninstall pandas

step2: run pip install python-dateutil

step3: run pip install pandas

This resolved my issue.

Body:
Suddenly my python file won't run anymore due to an ImportError. I already tried updating/reinstalling pandas via conda but this didn't change anything.

  File "/p/tmp/user/env/lib/python3.7/site-packages/pandas/__init__.py", line 29, in <module>
    from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
  File "/p/tmp/user/env/lib/python3.7/site-packages/pandas/_libs/__init__.py", line 13, in <module>
    from pandas._libs.interval import Interval
  File "pandas/_libs/interval.pyx", line 1, in init pandas._libs.interval
  File "pandas/_libs/hashtable.pyx", line 1, in init pandas._libs.hashtable
  File "pandas/_libs/missing.pyx", line 1, in init pandas._libs.missing
  File "/p/tmp/user/env/lib/python3.7/site-packages/pandas/_libs/tslibs/__init__.py", line 30, in <module>
    from .conversion import OutOfBoundsTimedelta, localize_pydatetime
  File "pandas/_libs/tslibs/conversion.pyx", line 1, in init pandas._libs.tslibs.conversion
  File "pandas/_libs/tslibs/timezones.pyx", line 7, in init pandas._libs.tslibs.timezones
ImportError: cannot import name gettz

srun: error: cs-g14c06b11: task 0: Exited with exit code 1
srun: Terminating job step 19094047.0
The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/p/tmp/user/file_name.py", line 3, in <module>
    import pandas as pd
  File "/p/tmp/user/env/lib/python3.7/site-packages/pandas/__init__.py", line 37, in <module>
    ) from e
ImportError: C extension: gettz not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --force' to build the C extensions first.

What could I try to fix this?


问:
Typescript merge two interfaces

UPDATE

i found this solution

```<code>type Merge<T, U> = {
  [K in keyof T | keyof U]: K extends keyof U? U[K]: K extends keyof T? T[K]: never;
};
</code>```

is there something like this in typescript?(spread operator)

```<code>type Merge<T, U> = ...[K in keyof T]: T[K], ...[K in keyof U]: U[K]
</code>```

my task is to Merge two types into a new type. Keys of the second type overrides keys of the first type.
for example:

```<code>interface User {
  id: string;
  name: string;
  age: number;
  role: "admin" | "moderator" | "user";
  occupation: string;
}
interface User2 {
  id: string;
  name: string;
  age: boolean;
}

type mergedType = Merge<User, User2>
</code>```

after merge, interface type will be something like this->

```<code>{
  id: string;
  name: string;
  age: boolean;
  role: "admin" | "moderator" | "user";
  occupation: string;
}
</code>```

答:
I think you're looking for this

Here is a working example:

```<code>interface User {
  id: string;
  name: string;
  age: number;
  role: "admin" | "moderator" | "user";
  occupation: string;
}
interface User2 {
  id: string;
  name: string;
  age: boolean;
}

type Modify<T, R> = Omit<T, keyof R> & R;

var x: Modify<User, User2> = {id: '123', name: 'name', age: true, occupation: 'occ', role: 'admin'};
console.log(x);
</code>```

Title: Typescript merge two interfaces

Body:
UPDATE

i found this solution

type Merge<T, U> = {
  [K in keyof T | keyof U]: K extends keyof U? U[K]: K extends keyof T? T[K]: never;
};

is there something like this in typescript?(spread operator)

type Merge<T, U> = ...[K in keyof T]: T[K], ...[K in keyof U]: U[K]

my task is to Merge two types into a new type. Keys of the second type overrides keys of the first type.
for example:

interface User {
  id: string;
  name: string;
  age: number;
  role: "admin" | "moderator" | "user";
  occupation: string;
}
interface User2 {
  id: string;
  name: string;
  age: boolean;
}

type mergedType = Merge<User, User2>

after merge, interface type will be something like this->

{
  id: string;
  name: string;
  age: boolean;
  role: "admin" | "moderator" | "user";
  occupation: string;
}

Body:
I think you're looking for this

Here is a working example:

interface User {
  id: string;
  name: string;
  age: number;
  role: "admin" | "moderator" | "user";
  occupation: string;
}
interface User2 {
  id: string;
  name: string;
  age: boolean;
}

type Modify<T, R> = Omit<T, keyof R> & R;

var x: Modify<User, User2> = {id: '123', name: 'name', age: true, occupation: 'occ', role: 'admin'};
console.log(x);


问:
Are there any compression and encryption libraries in C#?
I want to compress some files (into the ZIP format) and encrypt them if possible using C#. Is there some way to do this?

Can encryption be done as a part of the compression itself?

答:
The GZipStream class is a native way to handle compression.

As for encryption, there are many ways to do it, most of them in the System.Security namespace. They can be done chained (encrypt a compressed stream or compress an encrypted stream).

OwnerDisplayName: Niyaz

ContentLicense: CC BY-SA 2.5

OwnerDisplayName: Vinko Vrsalovic


问:
Create multiple null containers in R (to be used in "for loop"), using a simple code
I'm creating empty null containers, to collect values from a "for loop".
Here is an example in my code, for which I've created 6 empty containers.

```<code>cont_min  <- NULL
cont_max  <- NULL
cont_unused <-  NULL
cont_n_rec  <- NULL
cont_n_don  <- NULL
cont_loop_time <- NULL
</code>```

I need to create quite a few of these and it's using a lot of space using a line of code for each.
Is there a way to create multiple containers without having a separate line of code? Many thanks

答:
You could use something like this:</p>
```<code>names <- c('min', 'max', 'unused', 'n_rec', 'n_don', 'loop_time')
var_lst <- sapply(paste0('cont_', names), function(x) assign(x, NULL))
list2env(var_lst, .GlobalEnv)
</code>```

Body:
I'm creating empty null containers, to collect values from a "for loop".
Here is an example in my code, for which I've created 6 empty containers.

cont_min  <- NULL
cont_max  <- NULL
cont_unused <-  NULL
cont_n_rec  <- NULL
cont_n_don  <- NULL
cont_loop_time <- NULL

I need to create quite a few of these and it's using a lot of space using a line of code for each.
Is there a way to create multiple containers without having a separate line of code? Many thanks

Body:
You could use something like this:

names <- c('min', 'max', 'unused', 'n_rec', 'n_don', 'loop_time')
var_lst <- sapply(paste0('cont_', names), function(x) assign(x, NULL))
list2env(var_lst, .GlobalEnv)


问:
React & Javascript - render field based on the result of an async function
I have an async function and want to use it to query and return a value, something like this:

```<code>  async function checkProfileFeature(values: any) {
    const data = await client.query<any>({
      query: PROFILE_QUERY,
      variables: { userId: 1, profileId: values.id },
    });

    if(something) {
      return true
    }
  }
</code>```

Based on this return value I want to display or not display a field:

```<code>  {checkProfileFeatures(profile) === true && (
    <Input .... />
  )}
</code>```

Unfortunately I can't get it to return the value and display the field on its result at the same time.
Is there a recommended way to do this?

答:
checkProfileFeature has a async keyword on it which basically means it will return a Promise, in your case Promise<boolean | undefined> (since you return true only if a certain condition is met). checkProfileFeatures(profile) === true will never be true because, as I already mentioned, your function returns a Promise. What you want to do is put your checkProfileFeatures inside a useEffect and then store results of the query inside a store of some kind or useState

```<code>// Run on first render
useEffect(() => {
 const fetchQuery = async () => {
  await checkProfileFeature({});
 }

 fetchQuery();
}, [])
</code>```

Then, inside checkProfileFeature save your results

```<code>async function checkProfileFeature(values: any) {
    const data = await client.query<any>({
      query: PROFILE_QUERY,
      variables: { userId: 1, profileId: values.id },
    });

    if(something) {
      setSomethingHappened(true);
    }
  }
</code>```

And in return body you can use this fetched value

```<code>{somethingHappened === true && (
    <Input .... />
  )}
</code>```

Of course you still need to figure out how to handle loading state, you may want to create an additional state which will tell whether the request is still running.

Body:
I have an async function and want to use it to query and return a value, something like this:

  async function checkProfileFeature(values: any) {
    const data = await client.query<any>({
      query: PROFILE_QUERY,
      variables: { userId: 1, profileId: values.id },
    });

    if(something) {
      return true
    }
  }

Based on this return value I want to display or not display a field:

  {checkProfileFeatures(profile) === true && (
    <Input .... />
  )}

Unfortunately I can't get it to return the value and display the field on its result at the same time.
Is there a recommended way to do this?

Body:
checkProfileFeature has a async keyword on it which basically means it will return a Promise, in your case Promise<boolean | undefined> (since you return true only if a certain condition is met). checkProfileFeatures(profile) === true will never be true because, as I already mentioned, your function returns a Promise. What you want to do is put your checkProfileFeatures inside a useEffect and then store results of the query inside a store of some kind or useState

// Run on first render
useEffect(() => {
 const fetchQuery = async () => {
  await checkProfileFeature({});
 }

 fetchQuery();
}, [])

Then, inside checkProfileFeature save your results

async function checkProfileFeature(values: any) {
    const data = await client.query<any>({
      query: PROFILE_QUERY,
      variables: { userId: 1, profileId: values.id },
    });

    if(something) {
      setSomethingHappened(true);
    }
  }

And in return body you can use this fetched value

{somethingHappened === true && (
    <Input .... />
  )}

Of course you still need to figure out how to handle loading state, you may want to create an additional state which will tell whether the request is still running.