MUI - Material-table/core - Provided selection does not work on checkbox click

Question: EDIT : This issue also concerns Material Ui's Data table. I tried using the same example as given by the documentation but the same problem occurs.
I have been battling with an issue regarding the provided selection feature where, when I click on a select, the box ripples, but does not get selected (no checkmark). The weird thing is that when I tried to create a code sandbox using the same components, everything worked just fine. I'm unsure how to debug this, but it seems that the environment is the cause.
I have forked the material-table-core/core project, and I am planning to do some debugging on there, but don't necessarily know where to look. Thought maybe some bored soul could offer some guidance here ?
It should be noted that if I try to control the checked state from "outside" of the table like instructed in this issue, the selection works just fine.
Here is a gif of the behavior :

The website is a PHP/contao legacy app on a Linux remote server with a lot of jquery all over the place, we recently decided to start using react and deprecating our jquery code gradually.
I am currently using a fork of @email@example.com. But no changes to the fork have been made yet. I just want to use it as a debugging tool.
As you can assume, react/webpack and babel have been manually installed and configured (not using CRA).
To understand how react is loaded, take a look at the following files  (stripped of all irrelevant code for clarity) :
Index.html5 : (most of these script tags are needed for the old legacy app)
<!DOCTYPE html>

    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,300;1,400;1,600;1,700;1,800&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp" rel="stylesheet">

    <?php include_once 'dist/styles.html5'; ?> <--- css build loads here

    ..html/scripts

  <?php include_once 'dist/main.html5'; ?> <--- react build loads here

Index.js :
import React, { StrictMode } from "react";
import { render } from "react-dom";
import "./Index.css";
import TimeTrackingTable from "./TimeTrackingTable";

const timeTrackingTable = document.getElementById(
  "time_tracking_react_component"
);

if (timeTrackingTable) {
  // console.log("timeTrackingTable", timeTrackingTable);
  render(
    <StrictMode>
      {/* <Provider store={store}> */}
      <TimeTrackingTable {...timeTrackingTable.dataset} />
      {/* </Provider> */}
    </StrictMode>,
    timeTrackingTable
  );
}

Timetracking component :
import React, { useState, forwardRef } from "react";
import MaterialTable from "@material-table/core";

import { Switch } from "@mui/material";
import {
  AddBox,
  ArrowUpward,
  Check,
  ChevronLeft,
  ChevronRight,
  Clear,
  DeleteOutline,
  Edit,
  FilterList,
  FirstPage,
  LastPage,
  Remove,
  SaveAlt,
  Search,
  ViewColumn,
} from "@mui/icons-material";

const tableIcons = {
  Add: forwardRef((props, ref) => <AddBox {...props} ref={ref} />),
  Check: forwardRef((props, ref) => <Check {...props} ref={ref} />),
  Clear: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
  Delete: forwardRef((props, ref) => <DeleteOutline {...props} ref={ref} />),
  DetailPanel: forwardRef((props, ref) => (
    <ChevronRight {...props} ref={ref} />
  )),
  Edit: forwardRef((props, ref) => <Edit {...props} ref={ref} />),
  Export: forwardRef((props, ref) => <SaveAlt {...props} ref={ref} />),
  Filter: forwardRef((props, ref) => <FilterList {...props} ref={ref} />),
  FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />),
  LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />),
  NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
  PreviousPage: forwardRef((props, ref) => (
    <ChevronLeft {...props} ref={ref} />
  )),
  ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
  Search: forwardRef((props, ref) => <Search {...props} ref={ref} />),
  SortArrow: forwardRef((props, ref) => <ArrowUpward {...props} ref={ref} />),
  ThirdStateCheck: forwardRef((props, ref) => <Remove {...props} ref={ref} />),
  ViewColumn: forwardRef((props, ref) => <ViewColumn {...props} ref={ref} />),
};

export default function TimeTrackingTable() {
  return (
    <>
      <MaterialTable
        title="$11.50 Menu"
        icons={tableIcons}
        columns={[{ title: "Section", field: "name" }]}
        data={menuSections}
        options={{
          selection: true,
          detailPanelColumnAlignment: "right",
          sorting: false,
          draggable: false,
          paging: true,
          pageSize: 5, // make initial page size
          emptyRowsWhenPaging: false, // To avoid of having empty rows
          tableLayout: "fixed",
        }}
        onSelectionChange={(rows, e) => {
          console.log("rows", rows);
          console.log("e", e);
        }}
        detailPanel={({ rowData }) => {
          return <RenderDetails rowData={rowData} />;
        }}
      />
      <SelectOutsideOfTable />{" "}
    </>
  );
}
function RenderDetails({ rowData }) {
  const [detailDataRow, setDetailDataRow] = useState({ ...rowData });

  return (
    <MaterialTable
      icons={tableIcons}
      title=""
      columns={[
        {
          title: "Item",
          field: "name",
          headerStyle: { backgroundColor: "royalblue", color: "white" },
        },
        {
          title: "Active",
          field: "active",
          headerStyle: { backgroundColor: "royalblue", color: "white" },
          render: ({ active }) => <Switch checked={active} />,
        },
      ]}
      data={detailDataRow.PartnerMenuItems}
      style={{
        backgroundColor: "aliceblue",
      }}
      options={{
        selection: true,
      }}
      onSelectionChange={(rows) =>
        alert("You selected " + rows.length + " rows")
      }
    />
  );
}

const menuSections = [
  {
    name: "Salads",
    PartnerMenuItems: [
      {
        name: "Farmers Salad",
        active: true,
      },
      {
        name: "Goat Cheese",
        active: true,
      },
      {
        name: "Champagne Vinaigrette",
        active: true,
      },
      {
        name: "Romaine Salad",
        active: true,
      },
      {
        name: "Cilantro Parmesan Dressing",
        active: true,
      },
      {
        name: "Asian Inspired Salad",
        active: true,
      },
      {
        name: "Cilantro Ginger Vinaigrette",
        active: true,
      },
      {
        name: "Beet Citrus Salad",
        active: true,
      },
      {
        name: "Maple Thyme Vinaigrette",
        active: true,
      },
    ],
  },
  .. etc i wont include all data here so not make the post too long
];

function SelectOutsideOfTable() {
  const [data, setData] = useState([
    {
      fruit: "Apple",
      id: 0,
    },
    {
      fruit: "Orange",
      id: 1,
    },
  ]);

  const toggleRowChecked = (row) => {
    return row.tableData && row.tableData.checked
      ? !row.tableData.checked
      : true;
  };

  const toggleSelectAll = () => {
    const newData = data.map((row) => ({
      ...row,
      tableData: {
        checked: toggleRowChecked(row),
      },
    }));
    setData(newData);
  };

  const columns = [
    {
      title: "Fruit",
      field: "fruit",
    },
    {
      title: "ID",
      field: "id",
    },
  ];

  return (

      <button onClick={toggleSelectAll}>Toggle Selection</button>
      <MaterialTable
        title="Select All External"
        columns={columns}
        data={data}
        options={{
          selection: true,
        }}
      />

  );
}

Package.json dependencies :
  "devDependencies": {
    "@babel/core": "^7.15.8",
    "@babel/preset-env": "^7.15.8",
    "@babel/preset-react": "^7.9.4",
    "babel-loader": "^8.2.2",
    "clean-webpack-plugin": "^4.0.0",
    "css-loader": "^6.4.0",
    "css-minimizer-webpack-plugin": "^3.1.1",
    "html-webpack-plugin": "^5.4.0",
    "html-webpack-skip-assets-plugin": "^1.0.3",
    "jquery-migrate": "^3.3.2",
    "mini-css-extract-plugin": "^2.4.3",
    "react-json-view": "^1.21.3",
    "style-loader": "^3.3.1",
    "webpack": "^5.59.1",
    "webpack-bundle-analyzer": "^4.5.0",
    "webpack-cli": "^4.9.1",
    "webpack-merge": "^5.8.0"
  },
  "dependencies": {
    "@emotion/react": "^11.7.1",
    "@emotion/styled": "^11.6.0",
    "@material-table/core": "https://github.com/HRpuls/core.git#dist",
    "@material-ui/core": "^4.12.3",
    "@material-ui/data-grid": "^4.0.0-alpha.37",
    "@material-ui/styles": "^4.11.4",
    "@mui/icons-material": "^5.1.0",
    "@mui/lab": "^5.0.0-alpha.56",
    "@mui/material": "^5.2.8",
    "@mui/styled-engine-sc": "^5.1.0",
    "@mui/styles": "^5.2.3",
    "@mui/x-data-grid": "^5.2.2",
    "axios": "^0.24.0",
    "bootstrap-table": "^1.19.1",
    "chart.js": "^3.6.2",
    "chartjs-plugin-datalabels": "^2.0.0",
    "date-fns": "^2.27.0",
    "jquery": "^3.6.0",
    "jquery-ui": "^1.13.0",
    "jspdf": "^2.5.0",
    "jspdf-autotable": "^3.5.23",
    "moment": "^2.29.1",
    "moment-range": "^4.0.2",
    "react": "^17.0.2",
    "react-bootstrap": "^2.0.2",
    "react-chartjs-2": "^4.0.0",
    "react-csv": "^2.2.1",
    "react-dom": "^17.0.2",
    "react-highlight-words": "^0.17.0",
    "react-hook-form": "^7.21.0",
    "react-player": "^2.9.0",
    "react-redux": "^7.2.6",
    "react-router-dom": "^6.1.1",
    "react-spinners": "^0.11.0",
    "react-swipeable-views": "^0.14.0",
    "react-table": "^7.7.0",
    "react-video-js-player": "^1.1.1",
    "redux": "^4.1.2",
    "redux-logger": "^3.0.6",
    "redux-promise-middleware": "^6.1.2",
    "redux-thunk": "^2.4.1",
    "signature_pad": "^4.0.1",
    "styled-components": "^5.3.3",
    "use-debounce": "^7.0.1"
  }

Answer: The problem was caused by css. Found some legacy code that gave all checkboxes inputs the following :
[type="checkbox"]:not(:checked),
[type="checkbox"]:checked {
  left: -99999px !important;
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
}

So I just needed to set those values to their initial state and that did the trick.


Is a balk scored differently from a "base on balls?

Question: Let's say you have men on first and third. The batter draws a "base on (four balls), and goes to first. The man on first is "pushed" to second, but the man on third stays where he is, because there is no "push" from second.
Now, suppose there are men on first and third. The pitcher balks. The batter goes to first, the man on first goes to second. But in this afternoon's Reds Pirates game, Homer Bailey's balk apparently sent the man on third home for a run,
Why would the rules be different for a balk than a base on balls?
Comment: Batter does not go to first.
Answer: Here is a good article.
As Wax Eagle has stated,

A balk has a different definition from a walk.
Walk
When a batter gets 4 balls they take first base, forced runners
  advance safely
Balk
When a pitcher balks, a ball is issued to the batter, all runners
  advance 1 base.

I have to correct something:
On a balk there is no ball issued if there are runners on base and it is not a violation of doctoring the ball.  If it is a violation of doctoring the ball, Wax Eagle is correct.  Most of the time (not always) a balk has to do with the pitcher having trouble with the "set position" (ie not coming all the way set, coming set in an illegal way, etc.).  All runners advance one base.  There are a few things about a balk depending on the situation:

If a pitcher balks and throws a pitch, the batter may swing and the play will be live.  The runners may advance without penalty one base forward.  However if the runner is tagged out after advancing safely one base, the balk is discarded and the live play is counted.
If the runners advance safely throughout the completion of the play, or they are tagged out or forced out before they reach the next base, the offense may select the result of the play or the balk.
The criteria for a balk with runners on and the bases empty are very different.  If you want more of an explanation on this let me know.
If there are no runners on, a balk will be counted as a ball to the batter.  Balks without runners on are very rare.

In the situation you describe, the batter would not walk if there is a balk unless he doctored the baseball, but both runners advance and the run scores.  On a walk, the man on first moves to second and the man on third may advance home at his own risk (may be tagged out by the defense for an out).
Mlb Rule 8, Pitching
Answer: The reason the balk advances the runners regardless of whether they are 'forced' to advance or not is that a balk is called to protect the runners from the pitcher using deception to cause them to leave their base early, and thus be picked off.  As such, when a balk is called, the game situation is treated as if the runners had been stealing a base, and they are awarded one base.  This goes a bit beyond a 'return to equity' of course, as often no runners are going when a balk is called, but that is the general reason.
From the comment on the specific rule:
Comment: Umpires should bear in mind that the purpose of the balk rule is to prevent the pitcher from deliberately deceiving the base runner.
  If there is doubt in the umpires mind, the intent of the pitcher should govern.

Additionally, a balk never results in a ball to the batter.  Instead, there are a few possible situations where a ball to the batter might be given instead of a balk, or in addition to a balk; but the term balk specifically applies only to the advancement of the runners.  Note the comment to 8.05e (the Quick Pitch rule):

With runners on base the penalty is a balk; with no runners on base, it is a ball.

And 8.02a (the Doctored Ball rule referred to by diggers), when a play occurs and the manager does not elect to accept the play's results:

(d) If the manager of the team at bat does not elect to accept the play, the umpire-inchief shall call an automatic ball and, if there are any runners on base, a balk.

In both cases, the balk and the ball are clearly separate items.
Also note that if a balk and a walk occur simultaneously - as could occur in either of the two above situations - any runners who would be 'forced' by the walk do not gain an additional base.
Answer: A balk has a different definition from a walk.
Walk

When a batter gets 4 balls they take first base, forced runners advance safely

Balk

When a pitcher balks, a ball is issued to the batter, all runners advance 1 base.

So in a first and third situation, if the pitcher balks, the runner on first goes to second, the runner on third goes home and if it's the fourth ball, the batter takes first base. In the event of a walk, the runner on third is not forced and stays put.
Comment: @BruceJames it's indicated as a BK for the runner who advances. Much the same way a stolen base is indicated SB.
Comment: So in a sense, a balk functions much like a "wild pitch." The batter gets a ball, and (de facto) all the base runners advance one base on a wild pitch. For a balk, it's de jure.
Comment: Basically, yeah. Though on a WP it's not free, runners can still be tagged out etc (and heck, a batter can swing at it...)
Comment: How do you write it on the score sheet?


Find significantly high values compared to others in a 1D array

Question: I have a number array and i want to pick only significantly big numbers from that array using some statistical method.
I tried calculating the average of the array and then subtracting each numbers from that avg and picked only values which are less than 0. like this. (for this number set correct answer should be 13 and 14 as you can notice).
<code>number array  : 10 10 7 13 10 10 14 10 10
avg = (10+10+7+13+10+10+14+10+10) / 9
avg = 10.44

10.44 - 10 > 0 (greater than zero. don't pick it)
...
10.44 - 13 < 0 (less than zero. Pick it).
</code>
But it doesn't always provide the correct answer
For example for this number array :-
<code> 10 10 7 14 10 10 7
</code>
the above method doesn't work as expected. It should only choose 14 but since the avg is 9.7 it chooses 10 as well.
So is there any way i can statistically pick the significantly high numbers compared to others from a given array reliably.
For example:
<code> 10 10 7 13 10 10 14 10 10 --> **13** and **14**

 10 10 7 14 10 10 7 --> **14**
</code>
Answer: What you are asking for is a way of detecting outliers. The most well-known rules define outliers based on the number of standard deviations from the mean, with popular threshholds being 2, 2.5, and 3. There is no particular science for deciding how to set the threshold for most real-world problems: the higher the threshold, the fewer outliers you will detect.
You also ask about identifying whether observations are "significantly high". This is a more complex issue. To decide that an outlier is "significantly high" you need to have a model that describes the distribution of values that you would expect to get. This will inevitably be different for different data sets (i.e., you need to work this out for yourself, there can be no magic rule applicable to all problems). The most common approach is to assume the data is generated as draws from a normal distribution, and if one does this you can come up with some more "scientific" rules (e.g., that values more than 1.96 standard deviations above or below the mean are "significant"). But, as your example data contains only positive integers, my guess is that a normal distribution is not going to be appropriate, and you will need to work out an appropriate count distribution, iff you are keen to meaningfully draw conclusions about whether values are "significantly high".
Comment: May be now it's bit late to ask but i tried the method in above comment with this data set : - 10 10 14 10 10 7 13 10 11 13 10 10. It is supposed to output the values 13 and 14 as outlires but it only outputs 14 since the upper outer fence is 13.75. How i can fix this.
Comment: Ok i'll try what you suggested. I already tried the method of finding outliers using Q3 + (1.5 * (Q3 - Q1)) for number array but didn't gave me a good answer.
Comment: Thanks. Sorry for the delay. It took me sometime to try it out and confirm it. the value 0.5 worked best for me :). Thanks for the insight.


How do I assign a view to a panel node in drupal

Question: I have a panel that shows a teaser of a bunch of nodes of a certain content type. I am attempting to replicate this for a new content type.
I have created a similar content type with the exact same fields. I have cloned the view(type = content pane) and changed the filter to the correct content type. I have now created a page of content type panel.
Question: How do I assign the view to that page(node)? Does it have something to do with display suite and the layout?
I am using Drupal 6.
EDIT: To put the above in another way:
I have a panel and I don't know how to apply a view to it. So I have my view that basically aggregates a bunch of nodes based on content type. I'm not sure how to add panel content to the panel. But the panel content being the query the view execute
Answer: If you are display the panel on a node then you need to add a variant of the node/%node page. In Drupal 7 you would

Edit the node_view (node/%node) page.
Press Clone to create a variant of your current page.
Under Selection rules add Node:type and select your new content type.
Ensure that the new variant is above your current variant, or add Selection rules to your current variant too.
In your new variant under Content replace the old View with the new View.

Note: If the only change to the View (and Page) is the Content type then you could have used the Content type of the node being viewed as a Contextual filter on the View. Then there would be no need for a Panel variant or another View.
Comment: I went to the /node/%node page and had a look at the existing variant. (Only one) It didn't look like it was the one for the content type I wanted to clone. What could this mean? (I'm somewhat new to drupal)

Could it have anything to do with "Display suite layouts" or "build modes"?
Comment: I disabled the variant and it didn't break any of the pages if that helps.
Comment: So you need to figure out which is the panel you are currently using and clone that. You can guess by comparing the path for the page you like and the paths of the enabled pages in Page Manager. Display Suite I can't help with. Is it possible you aren't using a panel page? Can you give an example path? Is it node/123 for example?


Why is the standard error in a diff-in-diff with 4 datapoints 'not well defined'?

Question: I was looking at this online book https://matheusfacure.github.io/python-causality-handbook/15-Synthetic-Control.html in order to learn about synthetic control. The author gets two cities in a panel with the target variable being analysed before and after an intervention. At some point, he says "However, note that the sample size here is 4, which is also the number of parameters in our Diff-in-Diff models. In this case, the standard error is not well defined...", what does he mean by NOT WELL DEFINED?
Answer: Because you have more free parameters than you do observations, hence there's no way to estimate their standard error. The model has free-parameters for: baseline, pre/post time, group indicator, the group by time interaction, and the standard error term.
Consider for a normal model, you need just one observation to estimate the mean, two observations for the mean and CI. In a bivariate linear model, you need just three observations to estimate the intercept and slope and CIs. Each parameter subtracts one from the degrees of freedom for the sampling distribution of the residual standard error until, overspecified, there is no distribution by which to compare it to, and consequently: no test.


What is reasonable storage failover time that most OS (VM) can tolerate?

Question: I have a GlusterFS 2 node 2 replica setup. I am planning to use it as OpenStack instance store, in which the VM disk image is stored.
From my tests, if the GlusterFS node which the hypervisor currently mounts on fails, (using default GlusterFS settings) it takes about 45 seconds for the connection to timeout and the glusterfs client fails over to the other node. During this 45 seconds IO operations will hang, from VM's perspective that means the disk become unresponsive.
I know for Linux, if the disk become unresponsive, after some time (I'm not sure how long) kernel will remount the filesystem as read-only.
I can also lower the value of GlusterFS volume's network.ping-timeout, which will reduce the failover time.
My question is, how much should I set this value such that most OS can tolerate the unresponsive time of virtual disk without side effects?
To be more precise, I would like to know the disk unresponsive time that Windows NTFS, FreeBSD UFS/ZFS and Linux ext4 can tolerate. What are the parameters involved? (for example, /sys/block/sda/device/timeout on Linux)
related information:

How to lower Gluster FS down peer timeout / reduce down peer impact?
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1009465

Update:
@the-wabbit has answered about Linux and Windows, I would also like to know the case of FreeBSD
Answer: The disk driver typically will wait until a configurable timeout is exceeded before even reporting an error for the operation requested.
As you have found out, this is /sys/block/<devicename>/device/timeout in Linux and defaults to 60 30 seconds.
Windows is storing this configuration as a global setting TimeoutValue (REG_DWORD) in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Disk\ with a 60 seconds default.
As long as no error is reported upstream, you will see no immediate action (like a ro-remount of the FS), even after the timeout is up you will typically see more error handler action (logging, resetting the device etc.) before an error is passed back to the upper layer.
But be aware that there will be other implications affecting overall availability.

applications or system services might implement own timeouts and throw exceptions on expiration
on servers with a high request turnaround, you will see queues fill up and memory exhaust as new clients keep submitting new requests with the old requests still waiting for the storage to respond.
if you happen to have swap space on the failed device, all page in / page out requests will stall, effectively blocking the processes working on these memory pages.

In general, you will want to keep the failover time as low as possible while still operating without premature failovers due to occasional load spikes or network glitches. Determining the right value for your use specific case is very much trial-and-error work over a prolonged period of operation. For general-use server VMs I would aim for something in the magnitude of 10 seconds, if feasible and supported by your infrastructure.
Comment: Strange, I spot checked a couple of Linux boxes and found the timeout set to 30 seconds. I don't recall having changed this, though it's possible that tuned did it.
Comment: @MichaelHampton no, you are right - [the default seems to be 30 seconds](http://www.docs.cloudbyte.com/knowledge-base-articles/customizing-disk-timeout-values-for-ha-settings-on-various-operating-systems/)
Comment: Are there other parameters involved?
Because `/sys/block//device/timeout` doesn't seem to have anything to do with filesystem, I believe there should be some other related filesystem parameters?
Answer: FreeBSD has the geom_mountver (https://www.freebsd.org/cgi/man.cgi?gmountver), which can be used to make it tolerate any failover time.  If you're using ZFS, you might need to disable the deadman timer; it will panic the box if an IO doesn't complete in 15 minutes (IIRC).


Handle redis connection reset

Question: We are facing [Errno 54] Connection reset by peer at very random in our application and looks like it is being triggered by redis server than client. Python's redis client have backoff strategy implementation but it's unable to handle this scenario.
There are github issues on official repo as well and many people commented recently confirming this problem.

Random ConnectionErrors (104, Connection reset by peer)
#1186
redis.exceptions.ConnectionError: Error while reading from socket: (104, 'Connection reset by peer') #1439

Step to reproduce
$ ipython
# in python client
import redis
from redis.retry import Retry
from redis.exceptions import (TimeoutError, ConnectionError)
from redis.backoff import ExponentialBackoff

# connect client with exponential backoff retry
client = redis.StrictRedis(retry=Retry(ExponentialBackoff(cap=10, base=1), 25), retry_on_error=[ConnectionError, TimeoutError, ConnectionResetError], health_check_interval=1)

client.keys()
# print all keys

Now reset connection directly from redis server
$ redis-cli
RESET

Wait for 120 second or more and run client again
# in client
client.keys()
---------------------------------------------------------------------------
ConnectionResetError                      Traceback (most recent call last)
<ipython-input-91-011ce9f936fc> in <module>
----> 1 client.keys("rq*")

~/path-to-python-env/env/lib/python3.8/site-packages/redis/commands/core.py in keys(self, pattern, **kwargs)
   1386         For more information check https://redis.io/commands/keys
   1387         """
-> 1388         return self.execute_command("KEYS", pattern, **kwargs)
   1389
   1390     def lmove(self, first_list, second_list, src="LEFT", dest="RIGHT"):

~/path-to-python-env/env/lib/python3.8/site-packages/redis/client.py in execute_command(self, *args, **options)
   1168         pool = self.connection_pool
   1169         command_name = args[0]
-> 1170         conn = self.connection or pool.get_connection(command_name, **options)
   1171
   1172         try:

~/path-to-python-env/env/lib/python3.8/site-packages/redis/connection.py in get_connection(self, command_name, *keys, **options)
   1315             # closed. either way, reconnect and verify everything is good.
   1316             try:
-> 1317                 if connection.can_read():
   1318                     raise ConnectionError("Connection has data")
   1319             except ConnectionError:

~/path-to-python-env/env/lib/python3.8/site-packages/redis/connection.py in can_read(self, timeout)
    793         if not sock:
    794             self.connect()
--> 795         return self._parser.can_read(timeout)
    796
    797     def read_response(self, disable_decoding=False):

~/path-to-python-env/env/lib/python3.8/site-packages/redis/connection.py in can_read(self, timeout)
    315
    316     def can_read(self, timeout):
--> 317         return self._buffer and self._buffer.can_read(timeout)
    318
    319     def read_response(self, disable_decoding=False):

~/path-to-python-env/env/lib/python3.8/site-packages/redis/connection.py in can_read(self, timeout)
    222
    223     def can_read(self, timeout):
--> 224         return bool(self.length) or self._read_from_socket(
    225             timeout=timeout, raise_on_timeout=False
    226         )

~/path-to-python-env/env/lib/python3.8/site-packages/redis/connection.py in _read_from_socket(self, length, timeout, raise_on_timeout)
    192                 sock.settimeout(timeout)
    193             while True:
--> 194                 data = self._sock.recv(socket_read_size)
    195                 # an empty string indicates the server shutdown the socket
    196                 if isinstance(data, bytes) and len(data) == 0:

ConnectionResetError: [Errno 54] Connection reset by peer

Running it second time works perfectly, though it should have taken care by Retry strategy.
client.keys()
# prints all keys

configuration
redis server - 6.2.6
python redis - 4.1.0

We can write our own try/catch around redis client, but we are using some libraries like rq and flask-cache which uses redis internally and have no interface to modify it's flow.
Any help is much appreciated.
Answer: I end up writing a custom class of Redis which retries on failure. Sharing it here in case anyone finds it useful.
import redis
import logging

from retry import retry

logger = logging.getLogger(__name__)

class RedisCustom(redis.Redis):
    def __init__(self, *args, **kwargs):
        super(RedisCustom, self).__init__(*args, **kwargs)

    @retry(ConnectionResetError, delay=0.1, tries=5)
    def set(self, key, value, ex=None, px=None, nx=False, xx=False):
        return super(RedisCustom, self).set(key, value, ex, px, nx, xx)

    @retry(ConnectionResetError, delay=0.1, tries=5)
    def get(self, name):
        return super(RedisCustom, self).get(name)

    @retry(ConnectionResetError, delay=0.1, tries=5)
    def delete(self, *names):
        return super(RedisCustom, self).delete(*names)

    @retry(ConnectionResetError, delay=0.1, tries=5)
    def hset(self, name, key=None, value=None, mapping=None):
        return super(RedisCustom, self).hset(name, key, value, mapping)

    @retry(ConnectionResetError, delay=0.1, tries=5)
    def hmset(self, name, mapping):
        return super(RedisCustom, self).hmset(name, mapping)

    @retry(ConnectionResetError, delay=0.1, tries=5)
    def hgetall(self, name):
        return super(RedisCustom, self).hgetall(name)

    @retry(ConnectionResetError, delay=0.1, tries=5)
    def scan_iter(self, match=None, count=None, _type=None, **kwargs):
        return super(RedisCustom, self).scan_iter(match, count, _type, **kwargs)

    @retry(ConnectionResetError, delay=0.1, tries=5)
    def hdel(self, name, *keys):
        return super(RedisCustom, self).hdel(name, *keys)

    @retry(ConnectionResetError, delay=0.1, tries=5)
    def keys(self, pattern="*", **kwargs):
        return super(RedisCustom, self).keys(pattern, **kwargs)

    @retry(ConnectionResetError, delay=0.1, tries=5)
    def info(self, section=None, **kwargs):
        return super(RedisCustom, self).info(section, **kwargs)

    @retry(ConnectionResetError, delay=0.1, tries=5)
    def ping(self, **kwargs):
        return super(RedisCustom, self).ping(**kwargs)

Answer: You can also set a healtcheck value,

client = redis.Redis(..., health_check_interval=30)

it will reestablish the connection.
More details in https://github.com/redis/redis-py/issues/1186
Answer: Try using a connection Pool as it will keep alive and automatically attempt to recover in the background. In the REPL
import redis
pool = redis.ConnectionPool(host="localhost", port=6379)
r = redis.Redis(connection_pool=pool)
r.ping()

In another shell you can test by running redis-cli
client LIST
client kill IP:PORT

Then run the
r.ping

And you should see a new connection in the redis-cli
client LIST

Comment: It's not working with `RESET` event. And redis internally uses pool by default if not specified.

Handle redis connection reset


Tentando passar valores da Controller para a Global.asax.cs para preencher as sessões

Question: Quando tento passar alguma valor de minha controller para a Global.asax os valores recebidos na global são sempre nulos.
Controller:
public class LoginController : Controller
{
    DataContext db = new DataContext();
    public ActionResult Index()
    {
        MvcApplication M = new MvcApplication()
        var U = db.usuarios.single(u=> u.Id == 1);
        M.SetCarregarDadosUsuario(U);
    }
}

Global:
public class MvcApplication : System.Web.HttpApplication {
    public Usuarios usuarioSession = new Usuarios();

    protected void Application_AcquireRequestState(){
        if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState){
            CarregarDadosUsuario();}
        }
        private void CarregarDadosUsuario(){
            if(usuarioSession.Id >0){
                var loadU = GetCarregarDadosUsuario();
                HttpContext.Current.Session.Add("UsuarioImagem", loadU.UrlImg);
                HttpContext.Current.Session.Add("UsuarioNome", loadU.Nome);
                HttpContext.Current.Session.Add("UsuarioSessao", loadU.SessaoID);
                HttpContext.Current.Session.Add("UsuarioFilial", loadU.FilialID);
            }
        }
        public void SetCarregarDadosUsuario(Usuarios user) {
            this.usuarioSession = user;
        }
        public Usuarios GetCarregarDadosUsuario(){
        return this.usuarioSession;
    }
}

Gostaria de saber como faço para passar um lavor de minha Controller para a Globlal.asax.cs para preencher minhas sessões.
Pois a finalidade das sessões será para adicionar valores no arquivo layout e definir permissões para não realizar consultar a banco a todo instante.
Exemplo:

Comment: Por que você quer fazer isso? Possivelmente não é a melhor forma de fazer.
Comment: Quero gravas as sessões para utiliza-las depois, no meu arquivo de _layout, poderia me dizer qual seria a melhor forma ?
Answer: Há várias formas de se fazer isso, vou te passar duas. Você pode fazer com sessão mesmo, porém você está criando a sessão de forma errada.
Com sessão
DataContext db = new DataContext();
public ActionResult Index()
{
    var U = db.usuarios.single(u=> u.Id == 1);
    Session["imagem"] = U.UrlImg;
    Session["nome"] = U.Nome;
    return View();
}

A view está correta:

Com Cache
Você pode jogar no cache a parte que exibe os dados do usuário, sendo assim a requisição com o banco dados e processamento da View será feita apenas uma vez pelo tempo definido. Isso irá dar mais performance à sua aplicação.

Defina uma View Parcial para exibir os dados do usuário
Indique que essa View é  ChildActionOnly e defina um OutputCache

No arquivo UsuarioController.cs:
    // multiplicando segundos por minutos
    [OutputCache(Duration = 60 * 60, Location = OutputCacheLocation.ServerAndClient)]
    [ChildActionOnly]
    public ActionResult DadosUsuario()
    {
        var user = db.usuarios.single(u=> u.Id == 1);
        return View(user);
    }

View (Views/Usuario/DadosUsuario.cshtml):
@model MeuProj.Usuario

Para chamar a View Parcial, provavelmente na _Layout.cshtml
@Html.Action("DadosUsuario", "UsuarioController")

Comment: Vlw mano, obrigado, ajudou bastante.


Measure dependence of categorical and ordinal variable

Question: My purpose: When trying to find out which variables of a generic questionnaire data set will show striking differences across columns in crosstabs, I first do correlation tests (or dependence tests) across all pairs of variables (similar to this question).
Let's say that the dataset only consists of categorical (i.e. nominal) data and ordinal data (from Likert scales).

For 1 nominal vs 1 nominal variable, I use the Fisher Exact Test or the Chi-Square Test of Independence.
For 1 nominal vs 1 ordinal variable or vice-versa, I would like to do a non-parametric test, but which one should I use?

I thought about Kruskal-Wallis, point-biserial correlation coefficient or Eta squared test, but I cannot evaluate which makes most sense for finding differences across categories (in case the crosstab has categorical var as columns) or ordinal categories (in case the crosstab has a Likert scale as columns).
"Down-grading" the ordinal vars to categorical would be one obvious work-around, but I would prefer not to lose the ordinal information. Thank you for recommendations.
Further links:

idre: What statistical analysis should I use?
Texas Arlington University: Nonparametric Statistics
Comment: Do you find some usefull answers in this list:  http://stats.stackexchange.com/search?q=+categorical+ordinal+
Comment: Another solution that comes to my mind is standardizing the ordinal measure to make it appear like a continuos one (from 1 up to k ordinal categories). That would give the ordinal measure an explicit "direction". Then if both variables are ordinal, a Pearson correlation would make sense. If one of them is nominal, a generic t-test for equal means could do the trick.
Answer: I can think of two measures of nonlinear dependencies for two discrete variables:

The Wijayatunga coefficient (https://arxiv.org/abs/1804.07937): Departing from the fact that Pearson correlation is a normalized, Euclidean type distance between joint probability distribution of the two random variables and that when their independence is assumed while keeping their marginal distributions, this measure uses all possible maximal dependences to measure any non-linear dependence. As it can measure non-linear dependencies, it can be used with nominal variables;
The Ordinal Classification Index (http://dx.doi.org/10.1142/S0218001411009093): This measure is more adequate to measure if the predictions about a dependent ordinal variable capture how much the result diverges from an ideal prediction. But because measures of accuracy are similar to measures of monotonic dependency, it can also probably be used in your context.

The problem with these measures is that I am not aware of any computational implementations other than the ones that I developed (e.g., https://github.com/vthorrf/wijayatunga).


Limits that occur in integrals during Feynmann integration

Question: When we use Feynman Integration, how do we decide the final constant of integration?
For example, in this problem:

$$ f(a) = \int_{0}^{1} \frac{\arctan(ax)}{\sqrt{1-x^2}} dx$$

After differentiating and integrating,
$$ f'(a) = \frac{\ln(a+\sqrt{1+a^2})}{a\sqrt{1+a^2}} $$
So we need to find out
$$ f(1) = \int_{0}^{1} \frac{\ln(a+\sqrt{1+a^2})}{a\sqrt{1+a^2}} da$$
How were the limits of the definite integral decided?
Answer: This just uses the Fundamental Theorem of Calculus, which gives us that
$$f(1) - f(0) = \int_0^1 f'(a) \,da.$$
For $$f(a) = \int_0^1 \frac{\arctan(ax)}{\sqrt{1 - x^2}} dx,$$ we have $f(0) = \int_0^1 0 \,dx = 0,$ and substituting gives the last display equation in the question.
Answer: You pick upper bound such that it matches the original integrand, and the lower bound such that it makes the original integrand 0.


Let $X_1, X_2,..., X_n$ be an i.i.d. sequence with distribution function $F_X$.

Question: Let $X_1, X_2,..., X_n$ be  an  i.i.d.  sequence  with  distribution  function $F_X$.
Define the samplestatistic $T=\frac{\#\{X_i\::\: X_i\: \in\: (-2,2)\}}{4n}$, where $\#A$ denotes the number of elements in the set $A$.
For large $n$, $T$ is with high probability approximately equal to?
(Result is: $\frac{P(-2<X<2)}{4}$)
I have no clue how to solve it, can someone help me, thanks in advance!
Answer: Let $Y_i$ equal $1$ if $X_i\in (-2,\,2)$ and $0$ otherwise, so $Y_i$ is Bernoulli-distributed, with $P(Y_i=1)=P(X_i\in (-2,\,2))$. Then $T_i$ is $1/4$ the mean of the $Y_i$, so the result follows from the central limit theorem.
Comment: Ohh, this makes sense! I got it! Thanks a lot :)


Hotmail SMTP doesn't work when App is on Server

Question: when I am registering or recovering my password while the application is depolying locally everything works fine. When I deploy it on a server I get an Error ocurred while processing your request. I am using .net mvc framework. Does anyone have any idea what is causing this?
Thanx in advance
Comment: It could be literally anything. Check firewall settings, as that's the most likely culprit.
Answer: It wasn't a big deal, I had to accept the request made by the server in my outlook account, and declare it was me that had sent it. That did it!


$ z_1^k+\cdots +z_n^k=0$ for all $k$ implies $z_i=0$ for all $i$

Question: Suppose $z_1,...,z_n\in \Bbb C$ are complex numbers, not necessarily distinct, satisfying $$ z_1^k+\cdots +z_n^k=0$$
$ \color{red}{\forall\; k>0}$. Then is it true that $z_1=\cdots=z_n=0$?
This will be obvious if the $z_i$'s  were all real, but I'm wondering that this is true for the complex case.
Comment: Also: https://math.stackexchange.com/q/811913/42969, https://math.stackexchange.com/q/1203786/42969, https://math.stackexchange.com/q/2963882/42969.
Comment: Yes it is true. Do you know how to covert those equations into showing that $\sum \prod_{i \text{terms} } x_ax_b \ldots  = 0$ ? Hence, by vieta, $z_i$ are the roots of $z^n = 0$, so $z_i = 0$.
Comment: @MartinR I doubt that the first link is related to this question. Well, maybe they are vaguely related via Newton's formulae.
Answer: Hint: Sure, if $k=2$ we have $z_1^2+...+z_n^2=0$ and $$(z_1+...+z_n)^2=0$$
so $$z_1z_2+...+z_{n-1}z_n=0$$
and so on... So by Newton formulas and Vieta formulas you get that coeficients of polynomial with zeroes $z_1,z_2...$ are zero which means that all $z_i=0$.
Answer: Another point of view, with recursion and linear algebra. Consider the following assumption hypothesis $H(n)$.
For all $z_1, \dots, z_n \in \mathbb{C}$, if for some $a_1, \dots, a_n > 0$, and all $k \in \{1, \dots, n\}$, we have
$$
a_1 z_1^k + \cdots + a_n z_n^k,
$$
then $z_1 = \cdots = z_n = 0$.
This a generalization of the result, necessary for the induction below.
So let us show this. Clearly, $H(1)$ is true, so assume $H(n-1)$, and take $z_1, \dots, z_n$ and $a_1, \dots, a_n$ as above. If one of the $z_i$ is $0$, then we use the $H(n-1)$ and we are done. Otherwise, consider the $n \times n$ matrix
$$
A = \begin{pmatrix}
1 & z_1 & z_1^2 & \cdots & z_1^{n-1} \\
1 & z_2 & z_2^2 & \cdots & z_2^{n-1} \\
\vdots & \vdots & \ddots & \vdots \\
1 & z_n & z_n^2 & \cdots & z_n^{n-1}
\end{pmatrix}.
$$
Then if $u$ is the vector $(a_1 z_1,a_2 z_2,\dots,a_n z_n)$ (which is non-zero by assumption), you are saying that $uA = 0$. In particular, $A$ is not invertible. But this is a Vandermonde matrix, so it means that two of the $z_i$ are the same, say for instance $z_1 = z_2$. Then we can use the assumption hypothesis with $z_1, z_3, \dots, z_n$ and $a_1+a_2, a_3, \dots, a_n$ (note that $a_1+a_2 > 0$), to find that all the $z_i$ are zero.
Note. The assumption on the $a_i$ being strictly positive could be improved to make this more general and work in any field of characteristic $0$, for instance by saying that any sum of the $a_i$ is non-zero.
Comment: I just realized that the comments above already mention a similar solution...
Comment: Is there an argument like this for proving $x_1^k+\dots+x_n^k = y_1^k+\dots+y_n^k$ for $0 \le k \le n-1$ implies $\{x_1,\dots,x_n\} = \{y_1,\dots,y_n\}$?
Comment: This seems more delicate. Just take $n=2$. Define $A = \begin{pmatrix} x_1 & x_1^2 \\ x_2 & x_2^2 \end{pmatrix}$, $B = \begin{pmatrix}  y_1 & y_1^2 \\  y_2 & y_2^2 \end{pmatrix}$, and let $u = (1,1)$. Then the assumption can be summarized as $u A = u B$. It tells that $A-B$ is not invertible, so its determinant $(x_1-y_1)(x_2-y_2)(x_2+y_2-x_1-y_1)$ is $0$. However, you cannot deduce from this that $\{x_1,y_1\} = \{x_2,y_2\}$. So you would need to get more from the assumption $uA = uB$, but I am not sure what.
Comment: lol, I asked that question because I know the exact same argument you used in your answer (which you tried to do in your comment above for $n=2$) will not work. I'm asking if there's any argument using linear algbera.
Comment: Not that I can think of.


What exactly is a "solver" in optimization?

Question: I am really confused by the usage of solver in computational optimization. I have looked around for a month on and off in order to see if I can get a good sense of what this term means yet I still do not have any good understanding of it.
It seems that, if I would like to solve an optimization problem in machine learning or elsewhere, I would refer to the exact computational procedure as an algorithm instead a solver. For example, if I had a quadratic program, I would use MATLAB's Quadprog function to solve the QP.
I would personally not refer to Quadprog function as a QP solver, because it is just a MATLAB function, or a script. I would not refer to the exact algorithm behind Quadprog as a QP solver, I don't care if it is gradient descent, interior point method, Newton Raphson...they are all algorithms to me. Finally, I would not refer to MATLAB as a QP solver because that is not MATLAB's sole purpose. So it seems that the word "solver" is missing from my everyday vocabulary despite having to routinely work with optimization, this confuses me quite a bit, it just feels I am not up to date with the lingo.
So by my reasoning, algorithms and MATLAB are not solvers. But suppose I have downloaded some softwares such as Gurobi or YALMIP to solve optimization problems, are these softwares called solvers? I have often time heard people referencing what "solver" you are using in sort of the same tone as what "software" you are using. What differentiate optimization softwares and solvers?
I know this sounds like a really rudimentary question, but I have only done optimization in MATLAB.
Comment: I've understood "solver" to mean an optimizer for problems with unique solutions, but perhaps I'm misinformed.
Comment: In general, a solver to optimization is similar as an engine is to driving. I would call Gurobi a solver, it's like an engine. MATLAB is like a car brand, it's the name for the overall environment.
Comment: I usually hear "solver" used to describe *software*, meaning it applies to an *implementation* of an algorithm. Generally the term will be reserved for mathematical problems with a "well-defined solution". A unique solution is sufficient, as @Sycorax says, and the [Gurobi](https://en.wikipedia.org/wiki/Gurobi) solvers seem to be for problems in this class. But I do not think unique is necessary, for example both local and global optimization problems can have well-defined but non-unique solutions.
Answer: A solver is a routine for finding exact numerical answers for determined systems. For example, when using Newton-Raphson to find root(s). When a system is overdetermined then one generally uses approximate solutions, for example, regression. One would generally not refer to regression as a solver, although, predictably language can be misused, and many routines that are approximate are loosely called solvers. For example, the CUTEr optimization software package contains algorithms at least some of which are for overdetermined systems, and some of which are solvers, so it becomes easy to say, I am downloading a "solver".  Both solvers and regression methods are examples of optimization methods.
Comment: A solver gives a solution. If the problem is "SOLVE $x+y=1$" then $x=1, y=0$ is a solution and it may return that solution (or any other solution)! To put it another way, is Python's `lstsq` not a linear system solver because it can solve undetermined systems?
Comment: yes, I agree I'm being nitpicky and apologize for that. If I were writing the answer, I wouldn't include the text "for determined systems." Otherwise though, excellent answer! (Eg. one other example... solvers for [boolean satisfiability](https://en.wikipedia.org/wiki/Boolean_satisfiability_problem) problems almost always have a multitude of solutions and the goal is to simply find one of them (in those problems, the systems are almost always undetermined).
Comment: Why does the system have to be determined? Can't it be underdetermined?  Eg. calling most any linear system solving routine on $x + y =1$ will return a solution.
Comment: @MatthewGunn Perhaps, but for $x+y=1$ one could use a random number generator because any random $x$ will generate a $y$. Now I suppose one could call a random number generator a "solver." However, I think you would admit, it is a stretch to do so. Usually, a solver would do something more organic with random numbers, if it uses them at all.
Comment: @MatthewGunn Besides, iterative methods of regression can be programmed to solve determined systems, but, that would not make them solvers, as their main use is for overdetermined systems.
Comment: @MatthewGunn Oh hush. When we call someone a bus driver, we do not mean he cannot drive a car. Just because I am a medical doctor does not mean that I cannot be a patient. We name things (and people) after their most demanding usage. And, the question was just one of those human definition thingies. You know, the icky type of thing (like statistics) that is inexact anyway.
Comment: @MatthewGunn For what it is worth, determined systems may have no solution, one solution, multiple real solutions, or a finite or trans finite number of complex solutions. So yes, sometimes we do not care if we have a best solution, as any solution will do, but sometimes we do care. I thought about using the term "determined system", and the shoe still fits, I think. If you want it changed, what would you change it to? I'm stumped on that.
Comment: (-1) You seem to be equating "solver" with "equation(s) solver". This limited scope is not consistent with the usage I hear (e.g. [here](http://scicomp.stackexchange.com/questions/tagged/solver)). You provide no evidence for your more limited definition, and your Wikipedia link lists several optimization problems in its examples of "problem classes with dedicated solvers". For problems like "regression" the determinacy of the equation system is irrelevant to the OP's question, i.e. mathematically linear least squares is solving an *optimization* problem, not an equation system.
Comment: Linear least squares is 1) an approximation to 2) a set of assumptions that 3) may be unrelated to a solution (-1).
Answer: I suggest a solver is:

a software package
that incorporates one or more algorithms
for finding solutions to one or more classes of problem

The classes of problem is part of it. It is a X solver.
So

I would call Gurobi "a MIP/LP solver".
And I would say "Matlab incorperates a QP solver, that it exposes via the Quadprog function.", In this case the actual "QP solver" may or may not exist as a stand alone product.
Concorde  is a TSP solver
Concorde incorporates  QSopt, which is a LP solver

I think this usage is in line with (for example) the JuMP documentation

JuMP is a domain-specific modeling language for mathematical optimization embedded in Julia. It currently supports a number of open-source and commercial solvers (see below) for a variety of problem classes, including linear programming, mixed-integer programming, second-order conic programming, semidefinite programming, and nonlinear programming.

Here is a list of things that JuMP calls solvers.
None of them are algorithms, all are specific programs
Answer: I usually hear "solver" used to describe software, meaning it applies to a particular implementation of an algorithm. For example, this seems to apply to most of the SciComp.SE questions tagged solver.
Generally the term seems to be reserved for mathematical problems with a "well-defined solution". A unique solution would qualify as "well defined" sufficient, as noted by Sycorax in the comments. (The Gurobi solvers seem to be for problems in this class; for what its worth, Gurobi looks like a suite or library of solvers to me).
But I do not think unique is necessary. For example both local and global optimization problems can have well-defined but non-unique solutions (e.g. the function $f[x]=\sin[\pi x]^2$ has global minimum $f[k]=0$ for $k\in\mathbb{Z}$).
I disagree with this answer, which seems to be discussing "equation-system solvers" rather than "optimization solvers". For example in linear least squares, the linear algebra problem is over-determined, but the optimization problem is convex, with a unique solution (in non-degenerate cases). Note also that the Wikipedia "solver" page linked in that answer lists "Linear and non-linear optimisation problems, Shortest path problems, Minimum spanning tree problems" among its examples.

In response to the comment, I will clarify what I mean in the "regression" case.
Given a function $F:\mathbb{R}^n\to\mathbb{R}^m$, a solution to the system of equations specified by
$$F[x]=0$$
is a vector $x\in\mathbb{R}^n$ such that all $m$ components of $F[x]$ are zero. Depending on the function $F$, there can be no solutions, a single unique solution, or many solutions (typically infinitely many), depending on the dimension of the null-space of $F$. In the case where $F$ is linear, i.e. $F[x]=Ax-b$ for some $A\in\mathbb{R}^{m\times{n}},b\in\mathbb{R}^m$, then no solution can exist unless $m\leq\mathrm{rank}[A]\leq n$.
On the other hand for a given objective function $E_F:\mathbb{R}^n\to\mathbb{R}$ and feasible set $\Omega_F\subset\mathbb{R}^n$, which depend on $F$, a solution to the optimization problem specified by
$$\epsilon=\min_{x\in\Omega_F}E_F[x]$$
is a vector $x\in\Omega_F$ such that $E_F[x]\leq E_F[y]$ for all $y\in\Omega_F$.
In "least squares" optimization, the function $E_F$ is a sum of squares. The two most common least squares problems are 1)
$$E_F[x]=\|F[x]\|^2 \text{ , } \Omega_F=\mathbb{R}^n$$
where $F$ corresponds to an overdetermined system of equations, and 2)
$$E_F[x]=\|x\|^2 \text{ , } \Omega_F=\{y\in\mathbb{R}^n\ \mid F[y]=0\}$$
where $F$ corresponds to an underdetermined system of equations.
Common linear algebra platforms, such as Matlab, may combine these three distinct mathematical problems "under the hood" in convenience function such as linsolve(). However low-level ("solver") libraries, such as LAPACK, will not.
Two final points of clarification:

A "solver" will typically correspond to a well-defined but abstracted mathematical problem. For example, "statistical inference" or "sucessful prediction" are not such problems. In the language of Computational Science, you verify a solver,  you validate a model.

The ideas of unique/non-unique or exact/approximate are not fully clear cut. Say we focus just on the case of square systems of equations, which should remove most points of contention. It is ubiquitous to talk of "iterative solvers" in this field (e.g. ~600,000 hits on Google Scholar). So the de facto definition of "solver" must include this class of algorithms, which by definition are essentially inexact.
Comment: Yet for linear ordinary least squares $OLS(x)\neq OLS(y)$. The solution may be unique, but yields a least error estimate of $y$, which is often inappropriate and generally does not agree with a bivariate generating equation using Monte Carlo simulation whereas the more poorly correlated Deming regression would recover that generating line plus or minus the regression error.
Comment: I feel that it is a disservice to call linear OLS in $y$; an approximation only valid under restrictive conditions that are usually ignored to be a "solution" as it perpetuates a mythos that is misleading.
Comment: @Carl I updated to try and clarify. I do not understand your comments fully, but they seem to be referring to solving "applied science" problems, such as statistical inference or machine-learning prediction. In my experience (pretty broad in computational science), "solver" is used to refer to software for solving a purely *mathematical* problem. You can verify a solver, but this is not the same as validating a model. If your applied science problem does not satisfy the assumptions of the chosen mathematical problem, validation failure is not due to the solver.
Comment: You are one smart cookie! Never doubt that. I will read through your answer and contribute if I can. In your comment above, Solvers can be validated easily, regression not so easily. You imply a paradox, "What is science that is not applied?" Science is the result of testing hypotheses, be that by proof or trial and error. Answer, all science is applied.
Comment: V&V terms are standard, e.g. [Verification, validation, and predictive capability in computational engineering and physics](https://scholar.google.com/scholar?cluster=12977516601211318124)
"Briefly, verification is the assessment of the accuracy of the solution to a computational model. Validation is the assessment of the accuracy of a computational simulation by comparison with experimental data. In verification, the relationship of the simulation to the real world is not an issue. In validation, the relationship between computation and the real world, i.e., experimental data, is the issue."
Comment: Fine, I meant verification. Besides, the elephant in the room is that solvers find solutions and regression finds approximate solutions and an approximate solution is not an honest to goodness solution. Now, we have better things to do, in specific, I want to write a paper with you about something else.
Answer: I think that the word solver comes from the similar functionality of solving some feasible solution, as there is in Solver add-on of Excel the option "value of", which tries to find $X$ such that $f(X) = Y$ and some more equality and inequality constraints. In mathematica the function solve does the same.
English (especially thanks to the media of US) has a tendency to evolve by mistakes being copied like 'cracker'~'hacker'. Solver could be similar. It is nicely abstract enough to hide the names of actual optimisation algorithms. Often the actual implementations are not that purely a single algorithm.


Python extract only exceptions from traceback

Question: I have nested python exceptions. I wan't to extract all of them into a list from a traceback while discarding everything else, i.e. files, code lines, etc.
The code below extracts everything from a traceback as a list of strings
import traceback
import requests

try:
    r = requests.get('https://thisdoesntexist.test')
except Exception as e:
    exc = traceback.format_exception(e)

print(exc)

Output:
[
    'Traceback (most recent call last):\n',
    '  File "c:\\Python312\\Lib\\site-packages\\urllib3\\connection.py", line 203, in _new_conn\n    sock = connection.create_connection(\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n',
    '  File "c:\\Python312\\Lib\\site-packages\\urllib3\\util\\connection.py", line 60, in create_connection\n    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n',
    '  File "c:\\Python312\\Lib\\socket.py", line 963, in getaddrinfo\n    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n',
    'socket.gaierror: [Errno 11001] getaddrinfo failed\n',
    '\nThe above exception was the direct cause of the following exception:\n\n',
    'Traceback (most recent call last):\n',

    # Output truncated

    'requests.exceptions.ConnectionError: HTTPSConnectionPool(host=\'thisdoesntexist.test\', port=443): Max retries exceeded with url: / (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x0000025E6C236600>: Failed to resolve \'thisdoesntexist.test\' ([Errno 11001] getaddrinfo failed)"))\n'
]

But i only need this:
[
    'socket.gaierror: [Errno 11001] getaddrinfo failed',
    'urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPSConnection object at 0x0000025E6C236600>: Failed to resolve 'thisdoesntexist.test' ([Errno 11001] getaddrinfo failed)',
    'urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=\'thisdoesntexist.test\', port=443): Max retries exceeded with url: / (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x0000025E6C236600>: Failed to resolve \'thisdoesntexist.test\' ([Errno 11001] getaddrinfo failed)"))',
    'requests.exceptions.ConnectionError: HTTPSConnectionPool(host=\'thisdoesntexist.test\', port=443): Max retries exceeded with url: / (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x0000025E6C236600>: Failed to resolve \'thisdoesntexist.test\' ([Errno 11001] getaddrinfo failed)"))\n'
]

Is there a better way of achieving this without iterating over strings and pattern matching?
NB: It would be perfect if I could get a type of the exception in addition to the exception message string, e.g:
[
    {"type": "socket.gaierror", "message": 'socket.gaierror: [Errno 11001] getaddrinfo failed'},
    {"type": "urllib3.exceptions.NameResolutionError", "message": 'urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPSConnection object at 0x0000025E6C236600>: Failed to resolve \'thisdoesntexist.test\' ([Errno 11001] getaddrinfo failed)'},

    # etc

]

Answer: You can try:
import traceback

import requests

def get_info(exc):
    r = []

    if exc.__context__:
        r += get_info(exc.__context__)

    tbe = traceback.TracebackException.from_exception(exc)

    t = tbe.exc_type.__module__ + "." + tbe.exc_type.__qualname__

    r.append({"type": t, "message": str(exc)})
    return r

try:
    r = requests.get("https://thisdoesntexist.test")
except Exception as e:
    print(get_info(e))

Prints:
[
    {"type": "socket.gaierror", "message": "[Errno -2] Name or service not known"},
    {
        "type": "urllib3.exceptions.NameResolutionError",
        "message": "<urllib3.connection.HTTPSConnection object at 0x7f6cc693d9d0>: Failed to resolve 'thisdoesntexist.test' ([Errno -2] Name or service not known)",
    },
    {
        "type": "urllib3.exceptions.MaxRetryError",
        "message": "HTTPSConnectionPool(host='thisdoesntexist.test', port=443): Max retries exceeded with url: / (Caused by NameResolutionError(\"<urllib3.connection.HTTPSConnection object at 0x7f6cc693d9d0>: Failed to resolve 'thisdoesntexist.test' ([Errno -2] Name or service not known)\"))",
    },
    {
        "type": "requests.exceptions.ConnectionError",
        "message": "HTTPSConnectionPool(host='thisdoesntexist.test', port=443): Max retries exceeded with url: / (Caused by NameResolutionError(\"<urllib3.connection.HTTPSConnection object at 0x7f6cc693d9d0>: Failed to resolve 'thisdoesntexist.test' ([Errno -2] Name or service not known)\"))",
    },
]

Comment: That's neat. Thnx Andrej!


How to use Speech Synthesizer with Japanese?

Question: I want to create a small Text-to-speech app in C#. I used Speech Synthesizer with English and it worked fine. But when I pass a Japanese sentence, it didn't work. I didn't receive any error messages. Do I need to install something else?
I tested this on Win 7 32-bit and Win 10 64-bit.
Comment: Do you have any voices installed for the Japanese locale you're using..? You can [check it here](https://msdn.microsoft.com/en-us/library/ms586870(v=vs.110).aspx)
Comment: Versioning matters, if you want to use Haruka then you have to use the Windows.Media.SpeechSynthesis namespace.  That cannot work on Win7 or in a Winforms project.  A shopping guide for the legacy SAPI engine [is here](http://stackoverflow.com/questions/1402833/is-there-any-japanese-tts-voice-to-work-with-c-sharp-speechsynthesizer).
Comment: @Rob I installed Japanese voice (Haruka). When I call GetInstalledVoices, it always has one voice (Anna, Win 7) or two (Zira, David, Win 10).
Comment: Are you passing the correct locale to `GetInstalledVoices`?
Comment: I pass "ja-JP" and get nothing. I think the problem is Japanese voice setup file but can't find out why.
Answer: Try to set CultureInfo of your application.
var ci = new System.Globalization.CultureInfo("ja-JP");
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;

You can set English or Japanese, checking the CurrentCultureInfo.
if (currentUICulture == "ja-JP")
{
    string colorsString = colors.Aggregate((first, Next) => (first += ";" + Next));
    string transColor = speak.Translate(colorsString, "en", "ja");
    string[] jaColors = transColor.Split(new char[]{';','、'});
    for (int i = 0; i < jaColors.Length; i++)
    {
        //
    }
    commands = new string[]{ "なし", "クリア", "イコール",
        "プラス", "マイナス", "掛ける", "分割", "追加" };
}

Choices commandsChoices = new Choices(commands);
GrammarBuilder gb = new GrammarBuilder(commandsChoices);
sr.LoadGrammar(new Grammar(gb));

Choices colorChoices = new Choices(colors);
gb = new GrammarBuilder(colorChoices);
sr.LoadGrammar(new Grammar(gb));

sr.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sr_SpeechRecognized);
sr.SpeechDetected += new EventHandler<SpeechDetectedEventArgs>(sr_SpeechDetected);
sr.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(sr_SpeechRecognitionRejected);

I hopes this help you
antonio


Como fazer troca de sprite sheet na unity sem precisar fazer mais animações?

Question: Olá,
estou fazendo um jogo onde será possível fazer troca de personagem na unity.
O jogo será em 2d, para android e estou enfrentando problemas para fazer a troca de personagens.
Eu fiz um sistema funcional de troca, porem ele é muito extenso e será extremamente cansativo fazer para todos os personagens.
Fiz um aquivo para guardar um int de seleção de personagem. Até ai tudo bem, mas pra cada personagem tenho que fazer todas suas animações de novo. Com um animatorpra cada um.
Gostaria de saber se tem como eu usar o mesmo animator e animações pra todos os personagens, apenas trocando o sprite sheet que ele vai ultilizar?
desde de já muito obrigado!
Answer: Não tenho certeza, porém seria mais facil criar um tipo de asset para cada animação, assim:
[CreateAssetMenu(menuName = "Custom Assets/Animation 2D")]
public class Animation2D : ScriptableObject
{
   public Sprite[] Frames;
   public float FrameSpeed = 0.1f;
   public Sprite this[int index]{get{return Frames[index];}}
}

E depois uma classe que serviria para executar essa animação internamente, assim:
[Serializable]
public class Animation2DInstance
{
 public SpriteRender Render;
 public Animation2D Animation;
 public int CurrentFrame;
 public void RunFrame()
 {
   Render.sprite = Animation[CurrentFrame];
   CurrentFrame++;
 }
}

Depois na clase que executa essas animações, faça os seguintes metodos:
public void Play(Animation2D anim){StartCoroutine(execute_anim(anim));}
public IEnumerator execute_anim(Animation2D anim)
{
 Animation2DInstance instance = new Animation2DInstance(anim);
 float time = anim.FrameSpeed;
 int l = anim.Frames.Lenght;
 while(instance.CurrentFrame < l)
 {
   instance.RunFrame();
   yield return new WaitForSeconds(time);
 }
}

Answer: O que você pode fazer é criar um Script como o seguinte:
public int spriteAtual;
public Sprite[] sprites;
private SpriteRenderer img;

void Start
{
    img = gameObject.getComponent<SpriteRenderer>();
}
void Update
{
    img.Sprite = sprites[spriteAtual];
}

E na animação você só muda o valor do int spriteAtual, assim o código vai atualizar a Sprite de acordo com o valor do int, depois é só mudar as sprites da matriz "sprites" no inspector e reutilizar o código e a animação sem precisar de mais nada. Caso ainda queria mudar as sprites por código pode ainda criar várias matrizes e usar a função Switch como abaixo
public int animacaoX;
public int spriteAtual;
public Sprite[] spritesDaAnimacaoX;
public Sprite[] spritesDaAnimacaoX2;
public Sprite[] spritesDaAnimacaoX3;
private SpriteRenderer img;

void Start
{
    img = gameObject.getComponent<SpriteRenderer>();
}

void Update
{
    img.Sprite = animacaoAtual(animacaoX)[spriteAtual];
}

Sprite[] AnimacaoAtual()
{
    Switch qualAnimacao
        case 1:
            return spritesDaAnimacaoX[];
            break;

        case 2:
            return spritesDaAnimacaoX2[];
            break;

        case 3:
            return spritesDaAnimacaoX3[];
            break;
}

Caso você use o mesmo Animator para mais de um personagem pode ser que todos fiquem com a mesma animação sincronizados, nesse caso terá que duplicar o Animator para cada personagem para que fiquem independentes
OBS: Eu criei os códigos pelo celular, então pode haver erros, (principalmente pq não sei se é possível um método que retorne uma matriz) mas o importante é entender a idéia e reproduzir você mesmo, espero ter ajudado.


C# Code - How to count the amount of files ia .7z

Question: I am searching for a way to open a .7z file and to get the amount/number of zipped content inside there by using C# Code.
string[] directoryPaths = Directory.GetDirectories(@"heregoesmypath");

foreach (string dircetory in directoryPaths)
{
   int fileCount = (from file in Directory.EnumerateFiles(@dircetory, "*", SearchOption.AllDirectories) select file).Count();

   string text = fileCount.ToString() + " Files of: " + "????" + " Files in Directory : " + dircetory;

try
{
   File.AppendAllText(_yourfile, text + Environment.NewLine + Environment.NewLine);
}

catch (Exception ex)
{
   MessageBox.Show(ex.ToString());
}
            string[] zippeddirectoryPaths = Directory.GetFiles(@"myresultpath");

            foreach (string exdircetory in zippeddirectoryPaths)
                {

                   // FileInfo info = new FileInfo(exdircetory);
                   // var test = info.Length;
                   // MessageBox.Show(test.ToString() + "Bytes");
                   // var test2 = info.Extension;
                   // MessageBox.Show(test2.ToString() + "Format");}
                   // var test3 = Empty;
                   // here must be a methode, which count my amount of files on the
                   //  .7z file and save it in var test3

That is my code so far... Instead of the last 5 lines bevore i need that methode getting the number of files in a .7z file.
In the manually way you would have a File, you do a right klick go on 7-Zip and klick open.
The 7-Zip UI opens and offers you a button Properties. If you klick on that button, another window opens with shows you the amount/numbers of files and folders.
So at all I do not prefer to do that manually if I have zipped lots of files and folders. I like to get a way in C# to save my result in a var, so that i can use them later in my code to write a logging.
So please give me suggestions or example code to solve that problem.
Comment: Post some code that you have done so far.
Comment: At least make an attempt prior to asking for help.
Answer: You could make use of the 7z SDK to call the 7z functions directly from your home-grown tool.
An alternative would be to use the 7z commandline interface and evaluate the text output.
Example call:
7z.exe l Repository.7z > list.txt

...

Example result:
7-Zip 9.22 beta  Copyright (c) 1999-2011 Igor Pavlov  2011-04-18

Listing archive: Repository.7z

--
Path = Repository.7z
Type = 7z
Method = LZMA
Solid = +
Blocks = 1
Physical Size = 976726
Headers Size = 22453

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2011-08-31 15:57:36 ....A       663225       954273  Repository\codelists\version 0031\codelists.zip
2010-08-30 18:06:23 ....A        30936               Repository\...\map_ALOCAT_EG4003_Child.xml
2010-10-04 16:38:02 ....A        30936               Repository\...\map_ALOCAT_EG4003_Child.xml
.....
2011-09-09 10:40:14 D....            0            0  Repository\ALOCAT\EDIFACT
2011-09-09 10:56:25 D....            0            0  Repository\ALOCAT
2011-09-09 10:46:13 D....            0            0  Repository
------------------- ----- ------------ ------------  ------------------------
                             130869837       954273  895 files, 2167 folders

Comment: The result looks very well, but it looks like it is not saved in a variable to use it for further code and also you do not post any C# Code...

I also update my question and show you just a little bit of Code I created already.

If you are using C# -Code for that call coud you be so polite to post it and tell me which references you are using?!

Refering to 7z SDK i need to find a good tuorial whick explains how to install and use it in my C# Request. Any suggestions?
Comment: The example output shown above was produced by 7z.exe, the commandline tool delivered with 7-zip. No C# coding involved. The idea is that it might be easier to just call 7z.exe from your program and interprete the output listing. This would save you from installing and comprehending the 7z SDK.


Music for Piano, Frangis Ali-Sade

Question: What should I know about the music tradition behind Music for Piano, I believe mugham? From what I gather, the notation is more of you'd call a guideline. I have the 1998 Musikverlag Hans Sikorski Hamburg edition:

Mismatched time between staffs

1/32 (rest) + 5/16 = a 5/16 quintuplet
I'm interpreting this as concurrent 1/16 note runs with one offset by a 1/32. But then why not write that?
2/32 = 1/8
I'm pretending they're 1/16 notes.
beamed notes in the lower staff arbitrarily positioned irrespective of duration
I'm playing them based on where they're positioned on the page rather than the durations. Specifically the upper staff as the melody drives the rhythm and should be played as written. The lower staff as accompaniment should be more flexible and played as displayed on the page, in relation to the fixed upper staff. Still, it's a bit odd to see an arbitrarily positioned 1/16+1/2 note (see image: first note, last staff). If the timing was so arbitrary, why not just forego the 1/16 and write only the 1/2?

Use of tuplets without time signature or barlines
Recording by the composer differs significantly from the sheet music
Wish I knew enough to do the same.

I also have some specific questions:

Do the upper-staff breath mark apply to the open-ended ties of the lower staff?
Do the tremolo-style feathered beams indicate the number of notes? Or do I play as many notes as I want (with gradual acceleration) in the duration of the left-staff?
Given a series of feathered (slow->fast) beams with each their own crescendo, is it alright to pause on the last (fast,loud) note to adjust to the next (slow,quiet) note?
Answer: Specifically:

It doesn't matter, because the damper pedal is held.
Play only as many notes as there are note heads.  The feathering suggests accel/decel, nothing more.
Yes, because that's in the spirit of ad libitum, improvvisazione.

Pulling off the amoroso may matter more than any rhythmic or dynamic quibble, especially when the composer's own recording seems to hold contempt for those quibbles.

Music for Piano, Frangis Ali-Sade


Why is shefication necessary in constructing the reduced scheme?

Question: Let $X$ be a scheme. Hartshorne defines the reduced scheme associated to $X$ as the sheafication of the presheaf $U \mapsto \mathcal{O}_X(U)_{\text{red}}$. Is there any example that shows that this presheaf need not be a sheaf?
Answer: Take $X=\coprod_n \mathrm{Spec}(\mathbb{Z}/p^n)$ for a prime $p$. Then $s:=(p)_n \in \prod_n \mathbb{Z}/p^n = \mathcal{O}_X(X)$ is not nilpotent, but the restriction to each $\mathrm{Spec}(\mathbb{Z}/p^n)$ is nilpotent. Hence, we have $[s] \neq [0]$ in $\mathcal{O}_X(X)_{red}$, although we have $[s]=[0]$ in each $\mathcal{O}_{X}(\mathrm{Spec}(\mathbb{Z}/p^n))_{red}$.
There are also quasi-compact counterexamples.
Comment: This is an excellent and very illuminating counterexample. Thank you!
Comment: Dear Martin, I think you want an index $n$ instead of $p$ in the formula  $s:=(p)_p \in \prod_p \mathbb{Z}/p^n = \mathcal{O}_X(X)$ of your illuminating answer.
Comment: Yes, it is corrected now. Thanks.
Answer: An indirect answer is that Hartshorne's sheaf constructions are often a little lacking in the elegance department.  This is one example; the definition of the structure sheaf is another.  If you are looking for a better way to understand the reduced scheme associated with an arbitrary scheme, think of it this way: it's a closed subscheme and thus given by a certain sheaf of ideals $\mathcal{I}$.  What is $\mathcal{I}$?  Simply, its sections on any open $U$ are the sections of $\mathcal{O}_U$ that are "in every prime ideal of $U$", i.e. whose image in the fiber at each point of $U$ is zero.  This is visibly an ideal of $\mathcal{O}_U$ and these ideals visibly form a sheaf, since evaluation in a fiber is a local property.  On any open affine set $\operatorname{Spec}(A)$, itgives the correct ideal, namely the nilradical, by virtue of the famous fact that this ideal is the intersection of all primes of $A$.  In this interpretation, the nilradical sheaf of ideals is the set of "all sections of $\mathcal{O}_X$ defining the zero function on $X$".
Comment: Good point. But for the quotient sheaf $\mathcal{O}_X/\sqrt{0}$ we still need to take the associated sheaf to the quotient presheaf.


sum up to nth term with fraction in the power

Question: Is there a formula to express the sum up to the nth term of this:
$$ 2^{(1/10)}+2^{(2/10)}+2^{(3/10)}+...+2^{(n/10)}? $$
I am not a mathematician and use computing algorithm but I am looking for a simplification of my algorithms..
Comment: $$(2^{1/10})^1 + (2^{1/10})^2 + (2^{1/10})^3 + \dotsc + (2^{1/10})^n$$ It's a geometric sum.
Comment: I knew it! many thanks! How could I miss the easy stuff????
Answer: In general, when $a\ne 1$,
$$
a^1+a^2+\cdots+a^n=\frac{a^{n+1}-a}{a-1},
$$
and hence
$$
2^{1/10}+2^{2/10}+\cdots+2^{n/10}=\frac{2^{(n+1)/10}-2^{1/10}}{2^{1/10}-1}.
$$
Answer: Let $2^{1/10} = x$ then you are summing
$$
x + x^2 + x^3 + \ldots + x^n = x \frac{x^n-1}{x-1}
$$
Answer: Just rewrite as $\sum_{k=1}^{n} (2^{1/10})^k $ and use the usual geometric series formula.


O que é a assinatura unicode (BOM)?

Question: Reparei que as vezes o dreamweaver coloca assinatura unicode (BOM) em algumas páginas php's, tenho que retirar a maioria das vezes para que não apareça um espaçamento na página de exibição e não sei bem para que serve assinatura unicode (BOM) vocês poderiam me explicar?
Comment: @DBX8 mas acredito que as resposta daquela pergunta podem responder essa pergunta.
Comment: ANSI é com um I só; ASCII é com dois I. ;-)
Answer: O marcador BOM é um indicar de ordem dos bytes em um arquivo de texto, para cada par de 2 bytes, no caso de unicode-16 e para o grupo de 4 bytes no unicode-32.
Esse marcador vem exclusivamente no início do arquivo.
BOM significa "Byte Order Mark", que em português seria algo como "Marca de ordenação de bytes".
EDIT
Também existe BOM para unicode-8, mas o seu uso não é recomendado, uma vez, que só existe uma ordenação possível para caracteres compostos por um único byte.
EDIT Print da wikipedia, mostrando os marcadores (já que não é possível montar tabelas aqui no SO)

Origem: http://en.wikipedia.org/wiki/Byte_order_mark
Comment: Byte Order Mark, marca de ordem de bytes, e não Binary Order Mark.
Comment: Lá vai...: https://www.youtube.com/watch?v=Sv8XehRa-cg (sorry, não resisti).
Comment: @Bacco HUahuhua! Boa... ou seja, a fêmea do BOM. (só pra entrar no espírito da coisa =)
Comment: Esse BOM é mais usado em sistemas Windows, certo?
Answer: O BOM (byte order mark, marca de ordem de bytes) foi criado para solucionar um problema do UTF-16 (e também do UTF-32, embora este formato seja pouco usado para salvar arquivos).
Como cada caracter em UTF-16 é composto por 2 bytes (ou em casos mais raros por um par de unidades de 2 bytes cada), existe a possibilidade de ordená-los de maneiras diferentes: byte 1, byte 2; ou byte 2, byte 1 (sobre a ordem dos bits, ninguém discute, pelo menos...). Então arquiteturas little-endian preferirão usar UTF-16LE (LE = little endian), que tem a ordem "byte 2, byte 1" que é a mais natural para o processador. E arquiteturas big-endian preferirão usar UTF-16BE.
Para diferenciar os dois tipos de UTF-16, usa-se o BOM no começo do arquivo, que é um caracter que não pode ser confundido com seu "inverso", portanto ao lê-lo será possível descobrir qual é a ordem dos bytes do resto do arquivo.
Já o UTF-8 foi elaborado de maneira diferente, onde a ordem dos bytes não depende da arquitetura do computador. Por isso, muitos consideram desnecessário usar BOM em arquivos UTF-8.
O BOM, que em UTF-16 ocupa 2 bytes, ao ser codificado em UTF-8 toma a forma de 3 bytes. Por isso alguns programas, apesar da não-recomendação de usar BOM em UTF-8 acabaram por adotá-lo mesmo assim, pois quando abrirem um arquivo e encontrarem aqueles 3 bytes especiais, saberão que provavelmente se trata de um arquivo UTF-8 (porque é muito raro um texto começar com , que é como aparece o BOM se for lido como a codificação cp1252).
Agora, se você deve ou não usar BOM nos seus arquivos, o debate fica um pouco filosófico, porque existem prós e contras...
Answer: BOM significa Byte Order Mark.
No nosso mundo as pessoas não conseguem se entender sobre várias coisas, inclusive se os bits de menor valor de um byte devem ser alinhados à esquerda ou a direita. Acredite, há discussões acaloradas e cheias de agressões pessoais sobre qual forma é melhor.
Com certos encodings acontece algo parecido. Alguns caracteres são representados por mais de um byte. Em UTF-32, por exemplo, são utilizados quatro bytes por caractere. Existem pessoas que preferem que os bytes com valores menores sejam alinhados a esquerda ou a direita em cada caractere.
Como não é possível adotar uma ou outra forma como a universal, às vezes a gente precisa informar a um parser a ordem em que os bytes devem ser lidos. A gente faz isso utilizando o BOM. Se você não informar o BOM, o parser tem que literalmente adivinhar a forma de leitura. Por isso que, sem ele, às vezes os textos ficam "quebrados".
É comum o BOM de um texto ser indicado pelo pré-âmbulo, que são os três primeiros bytes de um texto. O parser os utiliza para determinar qual é o encoding utilizado.
Como notado pelo DBX8 na resposta dele, isso deveria ser irrelevante para o UTF-8, que utiliza apenas um byte por caractere. A única vantagem de se informar o BOM do UTF-8 é que isso ajuda o parser a reconhecer o encoding utilizado.
Comment: Correção: ordem dos bytes, não dos bits. E no UTF-8 não existe esse problema, cada unidade tem apenas 1 byte, com a possibilidade de "extensões" serem colocadas depois, mas com uma ordem bem definida. O BOM no UTF-8 acaba servindo mais para indicar que o arquivo é UTF-8 do que realmente para indicar a ordem (seu propósito original).
Answer: UTF-8 em conjunto com BOM(Byte order mark) é codificado com os bytes EF BB BF no início do arquivo. Não há diferença, pelo menos não oficial entre UTF-8 e UTF-8 com BOM. Enquanto há utilização, de acordo com o Padrão Unicode, o Byte order mark para arquivos UTF-8 não é recomendado.
Na seção 3.10 Unicode Encoding Schemes, item D95 diz, em tradução livre:

O seu uso no início de um fluxo de dados UTF-8 não é necessário nem
  recomendado pelo Unicode Standard, mas a sua presença não afeta a
  conformidade com o esquema de codificação UTF-8.
Comment: A ordem dos bytes não é variável em UTF-8. Mas claro, pode haver o problema de descobrir que o texto está em UTF-8 para começo de conversa...
Comment: Verdade. Vou corrigir minha resposta.
Answer: Você pode corrigir esse problema como demonstrado abaixo:

http://www.melhorweb.com.br/artigo/5-Problemas-de-espacamento-e-acentuacao-no-Dreamweaver.htm
http://forum.imasters.com.br/topic/511360-desativar-assinatura-unicode-bom/

O que é o BOM?
A marca de ordem de byte (BOM) é um caractere Unicode usado para denotar a extremidade (ordem de bytes) de um arquivo de texto ou fluxo de dados, com código é U+FEFF. Seu uso é opcional e, se usado, deve aparecer no começo do fluxo de texto.
Além do seu uso tradicional, esse caractere também pode indicar em qual das diferentes representações Unicode o texto está codificado.1 Tendo em vista que o Unicode pode ser codificado tanto em 16 quanto 32 bits, o leitor de texto Unicode deve saber em que formato o texto sendo lido está codificado.
Fonte: http://pt.wikipedia.org/wiki/Marca_de_ordem_de_byte
Comment: "esse caractere também pode indicar em qual das diferentes representações Unicode o texto está codificado" Acho que não... se ele encontrar um `FF FE 00 00` como ele poderia diferenciar entre um UTF-32 e um UTF-16 onde o primeiro caractere é nulo?
Comment: @mgibsonbr, tens razão acerca desta ambiguidades. Na maioria dos casos o BOM é suficiente para determinar o sistema de codificação usado, e a generalidade das ferramentas interepreta o FEFF0000 como utf-32 (o que dá uma enorme dor de cabeça para os utf-16 começados por nulo -- casos rarissimos mas que já me aconteceu) (Detesto BOMs :)

O que é a assinatura unicode (BOM)?


Mathematics Audiobooks for the Blind?

Question: Are there any mathematics audiobooks, such as for those who are blind? How do they pronounce the equations?
Comment: Audio books for the deaf? You mean like movies for the blind?
Comment: this question made me wonder how difficult it is for the blind to understand mathematics ._.
Comment: @GitGud: Yeah, I was actually thinking about mathematical braille when I was writing the question… thanks for the correction.
Comment: @Lucyfer Zedd: http://math.stackexchange.com/questions/889594/who-are-some-blind-or-otherwise-disabled-mathematicians-who-have-made-important
Answer: You might find the answers to this post helpful, in terms of standards for speaking mathematics without relying on the receiver's vision.
The question asks for a definitive guide to spoken mathematics. You'll find many resources there, including the link to Handbook for Spoken Mathmatics.
Answer: Lectures on mathematics (e.g. MIT courses) can be considered as audio-books of mathematics.

Mathematics Audiobooks for the Blind?


Difference between Measurable and Borel Measurable function

Question: Definition of measurable function:
If $X$ is measurable space, $Y$ is topological space, then $f:X\to Y$ is measurable provided that $f^{-1}(V)$ is measurable set in $X$ for every open set $V$ in $Y$.
Definition of Borel measurable function: If $f:X\to Y$ is continuous mapping of $X$, where $Y$ is any topological space, $ (X,\mathfrak B)$ is measurable space and $f^{-1}(V)\in\mathfrak B$ for every open set $V$ in $Y$, then $f$ is Borel measurable function.
Both functions are mapping from measurable space to topological space what's the difference between the two definition?
Comment: Good question, but there is also the case of maps between two measurable spaces X,Y.
Answer: A Borel measurable function is a measurable function but with the specification that the measurable space $X$ is a Borel measurable space (where $\mathfrak B$ is generated as the smallest sigma algebra that contains all open sets). The condition "$f$ is continuous" is equivalent to "$f^{-1}(V)$ is open (and thus Borel measurable) for every open set $V\subseteq Y$".
But not every measurable function is Borel measurable, for example no function that takes arguments from $(\mathbb R,\{\emptyset,\mathbb R\})$ is Borel measurable, because $\{\emptyset,\mathbb R\}$ is not a Borel sigma algebra.
Comment: Would you mind explaining why your example holds? I mean, according to the definition, {∅,ℝ} can be a topology of ℝ and {∅,ℝ} will be a Borel sigma algebra of ℝ.
Answer: The difference is in the $\sigma$-algebra that is part of the definition of measurable space.  In your first definition you say that $X$ is measurable but you don't specify the $\sigma$-algebra; in the second you specify that the $\sigma$-algebra is the collection of all Borel sets.
The $\sigma$-algebra is a collection of sets closed under countably-infinite unions (that's rather rough and ready, but if you need to know more you're better off looking up a definition and some examples).


Is $\mathsf{X}_{n+1}$ also $\mathcal{F}_n$-measurable? (martingales)

Question: Let $(\Omega, \mathcal{F}, \mathcal{F_n}, P)$ be a filtered probability space and let $(\mathsf{X}_n,\mathcal{F_n})_{n \in \mathbb{N}_0}$ be a martingale on $(\Omega, \mathcal{F}, \mathcal{F_n}, P)$.
By definition $\mathsf{X}_n$ is $\mathcal{F}_n$-measurable.
My question: Is $\mathsf{X}_{n+1}$ also $\mathcal{F}_n$-measurable?
Answer: It cannot be unless $X_n$ is independent of $n$.  $X_n=E(X_{n+1}|\mathcal F_n)$. If $ X_{n+1}$ is already measurable w.r.t. $\mathcal F_n$ this would give $X_{n+1}=X_n$.


How can I access local variables in my React function?

Question: I am getting this error, TypeError: Cannot read property 'classList' of undefined, before even the functions are even called. The error happens on the line slide[n].classlist.
componentDidMount() {
    let slides = document.querySelectorAll(".slide");
    let currentSlide = 0;

    function showSlide(n) {
      slides[currentSlide].classList.remove('active-slide');
      slides[n].classList.add('active-slide');
      currentSlide = n;
      if (currentSlide === 0) {
        previousButton.style.display = 'none';
      }
      else {
        previousButton.style.display = 'inline-block';
      }
      if (currentSlide === slides.length - 1) {
        nextButton.style.display = 'none';
        //submitButton.style.display = 'inline-block';
      }
      else {
        nextButton.style.display = 'inline-block';
        //submitButton.style.display = 'none';
      }
    }

    function showNextSlide() {
      showSlide(currentSlide + 1);
    }

    function showPreviousSlide() {
      showSlide(currentSlide - 1);
    }

    const previousButton = document.getElementById("previous");
    const nextButton = document.getElementById("next");
    previousButton.addEventListener("click", showPreviousSlide());
    nextButton.addEventListener("click", showNextSlide());
    console.log(slides);
    showSlide(0);
  }

Comment: Don't use the DOM API and conditionally add/remove styles based on local variables. Those variables should be in the `state` and changes to state will re-render your component.
Comment: Your error is on adjusting an undefined element from an array defined by `document.querySelectorAll(".slide");` Well, I don't see any elements with `className="slide"`.  In which case, the error message is correct.
Comment: Welcome to SO. Please post a minimal reproducible example (the complete page in this case, I guess), not just the function code.
Answer: previousButton.addEventListener("click", showPreviousSlide());
nextButton.addEventListener("click", showNextSlide());

You are calling the functions instead of passing them as arguments. Because of that you call showSlides with n = -1 (The showPreviousSlide call comes first) and ofcourse the slides array doesn't have member -1 so it's undefined -> You do not check if the member exists before trying to use it's properties -> you get the error.
Also you really should'nt use this kind of vanilla js inside react it defeats the whole point of using react.
This is the correct code
previousButton.addEventListener("click", showPreviousSlide);
nextButton.addEventListener("click", showNextSlide);

Answer: Fastest way in this case is to declare slides and currentSlide variables as "var" type instead of "let":
    var slides = document.querySelectorAll(".slide");
    var currentSlide = 0;

Second option, with react you can use hooks to have global variables access along your code.
    import React, {useState} from 'react';

    const showSlide = (n) => {

    //HOOK
    const [useSlide, setUseSlide] = useState();
    .
    .
    .


Dúvida sobre icones em UX (Font-awesome)

Question: Possuo uma tabela (DataTables), e essa tabela lista controles:
Esses controles são atividades contábeis, fiscais, documentais e outras, todo mes um empresa recebe um controle pra cada setor, e esse controle de cada mês, pode receber uma flag.
No contexto em questão, a flag é para notificar o usuário que determinado controle necessita receber uma atenção extra, ou mesmo que precisa de menos atenção que os demais.
Essas flags podem ser:

Intermediário (fa-flag)
Importante (fa-hourglass-end)
Problema (fa-ban)
Informativo (fa-info)

Do meu ponto de vista, eses icones não condizem com o que flag deve significar, mas não consigo encontrar algo 'mais correto', exceto o fa-info que está correto, bom:

Do ponto de vista de UX/UI, da forma mais padrão possível, quais
  seriam os icones recomendados para estes pontos a seguir:

Intermediário:
Nível de necessidade de efetuar algo dentro deste controle, sendo mudar o prazo, ou notificar que o prazo venceu, etc, mas que é de nivel intermediário a necessidade de efetuar essa ação.
Importante:
Nível de necessidade de efetuar algo elevado, sendo as prazos, ações de verificação (o sistema pode gerar essa flag sozinho caso a empresa seja prioritária e o prazo de conclusão vencer por exemplo), essa flag não pode ser desmarcada como a '1', ela se conclui sozinha quando a ação for concluida;
Problema:
Quando houve algum problema técnico no controle, foi feito um lançamento de um documento que não existe(lançado errado), ou alguma informação foi salva por um usuário de nivel operacional e ele precisa sinalizar um moderador pra que ele lhe de permissão de reescrever, etc, essa flag é simples, pode ser feita e desfeita a qualquer momento;
Informativo:
Quando o usuário X deseja atrelar um informação a flag que não deva acarretar em nenhuma ação por nenhum outro usuário ou ele mesmo no futuro.

PS: Cores não importam neste contexto, o sistema ja possui o padrão, estou com problemas apenas com icones.
Comment: @LuizVieira vou inserir uns exemplos e dar um reformulada na pergunta, realmente está muito subjetiva.
Comment: Do jeito que a pergunta está, as respostas tenderão a ser opinativas. Vc fala de UX, mas não comenta nada sobre o contexto do seu sistema (por exemplo, que raios são "controles"? O que esses ícones irão indicar? Eles serão usados para uma notificação, ou para um botão de ação? etc). Sugiro que edite a pergunta para melhorá-la. Se a sua necessidade é somente pedir dicas de ícones, use o [chat].
Comment: Sem saber detalhes do contexto, eu posso opinar que ícone bons (e supondo que se tratam de notificações) talvez seriam uma estrela amarela para "importante" e uma exclamação vermelha para "problema". Para "intermediário" não dá pra sequer opinar porque não sei sobre o que ele trata (é intermediário entre o que? Grande e pequeno? Bom e ruim? Duro  e mole?). Talvez o próprio texto/rótulo "intermediário" esteja ruim (embora eu não entenda o que quer dizer um "nível de necessidade de efetuar algo").
Comment: Acho que com relação a interface, não existe forma mais padrão possível, fica a seu critério qual ícone inserir para cada flag. Por ex: Se você quiser colocar o ícone de um "abacaxi" na flag "Problema", uma hora você vai se acostumar e os usuários também, vai demorar um pouco? Vai, só porque não está no padrão.
Answer: No contexto de necessidade, entendi algo como tarefas a serem realizadas, seguindo essa lógica, tarefa intermediária fica muito próximo de tarefa importante, para diferenciar pode-se usar um hourglass-half (dando a impressão de que essa tarefa é parcialmente relevante), ou melhor ainda um exchange visando uma simples troca/alteração simples com pouca necessidade.
Seguindo a ordem da pergunta ficaria algo mais ou menos assim.

i{
  padding: 15px;
  margin: 15px;
  background-color: #EEE;
}
.fa-exchange{
  color: #004D40;
}
.fa-exclamation {
  color: #FFC107;
}
.fa-exclamation-triangle {
  color: #F44336;
}
.fa-info {
  color: #3F51B5;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

Não tenho uma visão aprofundada de como o usuário encara isso nos dias de hoje, talvez @LuizVieira possa salientar isso, minha resposta só engloba uma visão da GUI.
Comment: O 'fa-exchange' foi o unico que não ficou 100% acho, mas comparado com o icon 'fa-flag' que estava antes, ficou muito bom kk, vou dar mais uma estudada, se eu achar algo melhor coloco uma imagem aqui.
Comment: Acabei deixando dessa maneira por hora: https://imgur.com/a/A4Mbb , essa sugestão com o exclamation ficou muito melhor de como estava.
Comment: Ficou bom dessa forma, mas esse intermediário ainda não me convenceu kk.


BIztalk - keeping a session key in an API

Question: I have an API that has port type with multiple functions.
From those functions I need the logging operation and synchronize operation.
The problem is that BizTalk doesn't save session from the logging operation and thus not allowing me to perform the synchronize operation.
the API in question is a SVC WS which I generated from WCF consume adapter.
Does anyone has an idea how can I achieve the synchronize operation to work in the same session of the logging operation.
p.s.
The Logging operation doesn't return a session key it's returning only a status code
Answer: Unfortunately, that scenario is not supported by BizTalk Server, at least with the our of the box bindings.
All Send Operations are sessionless.
But, there are several ways to maintain a session.  Ask the service provider how they're doing it and there might be a way to replicate that with BizTalk.
Comment: I have a testing tool and there it works. so how can I replicate that code in biztalk? there I'm doing the logging operation and then moving on to a switch case which goes to the synchronize operation I need. so is there a way to do it?
Comment: I mean exactly how are they maintaining the state?  Cookies?  You need to know that before working on how to do it in BizTalk.