Correlation of bivariate normal variables with truncated tails

Question: What is the correlation of a bivariate normal distribution after truncating the tails of both variables at $\alpha$ standard deviations?
In symbols, what is $$E\left[XY\Big|X| \leq z_{\alpha/2}, |Y| \leq z_{\alpha/2}\right]\ ?$$
I'd like a formula for this; for now, here is a computation in R with $\alpha = .1$ and $\rho = .9$.
<code># generating the data set
set.seed(42)
n <- 5000
R <- matrix(c( 1,.9,
              .9, 1), 2, 2)
jd <- MASS::mvrnorm(empirical = TRUE,
                    mu = c(0,0),
                    Sigma = R,
                    n = n)

# remove truncated values
alpha <- .10
crit <- qnorm(alpha/2, lower.tail = FALSE)
jd[abs(jd)>(crit)] <- NA
jd <- na.omit(jd)

# Correlation
cor(jd)
</code>
The original correlation was .9 and the truncated correlation is .8382. This is not simply sampling variation; with a high sample size I also found find approximately the same difference (.837).
Can this correlation be derived analytically for any $\alpha$ and any correlation $\rho$?
Comment: This answer maybe helpful: https://stats.stackexchange.com/questions/517347/ It provides links to discussion about truncated nultivariate normals. The answer contains a link to paywalled papers, but the last one is on arXiv and is very thorough: https://arxiv.org/abs/1206.5387.
Comment: The solution comes down to finding integrals of the type https://stats.stackexchange.com/questions/498851 and with the same integrand multiplied by $x^2,$ which can be found by differentiating the result twice with respect to $b.$  Yes, it's messy, but taking that derivative is elementary.
Comment: Can you state the problem in math expression?  Is $E[XY||X| \leq z_\alpha, |Y| \leq z_\alpha]$ what you want to compute?
Comment: Thank you @Zhanxiong. Yes, it is.
Comment: @whuber, an expression with Owen's T would not be much simpler than the original integral. One could make the "analytical" requirement in the question precise by asking: Does the truncated correlation have an expression in terms of well-known functions of one argument, like $\text{erf}$ or $\Phi$? Then I think the answer would be no.
Comment: @MattF. The sense of "not simpler" depends on how well you understand Owen's T, your capabilities of computing with it and using for analysis, and on mathematical relationships between it and other transcendental functions.  I accept that it's a fairly obscure function, but it has been analyzed; it does appear in other contexts; and its definition is tractable, leading to various potential methods of numerical evaluation.
Answer: Thank you for everyone in the comments, I finaly understood how to compute the answer. From Manjunath & Wilhelm and their R package R package, we can get the solution.
<code>alpha <- .10
crit <- qnorm(alpha/2, lower.tail = FALSE)
a <- -c(crit, crit); b <- c(crit,crit)
mu <- c(0,0); sigma <- R
moments <- tmvtnorm::mtmvnorm(mean=mu, sigma=sigma,
                    lower=a, upper=b)

> moments
$tmean
[1] 0 0

$tvar
          [,1]      [,2]
[1,] 0.5747640 0.4811731
[2,] 0.4811731 0.5747640

> cov2cor(moments$tvar)
          [,1]      [,2]
[1,] 1.0000000 0.8371664
[2,] 0.8371664 1.0000000
</code>
Comment: This is just a numerical calculation. Your question explicitly asks for an "analytical solution."


Installing PNPM Package Manager on Debian/Ubuntu?

Question: I'm trying to install the PNPM package manager on debian/ubuntu, but when I enter the command:
curl -fsSL https://get.pnpm.io/install.sh | sh-
The following error shows up:
bash: sh-: command not found
(23) Failed writing body

Does anyone know how to fix this?
Answer: I do not believe -fsSL is a valid option.
Maybe you mean to use one of the following options.
LINK to curl options
 --ssl           Try SSL/TLS
 --ssl-allow-beast Allow security flaw to improve interop
 --ssl-no-revoke Disable cert revocation checks (Schannel)
 --ssl-reqd      Require SSL/TLS

 -f, --fail          Fail silently (no output at all) on HTTP errors
     --fail-early    Fail on first transfer error, do not continue
     --false-start   Enable TLS False Start
 -F, --form <name=content> Specify multipart MIME data
     --form-string <name=string> Specify multipart MIME data
     --ftp-account <data> Account data string
     --ftp-alternative-to-user <command> String to replace USER [name]
     --ftp-create-dirs Create the remote dirs if not present
     --ftp-method <method> Control CWD usage
     --ftp-pasv      Use PASV/EPSV instead of PORT
 -P, --ftp-port <address> Use PORT instead of PASV
     --ftp-pret      Send PRET before PASV
     --ftp-skip-pasv-ip Skip the IP address for PASV
     --ftp-ssl-ccc   Send CCC after authenticating
     --ftp-ssl-ccc-mode <active/passive> Set CCC mode
     --ftp-ssl-control Require SSL/TLS for FTP login, clear for transfer

I have no idea about the  | sh
What I would suggest is you go to https://curlconverter.com
Paste your curl command into the "curl command" textarea and if there is an error they will point it out for you.
Answer: the issue is a missing space in your command between sh and the -.
It should look like this:
curl -fsSL https://get.pnpm.io/install.sh | sh -


How to use plugin to reduce size when import lodash

Question: Here is my code : import _ from 'lodash';
I want to use babel-plugin-transform-imports to reduce size of folder when "yarn build".
But I don't know how to set up plugin and config in wepack.config.js
Thank you so much
Comment: did you check https://www.npmjs.com/package/babel-plugin-transform-imports ?
Comment: I did it, but it didn't work
Answer: There is three way to reduce:
1. When in development, you can include the folder where you are going to compile by config the loaders, so the file outside this folder won't be compiled. Loader config are like the following code:
{
    test: /\.(js|mjs|jsx)$/,
    include: path.resolve(__dirname,"src"),//important
    use: {
        loader: 'babel-loader'
    }
}

2、 You can use DDL to pre-compile the third-party library.
e.g.
Firstly create vendor.js, that is to say you need to bundle it by another webpack config.
const webpack = require('webpack')
const library = '[name]_lib'
const path = require('path')
module.exports = {
  mode:"production",
  entry: {
    vendors: ['lodash']
  },
  output: {
    filename: '[name].dll.js',
    path: path.join(__dirname,"dist/vendor"),
    library
  },
  plugins: [
    new webpack.DllPlugin({
      path: path.join(__dirname, 'dist/[name]-manifest.json'),
      // This must match the output.library option above
      name: library
    }),
  ]
}

And then you need to include mainfest.json in your project webpack config:
plugins: [
    new webpack.DllReferencePlugin({
      context: __dirname,
      manifest: path.join(__dirname, 'dist/vendors-manifest.json'),
    })
]

3、 You can use externals to exclude it, you can config it like:
externals : {
    lodash : {
      commonjs: 'lodash',
      amd: 'lodash',
      root: '_' // indicates global variable
    }
}

And don't forget to include lodsh script in HTML, because webpack don't compile or include it in your bundle. If you don't include ,the broswer will throw an error.
You can check more usage at Webpack website:
https://webpack.js.org/configuration/externals/
https://webpack.js.org/plugins/dll-plugin/


Shibboleth SP 2 and ADFS sha1 to sha256

Question: With shibboleth SP 2, I need to configure ADFS (as IdP) in advance tab SHA-1 algorithm to work fine.
If I configure in ADFS SHA-256 hash algorithm, I get an error in ADFS event log, that SP reponses with SHA-1 algorithm.
My stack OpenSSH, Shibboleth, Debian (Stretch) is very new so it can use SHA-256 algorithm. I install all with debian's repositories with out of the box configuration.
I consulted this document and Microsoft's docs.
Comment: What is the question? Are you asking if ADFS can use SHA2?. No, it's either SHA1 or SHA256.
Comment: @nzpcmad I want to use SHA-256 between ADFS and Shibboleth SP. It works only with SHA-1. I think the problem is in shibboleth side.
Comment: Most SAML integrations are SHA1. You'll have to look at the Shibboleth config. to see if you can change to SHA256.
Answer: I find in the shibboleth documentation those two attributes  :

signingAlg (URI) (defaults to the specifier for RSA-SHA1)
    An XML Signature signature algorithm specifier for signatures produced by the SP.
digestAlg (URI) (defaults to the specifier for SHA1)

So I add in my shibboleth2.xml configuration file in the ApplicationDefaults  node :
<code>digestAlg="http://www.w3.org/2001/04/xmlenc#sha256"
signingAlg="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
</code>
And after that it works with both configuration of ADFS : SHA1 and SHA256.
Comment: So I'm surprised that it works with SHA1 and SHA256 ADFS configuration.

Shibboleth SP 2 and ADFS sha1 to sha256


how to use mysql database replication to backup a single database

Question: Suppose I want to replicate a single database in mysql on my slave, the master might be creating and writing to multiple databases. is this possoible?
or does the replication slave have to replicate everything written to all dbs after setting up the initial Master Binary Log Coordinates?
if so, what is the best way to backup a single database assuming a lot of writes is going on the master?
Answer: Use the replicate-do-db setting, and note that replication is not the same as a backup... TRUNCATE TABLE very_important or UPDATE credit_cards SET number='whoops' will replicate across and delete everything on the slave as well.


Include Twitter Bootstrap by reference

Question: Is there an URL I could use to include any Twitter Bootstrap file, css or javascript, of my preference?
Comment: check out http://www.bootstrapcdn.com/
Comment: that's what I wanted thanks.
Answer: Try this or official github repository.

Include Twitter Bootstrap by reference


The right package/software for non-linear optimization with semidefinite constraints

Question: I am struggling to solve an optimization problem, numerically, of the following (generic) form.

minimize F(x)
such that:
___(1): 0 < x < 1
___(2):  M(x) >= 0.

where M(x) is a matrix whose elements are quadratic functions of x. The last constraint means that M(x) must be a positive semidefinite matrix. Furthermore F(x) is a callable function. For the more curious, here is a similar minimum-working-example.
I have tried a few options, but to no success.

PICOS, CVXPY and CVX -- In the first two cases, I cannot find a way of encoding a minimax problem such as mine. In the third one which is implemented in MATLAB, the matrices involved in a semidefinite constraint must be affine. So my problem falls outside this criteria.
fmincon -- How can we encode a matrix positivity constraint? One way is to compute the eigenvalues of the matrix M(x) analytically, and constraint each one to be positive. But the analytic expression for the eigenvalues can be horrendous.
MOSEK -- The objective function must be a expressible in a standard form. I cannot find an example of a user-defined objective function.
scipy.optimize -- Along with the objective functions and the constraints, it is necessary to provide the derivative of these functions as well. Particularly in my case, that is fine for the objective function. But, if I were to express the matrix positivity constraint (as well as it's derivative) with an analytic expression of the eigenvalues, that can be very tedious.

My apologies for not providing a MWE to illustrate my attempts with each of the above packages/softwares.
Can anyone please suggest a package/software which could be useful to me in solving my optimization problem?
Comment: Could give an example for `F` and `M`?
Comment: A more concrete example of $M(x)$ would help. As for MOSEK (I work at MOSEK), you cannot specify user-defined functions for SDP. However, if F(X) is conic representable, maybe you do not need it. See http://docs.mosek.com/modeling-cookbook/index.html
Answer: Have a look at a nonlinear optimization package with box constraints, where different type of constraints may be coded via penalty or barrier techniques.
Look at the following URL
merlin.cs.uoi.gr
Comment: If M is symmetric LDL^T choleski is cheaper to find out if M is pd


Darken a background image without affecting the Text

Question: I am almost there, but the text inside the a-tag should not be affected by the semi-transparent overlay:
http://jsfiddle.net/ChrisPrefect/GPLfM/
The text should be bright white, regardless if you hover over the image or not.
I can add more html elements if necessary, but I would like to keep it to the minimum.
There is a new element added with:
.tint:before

which has a semi transparent background:
background: rgba(0,0,0, 0.5);

But the "before" element is over the text inside the a-element too and makes it dark.
Can this be solved with z-index ordering?
Thank you!
Chris
Answer: This can easily be solved by ordering the stacking order of your elements correctly. Note the use of relative positioning on the text content.

.block {
  display: inline-block;
  color: #fff;
  position: relative;
  width: 200px;
  height: 200px;
  padding: 10px;
}

.block:before {
  content: "";
  display: block;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.5);
  transition: all .2s linear;
}

.block:hover:before {
  background: none;
}

.block h2,
.block p {
  position: relative;
}

Dogs are great sleepers

Mine can sleep all day long

Dogs are great sleepers

Mine can sleep all day long

Comment: You can even remove `z-index` from `.tint` and `.tint:before` entirely.
Comment: Or you could just use `box-shadow: 0 0 0 1000px rgba(0,0,0,0.5) inset;`. http://jsfiddle.net/tx58qf3m/5/
Comment: @SzabolcsPáll Using large box shadows destroys page performance, especially when scrolling on content-rich pages.
Comment: @Nit I didn't know that, do you have any reference?
Comment: @SzabolcsPáll There's countless examples, simply Google along the lines of box-shadow performance issues, see [this Airbnb](http://nerds.airbnb.com/box-shadows-are-expensive-to-paint/) article for an example.
Comment: @Nit actually that issue seems to be resolved by now https://code.google.com/p/chromium/issues/detail?id=99045
Comment: I dont understand @brouxhaha that you can remove the z-index completely. Doesnt that defeat the whole thing?
Comment: The way elements stack. The parent (`.tint`) will always be the first (or bottom) in the stack - it can never be above any children including pseudo elements. By default, `:before` will always come next and stack on top of the parent, and any children of `.tint` will come next and stack on top of both in order. Go to the fiddle and try it.
Comment: Generally, `z-index` only affects an element's stacking order in relation to its siblings, so setting it on `.tint` only affects how it gets stacked with its siblings, not its children.
Comment: I was able to implement this without the z-index.
Comment: @RonE Thanks for highlighting this, I wrote this post many years ago when I was less experienced with CSS. I've updated the example to remove redundant code.
Answer: The most straightforward solution is to contain the contents of the link in an element and apply to background to that.
HTML:

Themenwoche: Glatt gelogen!

Aktueller Beitrag

Themenwoche: Glatt gelogen!

Aktueller Beitrag

CSS:
body {
    color: #fff;
    font-family:arial;
}

a {
    color:#fff;
}

.block {
    display:block;
    width:250px;
    height:250px;
}

.tint {
    float: left;
    cursor: pointer;
}

.overlay {
    width: 210px;
    height: 210px;
    padding: 20px;
    background: rgba(0,0,0, 0.5);
    -moz-transition: all .2s linear;
    -webkit-transition: all .2s linear;
    -ms-transition: all .2s linear;
    -o-transition: all .2s linear;
    transition: all .2s linear;
}

.overlay *:first-child {
    margin-top: 0;
}

.tint:hover .overlay {
    background: none;
}

See this JSFiddle.


Hover effects on list item 3

Question: I'm trying to get li hover effect like the one on the right side bar of this page http://smokefree.gov/health-effects
as you see when you hover the background color and text color change
this is the code :

#ASIDE_1 {
    box-sizing: border-box;
    color: rgb(51, 51, 51);
    float: left;
    height: 528.171875px;
    min-height: 30px;
    width: 298.859375px;
    perspective-origin: 149.421875px 264.078125px;
    transform-origin: 149.421875px 264.078125px;
    background: rgb(255, 255, 255) none repeat scroll 0% 0% / auto padding-box border-box;
    border: 0px none rgb(51, 51, 51);
    font: normal normal normal normal 17px/26.0399990081787px cabinregular, Arial, Helvetica, sans-serif;
    margin: 13.4399995803833px 12.015625px 0px 8.3125px;
    outline: rgb(51, 51, 51) none 0px;
}/*#ASIDE_1*/

#DIV_2 {
    color: rgb(51, 51, 51);
    height: 232px;
    width: 298.859375px;
    perspective-origin: 149.421875px 116px;
    transform-origin: 149.421875px 116px;
    border: 0px none rgb(51, 51, 51);
    font: normal normal normal normal 17px/26.0399990081787px cabinregular, Arial, Helvetica, sans-serif;
    outline: rgb(51, 51, 51) none 0px;
}/*#DIV_2*/

#DIV_3 {
    color: rgb(51, 51, 51);
    height: 232px;
    width: 298.859375px;
    perspective-origin: 149.421875px 116px;
    transform-origin: 149.421875px 116px;
    border: 0px none rgb(51, 51, 51);
    font: normal normal normal normal 17px/26.0399990081787px cabinregular, Arial, Helvetica, sans-serif;
    outline: rgb(51, 51, 51) none 0px;
    overflow: hidden;
}/*#DIV_3*/

#IMG_4 {
    color: rgb(51, 51, 51);
    display: block;
    height: 232px;
    max-width: 100%;
    vertical-align: middle;
    width: 298.859375px;
    perspective-origin: 149.421875px 116px;
    transform-origin: 149.421875px 116px;
    border: 0px none rgb(51, 51, 51);
    font: normal normal normal normal 17px/26.0399990081787px cabinregular, Arial, Helvetica, sans-serif;
    outline: rgb(51, 51, 51) none 0px;
}/*#IMG_4*/

#DIV_5 {
    color: rgb(51, 51, 51);
    height: 283.171875px;
    width: 298.859375px;
    perspective-origin: 149.421875px 148.078125px;
    transform-origin: 149.421875px 148.078125px;
    border-top: 13px solid rgb(240, 240, 240);
    border-right: 0px none rgb(51, 51, 51);
    border-bottom: 0px none rgb(51, 51, 51);
    border-left: 0px none rgb(51, 51, 51);
    font: normal normal normal normal 17px/26.0399990081787px cabinregular, Arial, Helvetica, sans-serif;
    outline: rgb(51, 51, 51) none 0px;
}/*#DIV_5*/

#UL_6 {
    color: rgb(84, 84, 84);
    height: 283.171875px;
    width: 298.859375px;
    perspective-origin: 149.421875px 141.578125px;
    transform-origin: 149.421875px 141.578125px;
    background: rgb(255, 255, 255) none repeat scroll 0% 0% / auto padding-box border-box;
    border: 0px none rgb(84, 84, 84);
    font: normal normal normal normal 17px/26.0399990081787px cabinregular, Arial, Helvetica, sans-serif;
    margin: 0px;
    outline: rgb(84, 84, 84) none 0px;
    padding: 0px;
}/*#UL_6*/

#LI_7 {
    color: rgb(181, 96, 0);
    height: 92.390625px;
    min-height: 92.3999938964844px;
    width: 283.921875px;
    perspective-origin: 149.421875px 47.1875px;
    transform-origin: 149.421875px 47.1875px;
    background: rgb(255, 255, 255) none repeat scroll 0% 0% / auto padding-box border-box;
    border-top: 0px none rgb(181, 96, 0);
    border-right: 0px none rgb(181, 96, 0);
    border-bottom: 2px solid rgb(240, 240, 240);
    border-left: 0px none rgb(181, 96, 0);
    font: normal normal normal normal 17px/20px cabinregular, Arial, Helvetica, sans-serif;
    list-style: none outside none;
    outline: rgb(181, 96, 0) none 0px;
    padding: 0px 0px 0px 14.9375px;
}/*#LI_7*/

#A_8, #A_15, #A_22 {
    color: rgb(0, 136, 204);
    text-align: left;
    text-decoration: none;
    border: 0px none rgb(0, 136, 204);
    font: normal normal normal normal 17px/20px cabinregular, Arial, Helvetica, sans-serif;
    list-style: none outside none;
    outline: rgb(0, 136, 204) none 0px;
}/*#A_8, #A_15, #A_22*/

#DIV_9, #DIV_16, #DIV_23 {
    color: rgb(0, 136, 204);
    display: inline-block;
    height: 73.390625px;
    text-align: left;
    width: 232.8125px;
    perspective-origin: 116.40625px 36.6875px;
    transform-origin: 116.40625px 36.6875px;
    border: 0px none rgb(0, 136, 204);
    font: normal normal normal normal 17px/20px cabinregular, Arial, Helvetica, sans-serif;
    list-style: none outside none;
    outline: rgb(0, 136, 204) none 0px;
}/*#DIV_9, #DIV_16, #DIV_23*/

#H2_10 {
    color: rgb(181, 96, 0);
    height: 39px;
    text-align: left;
    text-rendering: optimizelegibility;
    width: 220.21875px;
    perspective-origin: 110.109375px 19.5px;
    transform-origin: 110.109375px 19.5px;
    background: rgb(255, 255, 255) none repeat scroll 0% 0% / auto padding-box border-box;
    border: 0px none rgb(181, 96, 0);
    font: normal normal bold normal 25px/39.0599975585938px cabinregular, Arial, Helvetica, sans-serif;
    list-style: none outside none;
    margin: 0px 12.5999994277954px 0px 0px;
    outline: rgb(181, 96, 0) none 0px;
}/*#H2_10*/

#P_11, #P_18, #P_25 {
    color: rgb(84, 84, 84);
    height: 26px;
    text-align: left;
    width: 232.8125px;
    perspective-origin: 116.40625px 13px;
    transform-origin: 116.40625px 13px;
    border: 0px none rgb(84, 84, 84);
    font: normal normal normal normal 17px/26.0399990081787px cabinregular, Arial, Helvetica, sans-serif;
    list-style: none outside none;
    margin: 0px 0px 8.39999961853027px;
    outline: rgb(84, 84, 84) none 0px;
}/*#P_11, #P_18, #P_25*/

#DIV_12 {
    background-position: 0px 0px;
    color: rgb(0, 136, 204);
    float: right;
    height: 35px;
    text-align: left;
    width: 28.390625px;
    perspective-origin: 14.1875px 17.5px;
    transform-origin: 14.1875px 17.5px;
    background: rgba(0, 0, 0, 0) url(http://smokefree.gov/sites/all/themes/sfg/images/content/smokefree-content-page-related-link-ong-mobile-43x43.png) no-repeat scroll 0px 0px / 90% padding-box border-box;
    border: 0px none rgb(0, 136, 204);
    font: normal normal normal normal 17px/20px cabinregular, Arial, Helvetica, sans-serif;
    list-style: none outside none;
    margin: 25px 8.39999961853027px 0px 0px;
    outline: rgb(0, 136, 204) none 0px;
}/*#DIV_12*/

#IMG_13, #IMG_20, #IMG_27 {
    color: rgb(0, 136, 204);
    height: 1px;
    max-width: 100%;
    text-align: left;
    vertical-align: middle;
    width: 1px;
    perspective-origin: 0.5px 0.5px;
    transform-origin: 0.5px 0.5px;
    border: 0px none rgb(0, 136, 204);
    font: normal normal normal normal 17px/20px cabinregular, Arial, Helvetica, sans-serif;
    list-style: none outside none;
    outline: rgb(0, 136, 204) none 0px;
}/*#IMG_13, #IMG_20, #IMG_27*/

#LI_14 {
    color: rgb(0, 128, 171);
    height: 92.390625px;
    min-height: 92.3999938964844px;
    width: 283.921875px;
    perspective-origin: 149.421875px 47.1875px;
    transform-origin: 149.421875px 47.1875px;
    background: rgb(255, 255, 255) none repeat scroll 0% 0% / auto padding-box border-box;
    border-top: 0px none rgb(0, 128, 171);
    border-right: 0px none rgb(0, 128, 171);
    border-bottom: 2px solid rgb(240, 240, 240);
    border-left: 0px none rgb(0, 128, 171);
    font: normal normal normal normal 17px/20px cabinregular, Arial, Helvetica, sans-serif;
    list-style: none outside none;
    outline: rgb(0, 128, 171) none 0px;
    padding: 0px 0px 0px 14.9375px;
}/*#LI_14*/

#H2_17 {
    color: rgb(0, 128, 171);
    height: 39px;
    text-align: left;
    text-rendering: optimizelegibility;
    width: 220.21875px;
    perspective-origin: 110.109375px 19.5px;
    transform-origin: 110.109375px 19.5px;
    background: rgb(255, 255, 255) none repeat scroll 0% 0% / auto padding-box border-box;
    border: 0px none rgb(0, 128, 171);
    font: normal normal bold normal 25px/39.0599975585938px cabinregular, Arial, Helvetica, sans-serif;
    list-style: none outside none;
    margin: 0px 12.5999994277954px 0px 0px;
    outline: rgb(0, 128, 171) none 0px;
}/*#H2_17*/

#DIV_19 {
    background-position: 0px 0px;
    color: rgb(0, 136, 204);
    float: right;
    height: 35px;
    text-align: left;
    width: 28.390625px;
    perspective-origin: 14.1875px 17.5px;
    transform-origin: 14.1875px 17.5px;
    background: rgba(0, 0, 0, 0) url(http://smokefree.gov/sites/all/themes/sfg/images/content/smokefree-content-page-related-link-blu-mobile-43x43.png) no-repeat scroll 0px 0px / 90% padding-box border-box;
    border: 0px none rgb(0, 136, 204);
    font: normal normal normal normal 17px/20px cabinregular, Arial, Helvetica, sans-serif;
    list-style: none outside none;
    margin: 25px 8.39999961853027px 0px 0px;
    outline: rgb(0, 136, 204) none 0px;
}/*#DIV_19*/

#LI_21 {
    color: rgb(96, 128, 24);
    height: 92.390625px;
    min-height: 92.3999938964844px;
    width: 283.921875px;
    perspective-origin: 149.421875px 47.1875px;
    transform-origin: 149.421875px 47.1875px;
    background: rgb(255, 255, 255) none repeat scroll 0% 0% / auto padding-box border-box;
    border-top: 0px none rgb(96, 128, 24);
    border-right: 0px none rgb(96, 128, 24);
    border-bottom: 2px solid rgb(240, 240, 240);
    border-left: 0px none rgb(96, 128, 24);
    font: normal normal normal normal 17px/20px cabinregular, Arial, Helvetica, sans-serif;
    list-style: none outside none;
    outline: rgb(96, 128, 24) none 0px;
    padding: 0px 0px 0px 14.9375px;
}/*#LI_21*/

#H2_24 {
    color: rgb(96, 128, 24);
    height: 39px;
    text-align: left;
    text-rendering: optimizelegibility;
    width: 220.21875px;
    perspective-origin: 110.109375px 19.5px;
    transform-origin: 110.109375px 19.5px;
    background: rgb(255, 255, 255) none repeat scroll 0% 0% / auto padding-box border-box;
    border: 0px none rgb(96, 128, 24);
    font: normal normal bold normal 25px/39.0599975585938px cabinregular, Arial, Helvetica, sans-serif;
    list-style: none outside none;
    margin: 0px 12.5999994277954px 0px 0px;
    outline: rgb(96, 128, 24) none 0px;
}/*#H2_24*/

#DIV_26 {
    background-position: 0px 0px;
    color: rgb(0, 136, 204);
    float: right;
    height: 35px;
    text-align: left;
    width: 28.390625px;
    perspective-origin: 14.1875px 17.5px;
    transform-origin: 14.1875px 17.5px;
    background: rgba(0, 0, 0, 0) url(http://smokefree.gov/sites/all/themes/sfg/images/content/smokefree-content-page-related-link-grn-mobile-43x43.png) no-repeat scroll 0px 0px / 90% padding-box border-box;
    border: 0px none rgb(0, 136, 204);
    font: normal normal normal normal 17px/20px cabinregular, Arial, Helvetica, sans-serif;
    list-style: none outside none;
    margin: 25px 8.39999961853027px 0px 0px;
    outline: rgb(0, 136, 204) none 0px;
}/*#DIV_26*/

      Live a smokefree life

      Discover the rewards of quitting

      Craving cigarettes?

      Get tips for when the urge hits

      Quitting today?

      Review steps for your quit day

Comment: Don't look like no Java to me.  I've retagged accordingly.
Comment: Add this to your CSS: `#UL_6 li:hover { background-color: #00F; }`. Also read about [MCVE](http://stackoverflow.com/help/mcve)
Comment: @dave: so close to what i want .. but how to change specific li .. not all the li
Answer: From Chrome's 'inspect element' it would appear that the list is using CSS :hover selector.
.li_foo:hover {
 background: #B56000;color: #FFFFFF;}

More info: http://www.w3schools.com/cssref/sel_hover.asp
Answer: If you look into the source of the page you linked to, the CSS rules that are being applied that change the background color and text color are as follows:
.li-first:hover,
.li-first:hover H2,
.li-first:hover A,
.li-first:hover A:visited H2 {
    background:none repeat scroll 0 0 #b56000;
    color:#ffffff;
}

...

.li-second:hover,
.li-second:hover H2,
.li-second:hover A,
.li-second:hover A:visited H2 {
    background: none repeat scroll 0 0 #0080ab;
    color: #ffffff;
}

...

.li-third:hover,
.li-third:hover H2,
.li-third:hover A,
.li-third:hover A:visited H2 {
    background: none repeat scroll 0 0 #608018;
    color: #ffffff;
}

So what's actually happening is the li element itself is having its background color changed (to a different color for each of the three li elements), and the descendent elements that have text content are having both their background color and text color changed as well (text to white).
You can apply the same design to your code, taking into account the differences between your code and the site code:
#LI_7:hover, #LI_7:hover h2, #LI_7:hover p { background-color:#b56000; color:#ffffff; }
#LI_14:hover, #LI_14:hover h2, #LI_14:hover p { background-color:#0080ab; color:#ffffff; }
#LI_21:hover, #LI_21:hover h2, #LI_21:hover p { background-color:#608018; color:#ffffff; }

http://jsfiddle.net/9juf1nLf/
Edit: Sorry, I didn't notice that the image had changed! After some investigation, this is the CSS rule that's changing the image:
.li-first:hover .image-note,
.li-second:hover .image-note,
.li-third:hover .image-note {
    background: url("../images/content/smokefree-content-page-related-link-ro-mobile-43x43.png") no-repeat scroll 0 0 / 90% auto transparent;
}

So what's happening is that they're replacing the entire image with an alternative one when you hover over the li. It's also a bit strange, as the .image-note class is actually being applied to a div that contains an img element. The img element is just applying a blank spacer, while the div is actually showing the visible image as its background image.
Also interesting is that they're using the exact same hover image for all three lis. This works because although the image needs to be colored differently when you're not hovering over it, when you are hovering over it, it's just the same plain white image for all three lis.
For comparison, here's the first colored image compared to the common white image:
http://smokefree.gov/sites/all/themes/sfg/images/content/smokefree-content-page-related-link-ong-mobile-43x43.png
http://smokefree.gov/sites/all/themes/sfg/images/content/smokefree-content-page-related-link-ro-mobile-43x43.png
Anyway, you can apply this to your code as well with the following:
#LI_7:hover #DIV_12, #LI_14:hover #DIV_19, #LI_21:hover #DIV_26 { background-image:url('http://smokefree.gov/sites/all/themes/sfg/images/content/smokefree-content-page-related-link-ro-mobile-43x43.png'); }

http://jsfiddle.net/9juf1nLf/2/
Comment: thanks so much that really explained everything, but what about the side image next to the li .. how does it invert

Hover effects on list item 3


Why does Drupal 7 prefer CSS @import rules to  tags?

Question: "Don't use @import," lots of guys say.
There are lots of shortcomings of using @import.

Using @import within a stylesheet adds one more roundtrip to the overall download time of the page.
Using @import in IE causes the download order to be altered. This may cause stylesheets to take longer to download, which hinders progress rendering making the page feel slower.

Why does Drupal 7 use it?
I want to change the @import rules to <link> tags. How can I do this?
Comment: +1 for the question, I just wanted to ask the same, and then found yours, thanks!
Answer: Don't use @import to import css files:

@import is used only in non-CSS aggregation mode. This is done to workaround IE limitation with the number of  tags.

This should explain the reason and how to get rid of it. Any production site should use CSS aggregation, and not have @import.
Comment: +1, thanks for the answer. So this is a workaround for what IE CSS Optimizer module (http://drupal.org/project/ie_css_optimizer) had to be used in Drupal 6 to fix the issue that Internet Explorer refuses to load more than 31 linked stylesheets.
Comment: I know this is a few years later and most sane people don't use IE. unfortunately I don't work for most sane people. When using respond.js in IE 8 it fails to work using @imports. this gotcha can be hard to find
Comment: As for me i have never bumped in IE tags limitation. So it seems like stupid decision. Override of problem that almost never happens. If there are a lot of CSS files you have to think how to merge most part of them. In order to speed up page loading.
Comment: -1, This answer doesn't answer the two questions in the original post. Why does Drupal use @import and how do we change it?


Start/stop Postfix as service or directly

Question: What's the difference between starting postfix directly (postfix start) and as a service (service postfix start)? What (if any) is the preferred way as a best practice, and is there any way to make service postfix status show the process as active no matter how it was started?
Some code to further clarify:
root@luke:/# postfix status; service --status-all | grep postfix
postfix/postfix-script: the Postfix mail system is running: PID: 17332
 [ - ]  postfix

root@luke:/# postfix stop; service postfix start
postfix/postfix-script: stopping the Postfix mail system

root@luke:/# postfix status; service --status-all | grep postfix
postfix/postfix-script: the Postfix mail system is running: PID: 18237
 [ + ]  postfix

Answer: Starting it as a system service is naturally the best way, everything else should only be used for testing/debugging purposes.
This way, the service is integrated into the normal startup procedure of the system and can be easily turned on or off for subsequent reboots, and you can use reporting features of your init system.
This reporting (service xxxx status) can't be easily achieved for manual started services and, while certainly not impossible, it would require some work of your own to make it possible (and then run into conflicts on updates).
Speaking of updates, this is another important advantage of using system services, as the update mechanism can restart the service if necessary, depending on the configuration and nature of the update.


Animal sound in Alkan's Le Festin d'Aesop

Question: Hi guys I've been practicing piano for years. I heard the piece Le Festin D'Aesop by Charles Alkan and got obsessed researching about this one. However, there is a theory that the sound from the piece depicts different sound of animals who present in Aesop's fables. I attempted to imagine the sound but nothing is relevant. Could someone practicing this before help me out?
Answer: No, it sounds like you have to use your imagination.
According to this source,

It's in the finale (`Free multiple variations') that the Festin (communal feast) aspect comes into its own. In Alkan's Le Festin d'Aesop the variations seem to represent animals – although, unlike say Saint-Saëns's Carnaval des animaux, we are left to guess their identities.
Answer: I shouldn't worry if you can't identify animals in all the variations. I know that in many of Aesop's fables the characters are animals, but perhaps in trying to pin the tale on the music we have the wrong idea. I quote from Ronald Smith's excellent Alkan Vol. two, The Music:
Sir Roger L'Estrange's Life and Fables of Aesop offers a more plausible theory. He relates how Aesop's master, Xanthus, invited several philosophers to supper on two consecutive nights. Xanthus instructed his slave to provide a banquet from the choicest and then from the basest of all foods. On both occasions Aesop brought the same delicacy to his master's table, an ox-tongue, but prepared in every possible manner: sliced, dressed, fried, boiled, etc. In this way Aesop was able to demonstrate to his master's distinguished guests the absolute power of the word, its responsibility for all good and for all evil in the world. This was "Aesop's feast".
So perhaps the only connection to the music is that it is a theme with diverse variations. And the variations certainly are diverse. If you're wondering "if that's all he meant, why did he use an obscure classical allusion instead of just Air varié?", well, that's Alkan for you. He liked putting allusions to the classics, or to the Torah/Old Testament, in titles of his works.
I agree with Ronald Smith in identifying animals in one variation: in XXI we have hunting horns, and in XXII Alkan unleashes the hounds, which get increasingly vocal as the variation continues. The way Raymond Lewenthal plays XXII it's hilarious.
Best of luck trying to master Le festin d'Esope. Parts of it are very taxing on the stamina (e.g. XXV and the ensuing coda) or the fingers (especially XVII and XVIII).

Animal sound in Alkan’s Le Festin d’Aesop


Find $\lim\limits_{n \to \infty} n \int_2^e (\ln x)^n \, dx$.

Question: I have to find the limit:
$$\lim\limits_{n \to \infty} n \displaystyle\int_2^e (\ln x)^n dx$$
I tried using the Squeeze Theorem but it didn't work (or at least I didn't use it correctly):
$$2 \le x \le e$$
I took the log of this inequality
$$\ln(2) \le \ln(x) \le 1$$
Raised to the $n$:
$$\ln^n(2) \le \ln^n(x) \le 1$$
Took the integral from $2$ to $e$:
$$\int_2^e \ln^n(2)dx \le \int_2^e \ln^n(x) dx \le \int_2^e 1 dx$$
$$\ln^n(2) \cdot (e-2) \le \int_2^e \ln^n(x) dx \le (e-2)$$
Multiplied by n:
$$n \ln^n(2) \cdot(e - 2) \le n\int_2^e \ln^n(x) dx \le n(e-2)$$
And now, since $\ln(2) < 1$, so $\ln^n(2) = 0$ as $n \to \infty$, if I take the limit with $n \to \infty$ I get:
$$\infty \cdot 0 \le n\int_2^e \ln^n(x) dx \le \infty$$
So I didn't get anywhere trying to use the Squeeze Theorem.
Comment: @imranfat Yes, I think it would change the answer. If you look at Atticus' answer you will see that he used the Squeeze Theorem. If you look at his last inequality you will see that he has a limit involving $\ln^{n+1}2$ on one side and $\ln^{n}2$ on the other side. Because $\ln2<0$, we have $\lim_{n \to \infty} (\ln 2)^n = 0$ and we can evaluate both the limits and use the Squeeze Theorem, but if we would have $\ln 3$, that wouldn't go to $0$ as $n$ goes to $\infty$. Does that make sense?
Comment: I wonder, does it matter that the lower bound is $2$? I mean, if the lower bound were to be $3$, would that change tho outcome of the limit?
Answer: As you said $\lim\limits_{n\to \infty}\ln^n 2=0$. Let:
$$I_n = \int_2^e\ln^n x\,dx$$
$I_n$ is decreasing because:
$$I_{n}-I_{n+1}=\int_2^e\ln^n x(1-\ln x)\,dx \geq 0$$
Integrating by parts:
$$
\begin{aligned}
\displaystyle\int_2^e \ln^n x\, dx &= \displaystyle\int_2^e \ln^n x \cdot (x)'\, dx\\
&=x\ln^n x\bigg|_2^e -n\int_2^e\ln^{n-1}x\,dx\\
&= e-2\ln^n 2-nI_{n-1}
\end{aligned}
$$
Therefore $I_n+nI_{n-1}=e-2\ln^n2$. Now, since $I_n$ is decreasing:
$$I_n+nI_{n-1}\geq I_n+nI_n\Rightarrow I_n\leq \frac{1}{n+1}(e-2\ln^n 2)$$
and
$$I_{n+1}+(n+1)I_n\leq I_n+(n+1)I_n\Rightarrow I_n\geq \frac{1}{n+2}(e-2\ln^{n+1}2)$$
Combining the two:
$$\frac{1}{n+2}(e-2\ln^{n+1}2) \leq I_n\leq \frac{1}{n+1}(e-2\ln^n 2)$$
or
$$\frac{n}{n+2}(e-2\ln^{n+1}2) \leq nI_n\leq \frac{n}{n+1}(e-2\ln^n 2)$$
and squeezing $\lim\limits_{n\to \infty}nI_n=e$.
Comment: The line before "combining the two". It should start with $I_{n+1}+(n+1)I_{n}$
Comment: @bjorn93, Great spotting. It took me a while to realize it even after you pinpointed. Edited accordingly.
Answer: Use $t = \log^{n+1}(x) \implies \frac{1}{n+1}e^{t^{\frac{1}{n+1}}}dt = \log^n(x)dx$:
$$I = \lim_{n\to\infty} \frac{n}{n+1}\int_{\log^{n+1}(2)}^1 e^{t^{\frac{1}{n+1}}}\:dt \longrightarrow \int_0^1 e\:dt = e$$
by dominated convergence.
Answer: Let $\epsilon $ be any fixed number such that $0<\epsilon <e-2$ and we split the integral as a sum of two integrals using intervals $[2,e-\epsilon]$ and $[e-\epsilon, e] $. The first integral tends to $0$ as integrand uniformly tends to $0$.
For the second integral we need to bound it suitably. We have via integration by parts $$(n+1)\int_{e-\epsilon} ^{e} \dfrac{(\log x) ^n} {x} \cdot x\, dx=\left. x(\log x) ^{n+1}\right|_{x=e-\epsilon} ^{x=e} - \int_{e-\epsilon} ^{e}(\log x) ^{n+1}\,dx$$ (note that the factor $n$ before integral can be safely replaced by $(n+1)$ as $n/(n+1)\to 1$). The first term on right tends to $e$ and second term is bounded in absolute value by $\epsilon$ (as integrand lies in $[0,1]$). It follows that the desired limit is $e$.
Answer: Fixed $\epsilon\in(0,1-\ln2)$. Let $u=\ln x$ and then
$$ n\int_2^e (\ln x)^n dx=n \int_{\ln 2}^1 u^ne^u du=n \int_{\ln 2}^{1-\epsilon} u^ne^u du+n \int^1_{1-\epsilon} u^ne^u du.$$
For the 1st part,
$$ 0\le n \int_{\ln 2}^{1-\epsilon} u^ne^u du\le 3n(1-\epsilon)^n $$
and one has
$$ \lim_{n\to\infty} n \int_{\ln 2}^{1-\epsilon} u^ne^u du=0. $$
For the 1st part, by the Mean Value Theorem for integrals, there is $\xi\in(1-\epsilon,1)$ such that
$$ n \int_{1-\epsilon}^1 u^ne^u du=n e^\xi\int_{1-\epsilon}^1 u^n du=\frac{n}{n+1}e^\xi(1-(1-\epsilon)^{n+1}). $$
Noting that
$$ e^{1-\epsilon}(1-(1-\epsilon)^{n+1})\le e^\xi(1-(1-\epsilon)^{n+1})\le e  $$
one has
$$ \frac{n}{n+1}e^{1-\epsilon}(1-(1-\epsilon)^{n+1})\le n \int_{1-\epsilon}^1 u^ne^u du=n e^\xi\int_{1-\epsilon}^1 u^n du\le\frac{n}{n+1}e $$
and hence
$$  e^{1-\epsilon}\le \underline{\lim}_{n\to\infty}n \int_{1-\epsilon}^1 u^ne^u du\le \overline{\lim}_{n\to\infty}n \int_{1-\epsilon}^1 u^ne^u du\le e. $$
So
$$  e^{1-\epsilon}\le \underline{\lim}_{n\to\infty}n \int_{\ln 2}^1 u^ne^u du\le \overline{\lim}_{n\to\infty}n \int_{\ln 2}^1 u^ne^u du\le e. $$
Letting $\epsilon\to0$ one has
$$ e\le \underline{\lim}_{n\to\infty}n \int_{\ln 2}^1 u^ne^u du\le \overline{\lim}_{n\to\infty}n \int_{\ln 2}^1 u^ne^u du\le e $$
or
$$ \lim_{n\to\infty}n \int_{\ln 2}^1 u^ne^u du= e $$


Releasing an Array crashes the app in xCode

Question: why does my app crash when releasing an array? Ive been trying to figure it out for HOURS! If I dont release it, it causes a memory leak. If I do release it, it crashes with this error:
    Program received signal:  "EXC_BAD_ACCESS".
Sometimes it also says this:
    Data Formatters temporarily unavailable, will re-try after a 'continue'. (Not safe to call dlopen at this time.)
Just cant work it out. Theres alot of code, so i will paste (what i think) is the relevant parts.
-(void)startGame:(int)levelNumber {

    //NOTE there is some code ive not pasted as its too big, but I dont think its relevant

levelsArray = [gameLevels loadLevelMap:levelNumber];
levelsArray_charGuards = [[levelsArray objectAtIndex:4]retain];

    //CREATE CHAR MAIN ########
charMainStore = [[NSMutableArray arrayWithCapacity:1] retain];

charMainToDestroy = [[NSMutableArray arrayWithCapacity:1] retain];

CharMain* charMain = [[CharMain alloc] initWithFrame:CGRectMake(((levels_charStart_x)*40), ((levels_charStart_y)*40), 0, 0)];
[viewController.mapView addSubview:charMain];

[self registerMainChar:charMain];
charMain.gameController = self;
charMain.currentGrid_x = levels_charStart_x;
charMain.currentGrid_y = levels_charStart_y;
charMain.nextGrid_x = levels_charStart_x;
charMain.nextGrid_y = levels_charStart_y;
mapViewController.gameController = self;

[self moveMap_x:((levels_charStart_x)*40) moveMap_y:((levels_charStart_y)*40)];

[charMain release];

 //CREATE CHAR GUARD ########
charGuardStore = [[NSMutableArray arrayWithCapacity:10] retain];
charGuardToDestroy = [[NSMutableArray arrayWithCapacity:10] retain];
    //These are both @synthesize properly
    //levelsArray_charGuards is from previously

    for (NSMutableArray* levelsArray_charGuards_path in levelsArray_charGuards) {

    NSMutableArray* levelsArray_charGuards_path_eachCoOrd = [levelsArray_charGuards_path objectAtIndex:0];

    int levels_charGuardStart_x = [[NSString stringWithFormat:@"%@",[levelsArray_charGuards_path_eachCoOrd objectAtIndex:0]] intValue];
    int levels_charGuardStart_y = [[NSString stringWithFormat:@"%@",[levelsArray_charGuards_path_eachCoOrd objectAtIndex:1]] intValue];

    CharGuard* charGuard = [[CharGuard alloc] initWithFrame:CGRectMake((levels_charGuardStart_x*40), (levels_charGuardStart_y*40), 0, 0)];
    //CharGuard* charGuard = [[CharGuard alloc] initWithFrame:CGRectMake(((levels_charStart_x)*40), ((levels_charStart_y)*40), 0, 0)];

    [viewController.mapView addSubview:charGuard];

    [self registerGuardChar:charGuard];
    charGuard.gameController = self;
    [charGuard setImage];
    charGuard.currentGrid_x = levels_charGuardStart_x;
    charGuard.currentGrid_y = levels_charGuardStart_y;
    charGuard.nextGrid_x = levels_charGuardStart_x;
    charGuard.nextGrid_y = levels_charGuardStart_y;
    mapViewController.gameController = self;

    charGuard.levelsArray_charGuards_path = levelsArray_charGuards_path;

    [charGuard release];
    charGuard = nil;

    levelsArray_charGuards_path = nil;

    levelsArray_charGuards_path_eachCoOrd =nil;
}
}

When one level is finished, or is restarted, this is called:
-(void)clearLevel {
NSLog(@"Clear Level");

    for (CharMain* charMain in charMainStore){

    [charMain removeFromSuperview];
    [charMainToDestroy addObject:charMain];
}

for (CharMain* charMain in charMainToDestroy){

    [charMainStore removeObject:charMain];

}

for (CharGuard* charGuard in charGuardStore) {

    [charGuard removeFromSuperview];
    [charGuardToDestroy addObject:charGuard];

}

for (CharGuard* charGuard in charGuardToDestroy){

    [charGuardStore removeObject:charGuard];

}

    [charGuardStore release];
charGuardStore=nil;

[charMainStore release];
charMainStore=nil;

//[charGuardToDestroy release]; //If I allow this it crashes!***********
charGuardToDestroy= nil;

[charMainToDestroy release];
charMainToDestroy = nil;

}

The game then calls startGame:(int)levelNumber again.
I have other object which i havnt shown here but they all work fine. Its just the charGuardToDestroy that doesnt want to be released!
I have tried:
-(void)clearLevel {
NSLog(@"Clear Level");

    for (CharMain* charMain in charMainStore){

    [charMain removeFromSuperview];
    [charMainToDestroy addObject:charMain];
}

for (CharMain* charMain in charMainToDestroy){

    [charMainStore removeObject:charMain];

}

for (CharGuard* charGuard in charGuardStore) {

    [charGuard removeFromSuperview];
    //[charGuardToDestroy addObject:charGuard];

}
/*
for (CharGuard* charGuard in charGuardToDestroy){

    [charGuardStore removeObject:charGuard];

}
    */

    [charGuardStore release];
charGuardStore=nil;

[charMainStore release];
charMainStore=nil;

[charGuardToDestroy release]; //I tried allowing this and removing the above code ***********
charGuardToDestroy= nil;

[charMainToDestroy release];
charMainToDestroy = nil;

}

This also worked, but why?? I really need to be able to remove the charGuard from the screen, and from the array, then release it, but I can only do one or the other. Its strange!
Answer: Most likely you somewhere added a CharGuard object to the array charGuardStore which is only retained by this array and charGuards superview.
Here is what I think happens:
for (CharGuard* charGuard in charGuardStore) {

    [charGuard removeFromSuperview];             // charGuard only retained by charGuardStore (= 1 retain left)
    [charGuardToDestroy addObject:charGuard];    // charGuard retained by charGuardToDestroy too (= 2 retains left)

}

for (CharGuard* charGuard in charGuardToDestroy){

    [charGuardStore removeObject:charGuard];     // remove 1 retain (= 1 retain left) because it's still in charGuardToDestroy

}

/* more code */

[charGuardToDestroy release];                    // remove all charGuards. charGuard gets released. And most likely you access it later.

so most likely your bug happens already when you create the CharGuards. Probably overreleasing, but the effect shows up much much later.
Use NSZombieEnabled to figure out if this is the case.
I think if you add [charGuardToDestroy removeAllObjects]; after you have removed the charGuards from that array it will crash. This would confirm what I said.
Comment: Thanks. I used the Zombies (which I didnt know existed because it was greyed out) but this worked great and found some other bugs. Does [charGuard removeFromSuperview]; also release charGuard? I think part of the problem was within charGuard, under -(void)dealloc{} I was releasing charImage which was set earlier:
 NSString* tempStr = [NSString stringWithFormat:@"char_guard_%d_%d",2,1];

 UIImage* loadedImage = [UIImage imageNamed:tempStr];
 charImage = [loadedImage retain];
I thought this should have been released.
Comment: sorry for the late answer. Yes, removeFromSuperview will release the object 1 time. This release is just to counter the retain that was caused when you added that view with `addSubView:` to another view earlier. Looks like you retained charImage, so you have to release it in dealloc. Since you marked my answer as correct I hope you figured it out. Unfortunately sometimes memory bugs are hard to find.


SCons - integrating custom builders for CUDA, CORBA etc

Question: For a a heterogeneous (C, C++14, Fortran95, python3) project, I'm currently evaluating what advantages over CMake SCons will provide to us for the integration of platform compilers and compiler wrappers for CUDA (7.5), CORBA (omniorb-4.2.1), MPI2 (MPICH) etc.
To get started, I created a project root directory ('data/projects/snippets' in the SConstruct script attached) with a subdirectory 'model', in which the 'echo.idl' of the omniorb4 Documentation
interface Echo {
    string echoString(in string mesg);
};

resides (an echo_i.cc with an int main() will be generated by omniidl used with the -Wbexample switch), and a subdirectory-tree 'include/cuda_samples_inc', which is a copy of the the 'common/inc' branch of the CUDA Toolkit Samples, and copied the CUDA Toolkit Samples
2_Graphics/simpleGL/simpleGL.cu

into the project root directory.
My customized SConstruct
import os

CORBA_PASS = False
CUDA_PASS = True

CUDA_FAIL = not CUDA_PASS
CORBA_FAIL = not CORBA_PASS

EXE_SUFFIX = None
if os.name != 'posix':
    raise NotImplementedError('Only on POSIX platforms yet')

PROJECT_ROOT = '/data/projects/snippets'  # your mileage will likely vary

INCLUDE_DIR = os.path.join(PROJECT_ROOT, 'include')
LIB_DIR = os.path.join(PROJECT_ROOT, 'lib')

SYS_LIBS = ['dl', 'pthread']
GL_LIBS = ['glut', 'GLEW', 'GL', 'GLU', 'X11']
CORBA_LIBS = ['omniORB4', 'omnithread']

class CUDAEnvironment(Environment):
    CUDA_ROOT = '/usr/local/cuda-7.5'
    CUDA_BIN_DIR = os.path.join(CUDA_ROOT, 'bin')
    CUDA_INCLUDE_DIRS = os.path.join(INCLUDE_DIR, 'cuda_samples_inc')
    GENC = "-gencode arch=compute_%d,code=sm_%d "
    GEN_RANGE = [20, 30, 35, 37, 50, 52]
    GENT = "-gencode arch=compute_52,code=compute_52"
    GENS = " ".join([GENC % (n, n) for n in GEN_RANGE]) + GENT

    COMPILE = """\
        %s/nvcc -ccbin g++ -I %s -m64 %s -o $TARGET -c $SOURCE \
    """ % (CUDA_BIN_DIR, CUDA_INCLUDE_DIRS, GENS)

    LINK = """\
        %s/nvcc -ccbin g++ -I %s -m64 %s -o $TARGET $SOURCE \
        -L%s, %s\
    """ % (CUDA_BIN_DIR, CUDA_INCLUDE_DIRS, GENS, LIB_DIR,
           ''.join([' -l%s' % (s,) for s in GL_LIBS]))

    def __init__(self):
        super(Environment, self).__init__()
        C = CUDAEnvironment  # class alias

        self.Append(PATH=":".join([os.environ['PATH'],
                                    C.CUDA_BIN_DIR]))

        cu2o = Builder(action=C.COMPILE, suffix='.o', src_suffix='.cu')
        o2exe = Builder(action=C.LINK, suffix=EXE_SUFFIX, src_suffix='.o')

        self.Append(BUILDERS={'CU2O': cu2o, 'O2EXE': o2exe})

if (CUDA_PASS):
    CUDA = CUDAEnvironment()
    CUDA.CU2O(['simpleGL.cu'])
    CUDA.O2EXE(['simpleGL.o'])

if (CUDA_FAIL):
    CUDA = CUDAEnvironment()
    o = CUDA.Object(['simpleGL.cu']) # line 63
    CUDA.Program(o)

class CORBAEnvironment(Environment):
    IDL2CC = """
        omniidl -bcxx -Wbexample $SOURCE
        cp `basename $SOURCE .idl`SK.cc `basename $SOURCE .idl`.cc
     """
    COMPILE = """\
        g++ -std=c++14 -I. -Wall -pedantic %s $SOURCES -o $TARGET
    """ % (''.join([' -l%s' % (s,) for s in CORBA_LIBS + SYS_LIBS]))

    def __init__(self):
        super(Environment, self).__init__()
        C = CORBAEnvironment  # class alias

        idl2cc = Builder(
            action=C.IDL2CC, suffix='.cc', src_suffix='.idl'
        )

        cc2exe = Builder(
            action=C.COMPILE, suffix=EXE_SUFFIX, src_suffix='.cc'
        )

        self.Append(BUILDERS={'IDL2CC': idl2cc, 'CC2EXE': cc2exe})

if (CORBA_PASS):
    CORBA = CORBAEnvironment()
    CORBA.IDL2CC('echo.cc', os.path.join('model', 'echo.idl'))
    CORBA.CC2EXE('echo', ['echo.cc', 'echo_i.cc'])

if (CORBA_FAIL):
    CORBA = CORBAEnvironment()
    skel = CORBA.Object(os.path.join('model', 'echo.idl'))  # line 98
    impl = CORBA.Object('echo_i.cc')
    CORBA.Program([skel, impl])

works well with the switches CUDA_PASS and CORBA_PASS enabled, but for the
CUDA = CUDAEnvironment()
o = CUDA.Object(['simpleGL.cu']) # line 63
CUDA.Program(o)

resp
CORBA = CORBAEnvironment()
skel = CORBA.Object(os.path.join('model', 'echo.idl'))  # line 98
impl = CORBA.Object('echo_i.cc')
CORBA.Program([skel, impl])

blocks, scons gives up due to that sort of error I was afraid of:
scons: *** While building `['simpleGL.o']' from `['simpleGL.cu']'
Don't know how to build from a source file with suffix `.cu'.
Expected a suffix in this list: ['.c', '.m', '.cpp', '.cc', '.cxx',
'.c++', '.C++', '.mm', '.C', '.f', '.for', '.ftn', '.fpp', '.FPP',
'.F', '.FOR', '.FTN', '.f77', '.F77', '.f90', '.F90', '.f95', '.F95',
'.f03', '.F03', '.s', '.asm', '.ASM', '.spp', '.SPP', '.sx', '.S'].
File "/data/projects/snippets/SConstruct", line 63, in <module>

resp.:
scons: *** While building `['model/echo.o']' from `['model/echo.idl']':
Don't know how to build from a source file with suffix `.idl'
[same as above]
File "/data/projects/snippets/SConstruct", line 98, in <module>.

Sadly,

how to build from a source file with suffix <suffix>

is just what I tried to tell scons with my custom environments and builders.
So my question is:
How to integrate custom environments and builders so that the SCons Object() and Program() builder facade can be used?
The Scons Builder() doc, esp. 18.2. Attaching a Builder to a Construction Environment seemingly just explains the syntax used in my PASS blocks along with passed-though Program() invocation, but not how make e.g. 'Object()' aware of the custom builders.
It goes without saying that python itself could be used to hand-code virtually every kind of behavior or add-on, but I want to stay within the realm of the SCons toolset as much as possible.
versions:
SCons 2.3.1 (but that is not craved in stone, if an update to 2.4.1 will help, I'll do that) run with python 2.7.9
Comment: What does this question have to do with CUDA programming? Why is it tagged with the CUDA tag? Isn't a purely an `scons` configuration questiton?
Answer: SCons has the notion of a src_builder. It's a keyword (usually added to the constructor of the Builder class) that informs the system how to create the actual C/CPP source files by running an additional builder first.
Check out the Tool engine/SCons/Tool/qt.py in ll. 315 where it says:
# register the builders
env['BUILDERS']['Uic'] = uicBld
env['BUILDERS']['Moc'] = mocBld
static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
static_obj.add_src_builder('Uic')
shared_obj.add_src_builder('Uic')

. By calling add_src_builder the Uic builder gets registered with the static and shared Object builders each. Then, if an *.uic file is given to Object directly, SCons checks its list of defined source builders, converts the *.uic to its corresponding *.cc file and then passes the latter on to the Object builder.
Comment: Once you've successfully mastered the creation of an Object file, you should let the default handler for Program handle the linking step. Don't provide a specialised builder for linking each of your objects into the final executable. Instead, initialise a separate environment for each build task where you require different paths and/or settings. You'll also want to use the special variables like CPPPATH for include directories instead of hardcoding the "-I" flags into your command call, because the former let's you build on Windows as well.
Comment: There are several duplicates for this error message here at SO. It's probably better to open a new question, after checking that none of the other already existing answers aren't helping you out.
Comment: **Thanks a lot**! That's definitely a big step ahead, at least  the `Object()` call for the CORBA works (after some trivial mods of my code) with a .idl. Issue is, that the CU2O tool already produces an `.o`, and scons rightfully complains about  `Multiple ways to build the same target [...]  simpleGL.o` if I try to add my `CU2O` as as a `src_builder`. In addition I'm now the hunt for some use of the related  `Tool.createProgBuilder(env)`  to also plug my exe builders under the  `Program()` call. I'll update my code when I have a substantial progress and would like to drop you a line if I may.
Comment: Since you're starting with SCons, and looking at your current build specification, I'd also suggest that you subscribe to our user mailing list (email@example.com , see also http://scons.org/lists.php ) and start to ask your further questions there. You'll reach a much broader audience of SCons experts there...and response times are usually very short.
Comment: I'll certainly subscribe to that list; ty for that tip.
Comment: Ok, using your recipe I got the CORBA env part working acceptably smooth. But for the CUDA build, using the `add_src_builder` method to make scons recognize the '.cu' suffix,  leads to the already mentioned  `Multiple ways to build the same target were specified for: simpleGL.o  (from ['simpleGL.cu'] and from ['simpleGL.o'])` error. Although I understand the reason for this error, I don't know how to avoid it while maintaining the comfort of declaring `.cu`  as a source suffix (aside from decomposing nvcc's generation of object files from .cu into multiple steps)


Creating routes dynamically in Svelte

Question: I'm creating a Svelte SPA as a wrapper for an API. I get all data (content, menu items) from this API and I would like to create these routes dynamically. I have only one page (Mypage.svelte) and its content is updated depending on the menu link I click. Currently I am using the svelte-spa-router where I define the menu URLs manually:
<code>export const routes = {
  "/group0": Mypage,
  "/group1": Mypage,
  "/group2": Mypage,
  "/group3": Mypage,
  "/group4": Mypage,
  "*": NotFound
};
</code>
Is it possible in Svelte or SvelteKit to set these dummy routes dynamically for example by preloading them from my API?
Answer: As far as I am aware it is not possible to generate routes dynamically the way you describe
Although there might be an alternative at hand.
SvelteKit
In SvelteKit the routes are generated by the file System. Docs
You can define a Layout for your app and for every Sub Folder Docs
and pass arguments as part of the URL Docs
This way you could determine a Layout and pass a parameter via URL and fetch your data accordingly.
Depending on how variant your data is, this might be an option.

Creating routes dynamically in Svelte


Colorbar not appearing in (surface) plot - LaTeX interpreter issue

Question: As the title states, the colorbar in surface plots does not appear when the default interpreter is set to 'latex'. This occurs in MATLAB 2012b and 2013a and on two different machines.
Precisely, the colorbar object is created, can be clicked when editing the plot, can be edited using the interactive colorbar editor but is not visible at all.
It does not appear when saved as a figure and reopened, saved as a PNG, exported in .eps format or saved as a .pdf.
After searching around, I found the following post from 2011, concerning MATLAB 7:
http://mathforum.org/kb/message.jspa?messageID=7518470
Specifically, the interpreter appears to be at fault, when it is set to 'latex', the colorbar will not display. When set to the default, it does.
Here is the smallest demonstrating example.
set(0,'defaulttextinterpreter','none');
figure;
surf(peaks(100)); colorbar
set(0,'defaulttextinterpreter','latex');
figure
surf(peaks(100)); colorbar

The two figures are identical except that the colorbar is visible only in the first figure.
I use a lot of special characters and sub/superscripts in my plots so in startup.m I set the default interpreter to 'latex'. I could surround all calls to colorbar with:
 set(0,'defaulttextinterpreter','none');
 colorbar;
 set(0,'defaulttextinterpreter','latex');

But this is probably the least elegant solution possible. Can anyone shed some light on this issue which appears to be extant for over 5 years and multiple editions of MATLAB?
Answer: This behaviour is gone in Matlab R2014b, which uses an entirely new graphics engine, hg2. The plots look different (most of the time in a better way), but instead of old, documented bugs, there are now new, undocumented bugs...

Earlier versions of Matlab support somewhat experimental stages of hg2. You can enable these by running Matlab with the switch "-hgVersion 2". You can do this, for example, by editing the Desktop shortcut to point to something like "C:\Program Files\MATLAB\R2013b\bin\matlab.exe" -hgVersion 2.
Unfortunately, with the new graphics engine being the default in Matlab2014b, the old bugs are less likely to be fixed in the future. I wish I could help you in a better way, but the workaround you posted seems like a good solution, especially if you wrap it in a function called robust_colorbar or so.
Comment: The answers supplied address different aspects of the problem, I only wish I could 'accept' both. I've ended up going with replacing all calls to colorbar with `robustColorbar` instead of changing the renderer only due to consistency with all my previous graphics.

much appreciated
Answer: I can reproduce the problem on my system (R2010b, Windows Vista 32 bits) . It seems to be solved by changing the 'Renderer' property of the figure from the default 'OpenGL' to either 'painters' or 'zbuffer'. So, you can either change the renderer when creating the figure:
set(0, 'defaulttextinterpreter', 'latex');
figure('Renderer', 'zbuffer') %// this line changed
surf(peaks(100)); colorbar

or change the default renderer to be used for all figures (so you don't need to change it in every figure):
set(0, 'DefaultFigureRenderer', 'zbuffer'); %// this line added
set(0, 'defaulttextinterpreter', 'latex');
figure
surf(peaks(100)); colorbar

Using a renderer other than 'OpenGL' may affect features such as transparency or drawing speed. Here's some information about pros and cons of each renderer.


Equivalent of Python's min() with lambda in Ruby

Question: In Ruby, what would be the equivalent of the Python code below?
x = [6, 7, 8, 9, 10, 2, 3, 4]
y = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

min(range(len(x)), key=lambda i: y.index(x[i]))
=> 5

Edit: I'm just looking for a direct translation from Python to Ruby, don't bother about the  semantic of the provided example.
Comment: I think this means: the element in `x` with the smallest index in `y`.
Comment: Better to use a helper dict than the repeated calls to `.index` eg. `min(range(len(x)), key=(lambda i, d={k:v for v,k in enumerate(y)}: d.get(x[i])))`
Answer: Do you want to get the index of the smallest element?
x = [6, 7, 8, 9, 10, 2, 3, 4]

x.index(x.min()) # => 5
x.each_with_index.min[1] # => 5
(0...x.size).min_by {|i| x[i] } # => 5

Answer: Translating directly...
(0...x.length).min_by { |i| y.find_index(x[i]) }

Built-in functions that take lambdas in python tend to translate to Ruby methods that take blocks (lambdas defined in-line, essentially).
Edit: A slightly more idiomatic translation could be
obj,index = x.each_with_index.min_by { |o,i| y.find_index(o) }
index


What programming languages are supported by XFCE plugins?

Question: What programming languages are supported by XFCE plugins? \
Comment: From what I've seen you can only write these plugins in C (maybe in C++ too, but I'm not sure).
Comment: @luke1985 I have seen python and C so far. I need a full list, not guesses.
Comment: That's why I've posted a comment; other than that you will have to wait for an answer. I guess you would get the answer yourself if you look at the project sources.
Comment: @luke1985 That's my problem, I'd like to know this from some kind of documentation, not from the source code. Isn't there a plugin api docs? I did not find it...
Answer: en.wikipedia.org/wiki/Xfce:

Xfce is based on the GTK+ toolkit.

See gtk.org/language-bindings.
Next, you can search for this:

Together with GtkSocket, GtkPlug provides the ability to embed widgets from one process into another process in a fashion that is transparent to the user.
Answer: EDIT: Cleaned up answer a bit and linked to complete GTK+ language binding support (again).

GTK Language Binding Support:
As answered earlier, Xfce is GTK+ and uses that toolkit.
https://www.gtk.org/language-bindings.php

Panel Plugins:
Creating a panel plugin:
Python is supported, along with what GTK+ uses. Whisker (the panel plugin) uses Python, and I believe Orage does as well.
https://wiki.xfce.org/dev/howto/panel_plugins


Query segmentation with spell check

Question: Assuming I have a fixed list of multi word names like:
Water
Tocopherol (Vitamin E)
Vitamin D
PEG-60 Hydrogenated Castor Oil
I want the following input/output results:

Water, PEG-60 Hydrogenated Castor Oil -> Water, PEG-60 Hydrogenated Castor Oil
PEG-60 Hydrnated Castor Oil -> PEG-60 Hydrogenated Castor Oil
wter PEG-60 Hydrnated Castor Oil -> Water, PEG-60 Hydrogenated Castor Oil
Vitamin E -> Tocopherol (Vitamin E)

I need it to be performant and the ability to recognize that either there are too many close matches and no close matches. With 1 its relatively easy because I can separate by the comma. Most times the input list is separated by the comma so this works 80% of the time but even this has the small issue. Take for example 4. Once separated, 4's ideal match is not returned by most spellcheck libraries (I've tried a number) because the edit distance to Vitamin D is much smaller. There are some websites that do this well but I'm lost as to how to do it.
The second part to this problem is, how do I do word segmentation on top. Let's say a given list doesn't have a comma, I need to be able to recognize that. Simplest example being Water Vtamin D should become Water, Vitamin D. I can give a ton of examples but I think this gives a good idea of the problem.
Here's a list of names that can be used.
Comment: Given the subject matter do you have a moderately long list of words/phrases that you are dealing with?
Comment: Yea I have a list of about 5000 names
Comment: Do you have like the code and and example for us to use?
Comment: I don't have any code - I was playing around with this earlier using spellcheck libraries available on python (tried a number of them). I'm looking more for for of an approach/algorithm/idea on how this can be solved. Because standard spellcheck relies heavily on edit distance, I need something else, and I don't know what options are out there.
Comment: For a working example see https://www.skincarisma.com/ingredient-analyzer. All my examples work there except the one without the comma. Here's one that solves the one without the comma: https://incidecoder.com/decode-inci
Answer: Context
This is a case of approximate string matching or fuzzy matching. There is good materials and libraries about that.
There are different libraries and ways to cover this. I will restrict to relatively simple libraries
Some cool libraries:
from fuzzywuzzy import process
import pandas as pd
import string

First Part
Let's place the data to play around. I try to reproduce the above example, hope it is fine.
# Set up dataframe
d = {'originals': [["Water","PEG-60 Hydrogenated Castor Oil"],
                   ["PEG-60 Hydrnated Castor Oil"],
                   ["wter"," PEG-60 Hydrnated Castor Oil"],
                   ['Vitamin E']],
     'correct': [["Water","PEG-60 Hydrogenated Castor Oil"],
                 ["PEG-60 Hydrogenated Castor Oil"],
                 ['Water', 'PEG-60 Hydrogenated Castor Oil'],
                 ['Tocopherol (Vitamin E)']]}
df = pd.DataFrame(data=d)
print(df)
                                 originals                                  correct
0  [Water, PEG-60 Hydrogenated Castor Oil]  [Water, PEG-60 Hydrogenated Castor Oil]
1            [PEG-60 Hydrnated Castor Oil]         [PEG-60 Hydrogenated Castor Oil]
2     [wter,  PEG-60 Hydrnated Castor Oil]  [Water, PEG-60 Hydrogenated Castor Oil]
3                              [Vitamin E]                 [Tocopherol (Vitamin E)]

From the above we have the statement of the problem: we have some original wording and want to change it.
Which are the correct options for us:
strOptions = ['Water', "Tocopherol (Vitamin E)",
             "Vitamin D", "PEG-60 Hydrogenated Castor Oil"]

This functions are going to help us. I try to document them well.
def function_proximity(str2Match,strOptions):
    """
    This function help to get the first guess by similiarity.

    paramters
    ---------
    str2Match: string. The string to match.
    strOptions: list of strings. Those are the possibilities to match.
    """
    highest = process.extractOne(str2Match,strOptions)
    return highest[0]
def check_strings(x, strOptions):
    """
    Takes a list of string and give you a list of string best matched.
    :param x: list of string to link / matched
    :param strOptions:
    :return: list of string matched
    """
    list_results = []
    for i in x:
        i=str(i)
        list_results.append(function_proximity(i,strOptions))
    return list_results

Let's apply to the dataframe:
df['solutions_1'] = df['originals'].apply(lambda x: check_strings(x, strOptions))

Let's check the results, by comparing the columns.
print(df['solutions_1'] == df['correct'])
0    True
1    True
2    True
3    True
dtype: bool

As you can see the solution work in the four cases.
Second Part
Problem example solution:
You have Water Vtamin D should become Water, Vitamin D.
Let's create a list of valid words.
list_words = []
for i in strOptions:
    print(i.split(' '))
    list_words = list_words + i.split(' ')
# Lower case and remove punctionation
list_valid_words = []
for i in list_words:
    i = i.lower()
    list_valid_words.append(i.translate(str.maketrans('', '', string.punctuation)))
print(list_valid_words)
['water', 'tocopherol', 'vitamin', 'e', 'vitamin', 'd', 'peg60', 'hydrogenated', 'castor', 'oil']

That if the list of words that are valid.
def remove_puntuation_split(x):
    """
    This function remove puntuation and split the string into tokens.
    :param x: string
    :return: list of proper tokens
    """
    x = x.lower()
    # Remove all puntuation
    x = x.translate(str.maketrans('', '', string.punctuation))
    return x.split(' ')

tokens = remove_puntuation_split(x)
# Clean tokens
clean_tokens = [function_proximity(x,list_valid_words) for x in tokens]
# Matched tokens with proper selection
tokens_clasified = [function_proximity(x,strOptions) for x in tokens]
# Removed repeated
tokens_clasified =  list(set(tokens_clasified))
print(tokens_clasified)
['Vitamin D', 'Water']

That is as required initially.
However those could fail a bit, particularly when Vitamin E and D are combined.
References

https://www.datacamp.com/community/tutorials/fuzzy-string-python
https://pbpython.com/record-linking.html
https://pbpython.com/record-linking.html
Comment: Thank you for the detailed answer, but unfortunately it breaks down rather quickly with a large dataset. Here's a list of ingredients https://pastebin.com/QXabQXWP. With that list the output is "['tocopheryl acetate (vitamin e)', 'ceramide', 'water']".
Comment: What do you mean breaks? in terms of time? a wrong answer?
Comment: Yea. Given the input "Water Vtamin D" the answers are somewhat unrelated. (['tocopheryl acetate (vitamin e)', 'ceramide', 'water'])
Comment: There were two parts, one separated by commas and another not separated by comma, what above I called "Second Part". In that part that particular case is considered, providing results ['Vitamin D', 'Water'].
Comment: Did you try it with the entire list? With the entire list I get `(['tocopheryl acetate (vitamin e)', 'ceramide', 'water'])`. Also it seems like you are using a set which basically hides a symptom of problem. Ideally we should not be getting any repeats unless there is a repeat of the ingredient itself in a misspelled way. This becomes clear when you start using the full list.
Comment: I used the cases mentioned in the original question. To use a longer list could be ok, but it possible that other consideration need to be included, such as parallelization of the process or use spark instead of python.
Comment: Yea, I should have posted the list from the beginning but have now included it in the question. With a very small list your algorithm works, but once it gets slightly larger (>100) it doesn't produce the desired result. Parallelization doesn't really help with anything here since speed is not the issue.
Answer: This answer builds upon @Rafaels answer.

process.extractOne in FuzzyWuzzy uses the scorer fuzz.WRatio by default. This is a combination of multiple scorers provided by FuzzyWuzzy, that works well for the dataset Seatgeek is working with. So you might want to try around with other scorers to see which one performs best for you. However note, that quite a few of your elements might be hard to distinguish using the edit distance. E.g. Vitamin E <-> Vitamin D only need a single edit, even though they are something completely different. The same behavior also occurs with glycereth-7

FuzzyWuzzy is relatively slow, so when your working with a bigger dataset you might want to use RapidFuzz instead (I am the author) which provides similar algorithms, but has a better performance.

process.extractOne preprocesses the input strings by default (lowercases and replaces non alphanumeric characters with whitespaces). Since your probably searching for elements multiple times it would make sense to preprocess the possible choices once ahead of time and deactivate this behavior to safe some time:

process.extractOne(str2Match,strOptions, processor=None)

Differences between RapidFuzz and FuzzyWuzzy
Since you reported differences in the results between RapidFuzz and FuzzyWuzzy here are some possible reasons:

I do not round results. So you wil get a floating point like 42.22 instead of 42 as a result
In case your not using the fast FuzzyWuzzy implementation, that uses python-Levenshtein you might get different results, since it uses difflib which is a different metric. It produces very similar results most of the time but not always
In case your using the fast implementation any partial ratio like partial_ratio, WRatio ... might return wrong results in FuzzyWuzzy since partial_ratio is broken (see here)
Passing processor=None to extract/extractOne has a different meaning in RapidFuzz and FuzzyWuzzy. In RapidFuzz it will deactivate preprocessing, while in FuzzyWuzzy it will still use the default of the score. As an example for

extract(..., scorer=fuzz.WRatio, processor=None)

FuzzyWuzzy will still preprocess the strings inside WRatio, so there is no way to deactivate preprocessing. I personally think this is a bad design, so I changed it to give the user the possibility to deactivate the processor, which is likely what you want to achieve when passing processor=None
Comment: Thanks for your answer. I was able to fix the `Vitamin E` issue using an algorithm (see my answer). I did notice that fuzzyfuzzy is relatively slow. Thanks for the two tips. Do you have any pointers as to how I can go about try to separate out words like `wter PEG-60 Hydrnated Castor Oil`. The posted algorithm works for only one extraction.
Comment: Also, when I added `, processor=None`, it works fine on fuzzywuzzy but not yours. I preprocessed by only lower casing it, since symbols are somewhat important here. Without `, processor=None`, I get 0.0420 sec per lookup on fuzzywuzzy and 0.0036 on yours, which is crazy. Thank you so much!
Comment: I added differences between RapidFuzz and FuzzyWuzzy to my answer. Some are things I changed, because I did not find them very user friendly and some are bugs in FuzzyWuzzy (Should probably add this as a section to my documentation). Other things might very well be bugs on my side ;)
Comment: Thank you for the update. As for segmentation on top of this, do you have any pointers as to how I can go about it? I feel like correction makes segmentation significantly harder.
Answer: I copy and paste the list from https://pastebin.com/QXabQXWP in file list_terms_v3.txt.
"""

References
https://github.com/seatgeek/fuzzywuzzy
https://www.datacamp.com/community/tutorials/fuzzy-string-python

Questions Stackoverflow: https://stackoverflow.com/questions/65844582/query-segmentation-with-spell-check

"""

from fuzzywuzzy import process
from fuzzywuzzy import fuzz
import pandas as pd
import string

#strOptions = ['Water', "Tocopherol (Vitamin E)",
#             "Vitamin D", "PEG-60 Hydrogenated Castor Oil"]
strOptions = pd.read_csv("list_terms_v3.txt", sep='\n', header=None)
strOptions = strOptions[0].tolist()
print(strOptions.__len__())

"""
Create a list of key workds
"""
list_words = []
for i in strOptions:
    print(i.split(' '))
    list_words = list_words + i.split(' ')
# Lower case and remove punctionation
list_valid_words = []
for i in list_words:
    i = i.lower()
    list_valid_words.append(i.translate(str.maketrans('', '', string.punctuation)))

def function_proximity(str2Match,strOptions = strOptions):
    """
    This function help to get the first guess by similiarity.

    paramters
    ---------
    str2Match: string. The string to match.
    strOptions: list of strings. Those are the possibilities to match.
    """
    highest = process.extractOne(str2Match,strOptions)
    return highest[0]
def check_strings(x, strOptions):
    """
    Takes a list of string and give you a list of string best matched.
    :param x: list of string to link / matched
    :param strOptions:
    :return: list of string matched
    """
    list_results = []
    for i in x:
        i=str(i)
        list_results.append(function_proximity(i))
    return list_results

"""
2 Option
"""

def remove_puntuation_split(x):
    """
    This function remove puntuation and split the string into tokens.
    :param x: string
    :return: list of proper tokens
    """
    x = x.lower()
    # Remove all puntuation
    x = x.translate(str.maketrans('', '', string.punctuation))
    return x.split(' ')

def clean_tokens_funct(x, strOptions=strOptions):
    if x in strOptions:
        return x
    else:
        return function_proximity(x,strOptions=strOptions)

def searcher(x):
    tokens = remove_puntuation_split(x)
    clean_tokens = [clean_tokens_funct(x, strOptions=list_valid_words) for x in tokens]
    # Matched tokens with proper selection
    tokens_clasified = [function_proximity(x,strOptions=strOptions) for x in tokens]
    # Removed repeated
    tokens_clasified =  list(set(tokens_clasified))
    return tokens_clasified

Up to here everything fine, to check:
x = "Water Vtamin E"
print(searcher(x))
['Tocopheryl Acetate (Vitamin E)', 'Water']

However previous could file in some cases. The problem is that Vitamin D does not appear in the list, but if added everything should be fine.
x = "Water Vtamin D"
print(searcher(x))
['Tocopheryl Acetate (Vitamin E)', 'Ceramide', 'Water']

Or another case for problem:
x = "Water  D"
print(searcher(x))
['Ceramide', 'Water']

In case you just want to compare with the list you have then use  function_proximity
x = 'Actinidia Chinensis Fruit'
print(function_proximity(x))
Luffa Cylindrica Fruit/Leaf/Stem Extract

x = 'Nelumbo Nucifera Callus Culture'
print(function_proximity(x))
Nelumbo Nucifera Callus Culture Extract

Comment: Also when you give it things like `Actinidia Chinensis Fruit` it just repeats itself. Or even `Nelumbo Nucifera Callus Culture`, using your solution, gives two incorrect results `['Nelumbo Nucifera Germ Extract\n', 'Leontopodium Alpinum Callus Culture Extract\n']` when infact it's just missing one word `extract`. The solution I posted above covers all these cases including the ones you posted (mine automatically ignores the vitamin D instead of trying to find something for it)
Comment: As an aside note, you don't need to mess around with pandas just to read a simple line by line file. For your code, you could have just done this and avoided 2 separate loops and much cleaner code:
`
for line in open('ingredients_list.txt').readlines():
    strOptions.append(line)
    list_words = list_words + line.split(' ')`
Answer: I expanded on the other answers to make it work on the provided list. It's sort of an algorithm using fuzzywuzzy and seems to work for a case like vitamin e.
def merge_scores(text, matches, match_func):
    new_scores = []
    for match in matches:
        new_scores.append((match[0], (match[1] + match_func(match[0], text)) / 2))
    return sorted(new_scores, key=lambda m:m[1], reverse=True)

def get_best_match(text):
    fuzz_matches = process.extractBests(text, INGREDIENTS, limit=10, scorer=fuzz.ratio)
    if fuzz_matches[0][1] < 80 or fuzz_matches[0][1] == fuzz_matches[1][1]:
        fuzz_matches = process.extractBests(text, INGREDIENTS, limit=10, scorer=fuzz.token_set_ratio)
        # Combine only if the top 5 aren't perfect matches
        if fuzz_matches[4][1] != 100:
            fuzz_matches = merge_scores(text, fuzz_matches, fuzz.ratio)
    if fuzz_matches[0][1] == fuzz_matches[1][1]:
        fuzz_matches = process.extractBests(text, INGREDIENTS, limit=10, scorer=fuzz.WRatio)
    if fuzz_matches[0][1] == fuzz_matches[1][1]:
        return '', 0
    return fuzz_matches[0]

Query segmentation with spell check


When do Adaptive Optimization Algorithms modify their parameters?

Question: When do "Ada" optimizers (e.g. Adagrad, Adam, etc...) "adapt" their parameters? Is it at the end of each mini-batch or epoch?
Answer: They update their parameters after each mini-batch. (I use this term to avoid confusion with "batch gradient descent"; most neural network libraries talk about a 'batch size' when they mean 'minibatch size'.)
To help remember this: The optimizer has no notion of an 'epoch'. For instance, for stochastic gradient descent, you could sample randomly from the dataset at every time step (rather than the common shuffle-and-iterate strategy) and it'll still work. (It's your job to define the training curriculum, not the optimizer's.)
In that case, there's no clearly defined 'epoch'. Everything is in terms of which mini-batch the optimizer processes.
Comment: Yes, I meant mini-batch, editing question now. It makes sense, in documentation I sometimes read "after each gradient update" and that happens after processing a mini-batch.


If I do a PCA on centered only variables (of the same unit), does it mean that the principal components created expresses themselves with that unit?

Question: This question might look very trivial, but PCA is still nebulous to me.
If I have a set of individuals described by 10 variables: $A, B, C, D, E, F, G, H, I, J$, all quantitative and having the same unit (let's say: Euro),
If I choose to only center them,
and ask my PCA to find two components, and that it creates two axes:

$PC_1$ summarizing $A, B$, for example,
$PC_2$ summarizing $E, F, J$

does it mean that $PC_1$ unit is euro/euro
and $PC_2$ is euro/euro/euro?
Answer: Principle components are linear combinations of the original variables. The first one has the largest variance, the next has the second largest, and so on, subject to a fixed constraint on each set of coefficients.
If all the variables are measured on the same scale then the resulting linear combinations have that scale also.
If we were to do a PCA on the size measurements of mammals, say length, width, and height, all measured on the single scale of centimeters, then the resulting components are also centimeters. If we add another scale, say weight in kilograms, then the components are a mix of different measuring systems and we can't assign a standard measure to, for example, the first component. All we can do is call it "size."
Most people don't care since there measurements might be on several different scales.
Comment: Thanks! I have also to figure that having a principle component in the same unit than the original variables doesn't mean that the value of this principle component has a meaning: if I'm 1m80 tall, have a bike of 1.10m height and a chair of $0.9m$ height, a $PC_1$ could be $1.32m$, but if someone ask me: "_1.32m is height of what?_", I will be in trouble to respond. It's a new variable, having an unit of measure... But measuring nothing [I mean: nothing you can easily and clearly explain to someone].


Let $f$ be a continuous function on $\mathbb{R}$ satisfying $\int_\mathbb{R}|f(x)|dx<\infty$. Can we conclude that $\sum_\mathbb{Z}|f(k)|<\infty$?

Question: Let $f$ be a continuous function on $\mathbb{R}$ satisfying
$$\int_\mathbb{R}|f(x)|dx<\infty.$$
Can we conclude that
$$\sum_\mathbb{Z}|f(k)|<\infty?$$
Note: Continuity is necessary otherwise $f=\chi_\mathbb{Z}$ would give counterexample.
Answer: No; having finite integral does not impose what $f$ has to behave like on the integers (a set of measure zero). To give a smooth counterexample, we just want to "smooth out" your $\chi_{\mathbb{Z}}$ example. Let $\phi$ be a smooth bump function on $\mathbb{R}$ with compact support in $(-1/2, 1/2)$, with $\phi(0) = 1$, and with $\int_{-1}^1 \phi(x)\, dx = 1$. Define $\phi_n(x) = \phi(n^2(x - n))$. These are narrow versions of $\phi$. They are supporte in the interval $(n - 1/2n^2, n + 1/2n^2)$. Then set
$$
f(x) = \sum_{n \in \mathbb{Z}} \phi_n(x).
$$
Note that for each $x$, the sum is actually finite since the supports of $\phi_n$ are all disjoint.
Then $f(n) = 1$ for each $n \in \mathbb{Z}$ so certainly the sum over the integers isn't finite. However we can compute that
$$
\int_{\mathbb{R}} \phi_n(x) \, dx = n^{-2}\int_{\mathbb{R}}\phi(y) dy = n^{-2}
$$
and thus
$$
\int_{\mathbb{R}} f(x) \, dx = \sum_{n \in \mathbb{Z}}\int_{\mathbb{R}} \phi_n(x)\, dx = \sum_{n \in \mathbb{Z}} \frac{1}{n^2} < \infty.
$$
To get your desired conclusion from the hypotheses, we'd have to suppose some monotonicity on $|f(x)|$, I believe.
Comment: @SantanuDebnath Not true. You can modify the above example to construct a smooth $f$ consisting of a sum of smooth bump functions, where the bump function centered at $x=n$ (where $n$ runs over all nonzero integers) has height $1/|n|$ and area $1/n^2$ and is supported on $[n-1/2, n+1/2]$, and so $\sum f(n) = \sum 1/|n| = \infty$ but $\int f(x)\ dx = \sum 1/n^2 < \infty$.
Comment: I guess if we assume that $f\in C_0,$ space of continuous function vanishing at $\infty,$ the conclusion will hold true.
Comment: @SantanuDebnath it's as Bungo says. The takeaway is that merely enforcing that $f$ has a finite integral is a very very "light" restriction. It's honestly in some ways better to think of "hand drawn" examples to get some intuition, rather than worrying about the formal description in my answer.
Answer: Let $t(x) = \max(0,1-|x|)$. Then $\int t = 1$ and $t(0) = 1$.
Then let $\phi(t) = \sum_n t(n^2(x-n))$. Then $\int \phi = \sum_n {1 \over n^2}$
but $\phi(n) = 1$ for all $n$, so $\sum_n \phi(n) = \infty$.
Note, with $\eta(t) = \sum_n {1 \over n}t(n(x-n))$ we have $\int \eta = \sum_n {1 \over n^2}$ and $\eta(n) = {1 \over n}$ so
$\sum_n \eta(n) = \infty$ and $\eta \in C_0$.
Comment: If you have a specific question about my answer please let me know and I will endeavour to answer it. I have already indicated how to modify $\eta$ (just add $x \mapsto e^{-|x|}$). I don't know what you are asking about Cauchy-Maclaurin but it sounds like a different question to me.
Comment: I guess if we assume that $f\in C_0,$ space of continuous function vanishing at $\infty$ the conclusion will hold true.
Comment: No, see the counterexample above.
Comment: Sure it is, $\eta(x) \to 0$ as $|x| \to \infty$.
Comment: Yes you right. I was thinking about the other counterexample. Thanks
Comment: Sorry to bother you. I went through Cauchy-Maclaurin integral test which says that if $f$ is monotone decreasing and positive then $\int_1^\infty f(x)dx$ and $\sum_1^\infty f(n)$ converge or diverge together. That led me to ask that if in my question, I assume that $f$ is positive, will that make the above result positive?
Comment: That is, if $f$ is continuous and non-zero then can we say that $$\int_\mathbb{R}|f(x)|dx<\infty\implies \sum_\mathbb{Z}|f(n)|<\infty ?$$
Comment: The above are not monotone  so I am not sure what the relevance is there. Clearly you can add a positive integrable function to the above to make it strictly positive but the same conclusion holds.
Comment: The issue is that the summation only focuses on the value at specific points whereas the integral doesn't care about values at single points.
Comment: I may make no sense but I am raising this question because of two facts:  (1) In ur counterexample, zero set of $\eta$ is very much big and we can't modify that function to be positive (non-zero) and still works good as a counter example. (2) It would be nice to study if we replace monotone decreasing by continuity and proof a one-sided implication related to Cauchy-Maclaurin.
Comment: Thanks. That answer my doubt.
Answer: In measure theoretic point of view, consider measure space $(\Omega, \mathcal{F}, \mu)$ and consider a $\mu$-measurable function $f$.
Now consider,
$$
\int f d\mu
$$
In your case you take first $\mu=\lambda$, Lebesgue measure and then in your second case you take $\mu$ as a counting measure, say $\mu'$. But your $\Omega$ is same in both cases.
Now consider $\Omega = [0,1]$ then $\lambda(\Omega)<\infty$ but $\mu'(\Omega)=\infty$. that become problematic, to conclude about summability.


Application of Baire Category theorem in $C[0,1]$

Question: Let $f_n\in C[0, 1]$. Assume that for every $x\in [0, 1]$ there exists a finite limit $f(x) = \lim f_n(x)$. Apply the Baire category theorem to the sets
$$ A_n = \{x : |f_m(x) - f_n(x)| \leq \frac{1}{3} ,  \forall m > n\}$$
to prove that f cannot be the salt and pepper function
$$\left\{\begin{matrix}
1 & \text{if} \ x \in \mathbb{Q} \\
0 & \text{otherwise}
\end{matrix}\right.$$
I have to show that the metric space $C[0, 1]$  cannot be written as the countable union of closed , no where dense sets. So the set $A_n$ as given must be proven that is closed , nowhere dense.  Right? (I don't know how to approach any of these requirements)
how to show the second part?
Also the function g is not continuous, so it does not belong to $C[0,1]$. What is the role of it in the question?
Comment: Application of Baire: The sets $A_n$ are closed and $\bigcup_nA_n = [0,1]$. Hence, there is $n_0$ such that $A_{n_0}$ has non-empty interior.
Comment: @Masacroso Note that $f_n\to f$ pointwise!
Comment: what is the norm that youa re using in $C[0,1]$?
Comment: @Masacroso If nothing else is said $C[0,1]$ always is equipped with the infinity-norm.
Comment: @amsmath but then the exercise is trivial because $C[0,1]$ is complete, and then it is not possible that the Dirichlet function is a limit of some Cauchy sequence in $C[0,1]$
Comment: @stat_yale Can you use my hint? It means that there is a subinterval $I\subset [0,1]$ on which $f$ differs only by maximally $1/3$ from some fixed (continuous) $f_n$.
Comment: @amsmath , no actually, I did not get your hint for showing nowhere dense part. Also , how about showing that $C[0,1]$, cannot be written as the countable of those?
Comment: @stat_yale because $C[0,1]$ is complete with the supremum norm
Answer: We have $A_n = \bigcap_{m>n}(f_n-f_m)^{-1}([-1/3,1/3])$, and hence $A_n$ is closed for each $n$. Moreover, for each $x\in [0,1]$, as $(f_n(x))_{n\in\mathbb N}$ is a Cauchy sequence for each $x$, there exists $n$ such that $x\in A_n$. So, $\bigcup_nA_n = [0,1]$. By Baire's theorem, there exists $n_0$ such that $A_{n_0}$ has a non-empty interior; so, there exists an open interval $I\subset A_{n_0}$. Thus, for $x\in I$ we have $|f_m(x)-f_{n_0}(x)|\le 1/3$ for all $m>n_0$. In particular (letting $m\to\infty$),
$$
|f(x)-f_{n_0}(x)|\le 1/3\quad\text{for all $m>n_0$ and all $x\in I$.}
$$
Now, choose $x_0\in I$ irrational. Assume that $f(x_0) = 0$. That means that $f_{n_0}(x_0)\in [-1/3,1/3]$. Because $f_{n_0}$ is continuous, for $x$ in a neighborhood $J$ of $x_0$ we have $f_{n_0}(x)\in (-2/3,2/3)$. Choose some rational $x_1\in J$. Then
$$
|f(x_1)|\le|f(x_1)-f_{n_0}(x_1)|+|f_{n_0}(x_1)| < 1/3+2/3 = 1,
$$
so $f(x_1)\neq 1$. So, $f$ cannot be the salt-and-pepper function.
Comment: Two questions; 1) why we want to write $\bigcup_nA_n = [0,1]$? This gives us what? 2) I also did not understand this part; each $x\in[0,1]$, as $\{f_n(x)\}_{n∈N}$ is a Cauchy sequence for each x, there exists n such that $x\in A_n$. gives, $\bigcup_nA_n = [0,1]$.
Comment: (1) It gives us that one of the sets has non-empty interior. (2) Well, let $x\in [0,1]$ be arbitrary. Then $(f_n(x))_n$ is a Cauchy sequence. Thus, there exists $n$ such that for all $m,k\ge n$ we have $|f_k(x)-f_m(x)|\le 1/3$. In particular, $|f_n(x)-f_m(x)|\le 1/3$ holds for all $m>n$. So, $x\in A_n$.


counting tuples in $\mathbb Z^{i}$

Question: Let $d$ be a positive integer, let $\mathbb N$ denote $\{1,2,\dots\}$. What is the size of the following subset of $\mathbb Z^{i}$?
$$
\{ (a_1, \dots, a_i) : a_j \in \mathbb N, \text{ and } a_1 + \dots + a_i \leq d \}.
$$
Answer: Instead of summing the solutions to $a_1+\cdots+a_i=k$ (or $k=i$) to $d$, you may find it easier to argue like this. Add a dummy variable $a_{i+1}$ restricted to the same set as the other variables. Then the number of solutions to $a_1+\cdots+a_i\le d$ is the same as the number of solutions to $a_1+\cdots+a_i+a_{i+1}=d+1$, i.e. $$\binom{d}{i}.$$
Answer: First we should talk about the number of tuples with $a_1 + a_2 + \cdots + a_i = d$.
This is a well-known problem; it is the number of ordered partitions of $d$ into $i$ parts, and it is given by ${d-1} \choose {i-1}$.  You should be able to find extensive explanation of of this fact here on mathSE.
To get the number of tuples with $a_1 + a_2 + \cdots + a_i \le d$, we should just add up the number of tuples with $a_1 + \cdots + a_i = k$ for $k = i$ to $k = d$.  That is, we should compute
$$
\sum_{k = i}^{d} {{k-1} \choose {i-1}}
$$
which evaluates to ${d} \choose {i}$ by the hockey-stick identity.

counting tuples in $\mathbb Z^{i}$


HELP ME com Condição If numa MaskedTextBox

Question: Gente, eu sei que esse site é bem famoso porque a comunidade é SUPER caridosa e gentil.
Me ajudem com essa: eu não to conseguindo fazer com que um MessageBox seja exibido quando eu deixo a minha MaskedTextBox em branco. Eu formatei ela para ficar no padrão de CPF 123.456.789-00 Tô fazendo um formulário pra cadastro. Eu sei fazer pra TextBox normal, mas pra MaskedtTextBox não funciona. O código tá assim:
<code>if(txtNome.Text == "")
            {
                MessageBox.Show("Preencha o campo Nome!", "Falta de informação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if(txtCpf.Text == "") // <- Essa é a MaskedTextBox
            {
                MessageBox.Show("Preencha o campo CPF!", "Falta de informação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
</code>
Comment: o segredo é como vc faz a pergunta... tudo que digitou aí poderia ser apenas "maskedtextbox is empty", e então: https://stackoverflow.com/a/17757922/4713574
Comment: Muito obrigado, Rovann. Salvou minha noite, cara! Deus te abençoe :D
Answer: Tem vários jeitos de verificar se está uma MaskedTextbox está ou não vazia.
Segue o código abaixo que verifica sem erro.
<code>            if (maskedTextBox1.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("Preencha o campo CPF!", "Falta de informação", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
</code>