LogFormat apache 2.4 not work

Question: I'm trying to configure mod_remoteip in apache2.4 with proxy squid in a separate server but the IP in the access.log remains the IP of the proxy.
I use this https://trick77.com/apache2-2-4-logging-remote-ip-address-using-mod_remoteip/
In fact, I have found that in the /etc/apache2/apache2.conf, the command
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

don't change the format of the access.log even I change the text or remove it.
Someone can help ?
Answer: I found that using the nickname combined doesn't work since it is already taken. So this works:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" %D"myawesomeformat
CustomLog ${APACHE_LOG_DIR}/access.logmyawesomeformat
Comment: Took me an hour to find out. Bloody apache doesn't even issue a warning. Pulling my hair...
Answer: LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat creates only "nickname" for log format. Actually used format is defined by
CustomLog ${APACHE_LOG_DIR}/access.log combined

CustomLog which defines where and in which format the log is stored.
Comment: Not clear. I see the access.log but why doesn't it take the change i made in LogFormat, for example if i change the order of 2 parameters ?
Comment: There are more `LogFormat` lines in the config. And there might be more `CustomLog` entries. Search for them in your config. You need to pair them together AND of course restart your apache2 service, if you didn't do so.
Comment: thanks. I see 5 LogFormat and no CustomLog in /etc/apache2/apache2.conf . I see CustomLog here "apache2/sites-available/000-default.conf" but nothing in any vhost conf here "apache2/sites-available/"
Comment: Did it solve your problem already? It is not obvious from your last comment.
Comment: I have an access.log for each vhost but any change i do in the LogFormat doesn't change the format of this access.log because maybe there is no CustomLog associated with this and it takes the defaut one ?? Where should I put this CustomLog ?
Comment: of course, i restarted apache after each change

LogFormat apache 2.4 not work


Make a from element visible when a radio button is clicked

Question: I have a problem to make a date and a list element in a form in HTML invisible if the user selects one way, and visible if the user selects two. How can I write the JavaScript code for that?
Answer: No need to write JavaScript for that; if you are working in PHP, you can use #states on the form element.
Example: form_example_states_form.
<code>  $form['high_school'] = array(
    '#type' => 'fieldset',
    '#title' => t('High School Information'),

    // This #states rule says that the "high school" fieldset should only
    // be shown if the "student_type" form element is set to "High School".
    '#states' => array(
      'visible' => array(
        ':input[name="student_type"]' => array('value' => 'high_school'),
      ),
    ),
  );
</code>
Comment: but how if i'm using radio button to select.Does the same code can be used in php??
Comment: Yes, as written in the doc link above, #states can be used with any form element
Comment: with the secret santa knowledge that `#states` is really emitting some simple jquery to show/hide stuff site since the action => condition array is just basically jquery selectors. A useful brief tutorial is at http://randyfay.com/states
Comment: tq very much @DavidThomas
Comment: tq also @tenken


If $z_1,z_2,z_3,z_4$ are consecutive vertices of a quadrilateral that lie on a circle prove the following

Question: If $z_1,z_2,z_3,z_4$ are consecutive vertices of a quadrilateral that lie on a circle prove the following: $|z_1-z_3||z_2-z_4|=|z_1-z_2||z_3-z_4|+|z_1-z_4||z_2-z_3|$. I know that you can prove this without using the cross-ratio, but I would like to complete this proof using it. Here are some things I know:

The cross-ratio is real if and only if $(z_1,z_2,z_3,z_4)$ lie on the same circle.
The cross-ratio is invariant under linear transformations, i.e. $(z_1,z_2,z_3,z_4)=(Tz_1,Tz_2,Tz_3,Tz_4)$.

I am not sure if (2) will be of any use, but I definitely think (1) would be helpful. Using (1) I can only get as far as: $|z_1-z_3||z_2-z_4|=C|z_1-z_4||z_2-z_3|$, where $C \geq 0$.
Any help is appreciated.
Edit: After playing with the equation for a while this is what I concluded: Of course by simple verification, one indeed finds that $(z_1-z_3)(z_2-z_4)=(z_1-z_2)(z_3-z_4)+(z_1-z_4)(z_2-z_3)$. Then we have $$\frac{(z_1-z_3)(z_2-z_4)}{(z_1-z_4)(z_2-z_3)}=\frac{(z_1-z_2)(z_3-z_4)}{(z_1-z_4)(z_2-z_3)}+1.$$ Now our result is proven if we can show that both of these quotients are real and positive. Well, the real part follows from the fact that a cross-ratio is real if and only if all four points lie on the same circle. Now for the positive part: The quotient on the left is the cross ratio $(z_1,z_2,z_3,z_4)$ where $z_2 \rightarrow 1$, $z_3 \rightarrow 0$, $z_4 \rightarrow \infty$. Now this transformation, which is bijective, takes the circle that passes through these points to the real line. Therefore the arc from $z_4$ to $z_2$ is taken to $[-\infty,1]$, hence $(z_1,z_2,z_3,z_4) > 1$. A similar argument works to show that the other cross-ratio is also positive.
Is this reasoning correct? I guess we use the fact that continuous functions take connected sets to connected sets, so the image of these arcs must be connected.
Comment: [This is ptolemy's theorem](https://math.stackexchange.com/a/3995818/688539) I've written a proof in linked using inversion (fully self contained)
Comment: Btw what is cross ratio?
Comment: @Buraian: https://en.wikipedia.org/wiki/Cross-ratio#Definition.
Answer: Your reasoning is correct. You have demonstrated that
$$
\frac{(z_1-z_3)(z_2-z_4)}{(z_1-z_4)(z_2-z_3)}=\frac{(z_1-z_2)(z_3-z_4)}{(z_1-z_4)(z_2-z_3)}+1
$$
and the quotient on the left is $> 1$. That implies that the quotient on the right is $> 0$. Therefore  all expressions are positive, and it follows that
$$
\left|\frac{(z_1-z_3)(z_2-z_4)}{(z_1-z_4)(z_2-z_3)}\right|=\left|\frac{(z_1-z_2)(z_3-z_4)}{(z_1-z_4)(z_2-z_3)}\right|+1 \, .
$$
Instead of a connectedness argument you can also use that Möbius transformation preserve orientation: The quotient on the left is equal to $T(z_1)$ where $T$ is the Möbius transformation which maps $z_2, z_3, z_4$ to $1, 0, \infty$, respectively. $z_1,z_2,z_3,z_4$ are consecutive points on a circle. It follows that $T(z_1), 1, 0, \infty$ are consecutive points on the extended real axis (a generalized circle) and that is only possible if $T(z) > 1$.
Comment: If all expressions are positive, then how did the modulus thing equation follow?
Comment: @Buraian: If $a, b$ are positive with $a = b+1$ then $|a| = |b| +1$.
Comment: What if there is imaginary part in 'a' and 'b'?
Comment: @Buraian: There isn't. As OP already argued, the cross ratio is a real number because the four points lie on a circle. That is a fundamental property of the cross ratio.


my cUrl reliquishes control to the next statement before it's finished

Question: I'm running a script of commands (OSX) as follows
curl -o yahoo_IDJG.dwn http://ichart.finance.yahoo.com/table.csv?s=IDJG.AS&a=10&b=8&c=2015&g=d&ignore=.csv && sed -i -e 's/^/yahoo,IDJG,xams,/' yahoo_IDJG.dwn > yahoo_IDJG.csv;

or
curl -o yahoo_IDJG.dwn http://ichart.finance.yahoo.com/table.csv?s=IDJG.AS&a=10&b=8&c=2015&g=d&ignore=.csv;
sed -i -e 's/^/yahoo,IDJG,xams,/' yahoo_IDJG.dwn > yahoo_IDJG.csv;

unfortunately the sed starts before the curl is even finished. In fact all commands seem to start immediately.
I'm new to this so what haven't I understood ?
Thanks for you help.
Answer: The problem is that you miss the quotes, so :
curl -o yahoo_IDJG.dwn 'http://ichart.finance.yahoo.com/table.csv?s=IDJG.AS&a=10&b=8&c=2015&g=d&ignore=.csv'
sed -e 's/^/yahoo,IDJG,xams,/' yahoo_IDJG.dwn > yahoo_IDJG.csv

And when sed is used with -i switch, there's no output
Answer: First - note that the & tells your shell to run the given command in the background, then continue to the next line.  Therefore, your initial command is really running:
1 curl -o yahoo_IDJG.dwn http://ichart.finance.yahoo.com/table.csv?s=IDJG.AS&
2 a=10&
3 b=8&
4 c=2015&
5 g=d&
6 ignore=.csv;
7 sed -i -e 's/^/yahoo,IDJG,xams,/' yahoo_IDJG.dwn > yahoo_IDJG.csv;

So what's happening is that the shell is parsing the command as a series of "background" processes, split up according to the & character.  So, it

runs this in the background
assigns the shell variable $a to 10 (in the background)
assigns the shell variable $b to 8 (in the background)
assigns the shell variable $c to 2015 (in the background)
assigns the shell variable $g to d (in the background)
assigns the shell variable $ignore to .csv (not in the background, but that happens very quickly as shell variable assignment is reasonably quick).
finally, runs a sed command on the yahoo.IDJG.dwn file (though creates a backup of the file with a -e extension on the end - check the man page for sed on a mac or see the discussion on sed in-place flag that works both on Mac (BSD) and Linux) so you should have a yahoo.IDJG.dwn file (with the results of the sed command), a yahoo.IDG.dwn-e file (the original file), and (probably empty) yahoo.IDJG.csv file.  The solution is to enclose the entire URL in the curl command in single-quotes, and remove the -i from the sed command.

For reference, the man page for sed on a mac has the following:
-i extension
         Edit files in-place, saving backups with the specified extension.  If a zero-length extension is given, no backup will be saved.  It is not recom-
         mended to give a zero-length extension when in-place editing files, as you risk corruption or partial content in situations where disk space is
         exhausted, etc.

EDIT: forgot to post the real answer!:  Just enclose the URL in single quotes and remove the -i flag to the sed command:
curl -o yahoo_IDJG.dwn 'http://ichart.finance.yahoo.com/table.csv?s=IDJG.AS&a=10&b=8&c=2015&g=d&ignore=.csv' && sed -e 's/^/yahoo,IDJG,xams,/' yahoo_IDJG.dwn > yahoo_IDJG.csv;

EDIT: If you don't care about the intermediate yahoo_IDJG.dwn file, you can also just pipe the curl to the sed command:
curl -s 'http://ichart.finance.yahoo.com/table.csv?s=IDJG.AS&a=10&b=8&c=2015&g=d&ignore=.csv' | sed -e 's/^/yahoo,IDJG,xams,/' > yahoo_IDJG.csv;

When I ran that on command line, I got the same output in the .csv files.


How to see unpublishes content types In a view?

Question: I have a view which displays a list of unpublished content type "Nascholingen".
I use D8 + varbase + content access module
In super admin all goes good. I added a new rol called "lid". Logged in with this member the view does not display any result.
I did
- remove permissions on the view
- added all needed permissions on /permissions to edit this
- Access control for "Nascholingen" are set correctly.
- set priority of Content Access to 10
- Rebuild with drush cr
But whatever I do no results are displayed. grrr
Any suggestions? Is there a good way for debugging this?
Answer: This can be solved with the following module:
https://www.drupal.org/project/view_unpublished
After installation there are some new permissions in the permissions list which should be configurated and then unpublished items will be visible for the roles you configured.
Answer: $query = \Drupal::entityQuery('node');
  $query->condition('status', 0); // 0 CERO IS UNPUBLISHED
  $query->condition('type', 'CONTENT TYPE NAME');
  $entity_crop = $query->execute();
Comment: Not clear enough for me.


Need to understand why expressjs is redirecting to index.html

Question: I have the following server file, using express:
var express = require('express');
var app     = express();
var port    =   process.env.PORT || 8080;

app.listen(port);
console.log('Listening on port: ' + port);

// get an instance of router
var router = express.Router();
app.use('/', router);
app.use(express.static(__dirname + "/"));

// route middle-ware that will happen on every request
router.use(function(req, res, next) {
    // log each request to the console
    console.log(req.method, req.url + " logging all requests");
    // continue doing what we were doing and go to the route
    next();
});

// home page route for port 8080, gets executed when entering localhost:8080
// and redirects to index.html (correctly and as expected)
router.get('/', function(req, res) {
  console.log("routing from route")
  res.redirect('index.html');
});

 // This gets executed when my url is: http://localhost:8080/test
 // and redirects to index.html (the questions is why!? I thought
 // all the requests to root route would be caught by the router instance

app.get('*', function(req, res){
  console.log('redirecting to index.html');
  res.redirect('/index.html');
 });

Looking at the code above and my comments, I cannot understand why
app.get('*', function(){...})

does not get executed when URL is
localhost:8080/index.html but gets executed when URL is localhost:8080/test

Even though, this is the behavior that I was hoping for, I'm not sure why this works?

I don't have a "test.html" page in the root.
One other thing, the index.html does load other scripts, so I expected
app.get('*', function(){...})

to get executed for such get requests too, as it is supposed to be the catch all, but it does not.
Does app.use('/', router) mean that any route that has single character "/" should be handled by Router instance (as long as not a static file)? so "http:localhost:8080" gets interpreted as "http://localhost:8080/"?
I would appreciate any explanation.
Answer: This line-
app.use(express.static(__dirname + "/"));
will run first. It will see that index.html exists and serve that file statically.
Comment: Thank you for your response. Is my assumption regarding the second question correct: "Does app.use('/', router) mean that any route that has single character "/" should be handled by Router instance (as long as not a static file)? so "http:localhost:8080" gets interpreted as "http://localhost:8080/"?"


Repeated measures structural equation modeling

Question: I need to analyse a dataset of clinical rehabilitation data. I am interested in hypothesis-driven relationships between quantified "input" (amount of therapy) and changes in health status. Although the dataset is relatively small (n~70) we have repeated data reflecting temporal changes in both. I am familiar with non-linear mixed effects modelling in R however am interested in potential "causal" relationships between input and output here and thus am considering repeated measures applications of SEM
I'd appreciate advice on which if any of the SEM packages for R (sam, lavaan, openmx?) are best suited to repeated measures data, and particularly recommendations for textbooks (is there a "Pinheiro and Bates" of the field?).
Comment: Why do you think you need SEM, at all? If you heard the hype that SEM solve all causal problems, it is an overhype, only ideal randomized experiments do. See the reference I gave in my answer below.
Comment: When you say n~70, do you mean 70 patients measured over time, or 70 measurements (say 7 patients at 10 different times)? I'm just learning SEM, but one thing I've noticed so far is that it assumes large datasets (they talk of 200+ or more), so you might end up frustrating/fooling yourself.
Answer: I think you want a latent growth curve model. While I have only used LISREL for this, the lavaan package documentation indicates it can be used to fit this type of model.
I don't know of any books that specialise in this subject, the book I am working from for SEM covers a range of methods. Perhaps someone else can answer that aspect of your question.
Comment: (+1) Indeed, growth curve and mixture LV models are among some of the 'hot' topics in SEM or psychometrics; they are covered in some recent books, like *Latent Variable Mixture Models* (Hancock & Samuelsen, 2008). I have other papers on my TOBEREADFORTOOLONG list, and I would recommend looking at work from Múthen and coll., in conjunction with what the Mplus software offers for that [particular purpose](http://www.statmodel.com/discussion/messages/11/143.html?1327290364). If I find some time to reread the literature and compare `lavaan`/Mx to Mplus, I will post a reply myself.
Comment: That would be good, because I have only just learnt latent growth curve models, and they really are quite a unique model compared to other types of SEM.
Answer: No, there is no "Pinheiro and Bates". You can find a number of books titled like "SEM using AMOS/LISREL/Mplus", but I am not aware of any using R. The best book, mathematically speaking, on SEM is still Bollen (1989). It is written by a sociologist rather than a biostatistician (although a very good one!), and so is aimed at social scientists, and contains few references to software (and you don't want the software from quarter a century ago, anyway). Bollen has also co-authored a good paper recently on causality with Judea Pearl, see http://ftp.cs.ucla.edu/pub/stat_ser/r393.pdf. As far as I can tell, Mulaik (2009) should be good, too, but it is written by a psychologist for psychologists.
I don't think sem package is flexible enough to run this kind of stuff. OpenMx can deal with ordinal data (and hence binary outcomes), but I don't think lavaan can do this.
The software that you will conceptually find the easiest to deal with might be GLLAMM, a package written for Stata. Viewed one way, this is essentially a Stata incarnation of nlme. With an extra tweak (allowing the coefficients of the random effects vary according to values of other variables), it becomes a latent variable modeling package. This all is described in Skrondal and Rabe-Hesketh (2004)... which is a great book per se that you'd want to have even if you just do nlme.
Comment: (+1) Nice references. (About `gllamm`, viewed another way--from the perspective of a psychometrician used to IRT models: it's just horribly slow :-)
Comment: @chl, write your own likelihood ;). That's what I did with `polychoric`, for instance, when I needed it.
Answer: As you seem comfortable with generalized linear mixed models, and you don't seem to imply that you're interested in latent variables, perhaps you might want to take a piecewise approach using lmer which you can then evaluate using a D-Sep test.  See Shipley, B. (2009). Confirmatory path analysis in a generalized multilevel context. Ecology, Ecology, 90, 363–368.  http://dx.doi.org/10.1890/08-1034.1 for an example.  He also provides R code in the appendix for how to calculate the test of D-Separation.
If you really want to get into latent variable modeling and SEM using maximum likelihood, check out http://lavaan.org - there's a great tutorial there that covers its capabilities as well as a section on latent growth curve models which may well be what you're after.


Conducting music written in 6/8

Question: Can I get an illustration on how a choir master can conduct a piece of music written in 6/8 time? Thanks.
Comment: Like Tim  said, conducting in 2 is most common although there is a 6 pattern, it would have to be a slow tempo to conduct all those beats. Scroll down on this page to see it: https://courses.lumenlearning.com/musicappreciation_with_theory/chapter/conducting/
Answer: In conducting course I attended, we were taught four patterns. It depends on tempo and which beats are stressed.

If the tempo is fast and 1st and 4th beats are stressed, you conduct like 2/4 (on the stressed beats).
If the tempo is fast and 1st, 3rd and 5th beats are stressed, you conduct like 3/4 (on the stressed beats).
If the tempo is slow and 1st and 4th beats are stressed, you conduct every beat in this way: down (and outside), inside, inside, outside, outside, up.
If the tempo is slow and 1st, 3rd and 5th beats are stressed, you conduct every beat in this way: down (and inside), inside, outside, outside, inside (and slightly up), up. (It is like 3/4, but you make two beats in one direction.)

Of course, there are also different patterns, but for rare situations.
Comment: Isn't 6/8 time where the 1st, 3rd, and 5th beats are emphasized really 3/4 time?
Comment: I second this. If it isn't in two, it isn't 6/8.
Comment: @Dekkadeci Yes and no. Similarily I could ask, If 6/8 with 1st and 4th beats emphasised isn't really 2/4 with triplets. I assume you speak about fast tempo, because in slow tempo, 3/4 and 6/8 are different things.
If you conduct 6/8, it often happens that some beats are 1,4-emphasised and some 1,3,5-empasised. Consider main theme of America from West Side Story (https://youtu.be/JioV6kI316I?t=59). It is fast tempo and the stresses are constantly moving. You would conduct odd measures with the first pattern and even measures with the second pattern.
Comment: @VitHenych - "America" from *West Side Story* was probably always going to be a tough one to notate and conduct. If I'm not concerned with bringing out accents, I'd probably conduct strictly according to the sheet music. This often means not changing conducting patterns. (I've seen other questionably notated ensemble sheet music such as Michael Markowski's *Shadow Rituals*. That one has several measures notated as alternating 4/4 and 3/4 time that all recordings play as 7/8 time instead.)
Comment: @VitHenych - Regarding your "Similarily I could ask, If 6/8 with 1st and 4th beats emphasised isn't really 2/4 with triplets.", you could very well be right - I've actually seen the same music notated both ways, and in those cases, I'd truly play both of them the same way and not strongly question either notation upon listening to recordings. This is unlike "6/8 time" with beats 1, 3, and 5 emphasized - keep those beats emphasized for too many measures in a row and I'm likely to leave a comment on your piece asking you to re-notate the excerpt in 3/4 time.
Comment: @VitHenych - In fact, I could have sworn that I've seen music notated as 4/4 time with triplets that you could argue should be notated in 12/8 time instead. Looks like 6/8 is truly a notational convenience, while 4/4 time is so common that it might actually be debatable whether 4/4 time with triplets or 12/8 time is easier to read.
Comment: @Dekkadeci Well, I was taught, that conduct strictly according to the sheet music means actually changing the patterns, since it is how the author wrote the accents. But I guess that different teachers have different approaches. The thing is, you can actually find 3/4 music according to you, written like 6/8 however. And for this music, you use the second pattern (to make it 3/4). I think we agree to each other.
Answer: Since 6/8 is essentially two time, down up works just fine. Each movement will encompass three quavers, so instead of counting 1 2 3 4 5 6, the count will be 1(2 3) 2(2 3).
If it's incredibly slow, there could be an opportunity to count two lots of three, but that would be unusual.
Comment: The difference between conducting in one and in two is that in two, the hand or point of the baton crosses the imaginary line twice - once on the down stroke and again on the up stroke, and there's usually a kind of bounce or pause at the bottom. In one is more of a continuous motion and the beat is at the bottom of the stroke. There's a video of Leonard Bernstein demonstrating it on YouTube. Fast waltzes like the Blue Danube are often conducted in one.
Comment: Also if it's fast enough it could be conducted in one.
Comment: @ToddWilcox - condutors can't conduct in one, I believe. Their hand/arm needs to return to the top of the beat before the next downstroke! So isn't that two..?
Comment: @ToddWilcox - ah, that's what I envisaged when I wrote down up. Down = 1st beat, up = 2nd. So each bar used two movements, down, then up. So the last 'beat is an upbeat/upstroke, just like in 3/4 and 4/4 time.
Comment: Conducting in two and conducting in one are two different things. Maybe I'll find a link for you to look at later today. Conducting is based on a horizontal beat line. Each time the baton hits or crosses the line is a beat. In one the baton only touches the line once per measure and then goes back up. In two the baton hits the line on the downbeat and crosses it again on the upbeat.
Comment: @ToddWilcox - thanks for piquing my interest in conducting! It seems there are many ways that are used for conducting 6/8, really the only similarities being down is always 1, and the upbeat at bar's end is always shown with upward movement. I'll continue my foray into conducting...
Comment: It's not really Down-Up.  It's a low position 'click' then a high position one.   Think knocking on a door waist-height and then shoulder-height.  Sort of.  You can do a string of low knocks, lifting the arm in preparation for each.  That's one-in-the-bar conducting.  (Again, sort of.)  Conducting is more than elementary 'beating time'.
Comment: Conducting on one is not really recommended. It is usually much better to switch to conducting phrases and not measures. For example if every phrase consists of four 6/8 measures, you conduct like 4/4 with one swing for every measure. It is much clearer. However sometimes you cannot avoid conducting on one. (And it is a great tool, if you are lost during difficult polyphony. To change to one-beat conducting.)
Answer: In concert band, I've seen slow 6/8 time - or slow 6/4 time - conducted like 4/4 time, except with an extra flick of the hand at Beats "2" and "3" of the 4/4 conducting pattern. The conducting pattern for slow 6/8 time therefore looks like this from your point of view:
Down -> Left -> Flick -> Right -> Flick -> Up
Fast 6/8 ended up getting conducted like 2/4 time, except with the "upstrokes" of 2/4 time being transferred to beats 3 and 6 of 6/8 time.
I have no reason to believe that choir masters conduct differently, especially since I've also been in 2 school choirs.
Comment: If anything, from my experience, choir masters conduct *less* often than concert band conductors.

Conducting music written in 6/8


How to restore a site from a backup done with Backup and Migrate module using Drush

Question: Just that. I've a backup using the backup and migrate module. I've done some changes and now the site is down. I can't restore the site using the admin interface (because it's broken).
Can I use Drush to restore it?
Comment: Just as a side note, BAM backups can usually also be restored with normal MySQL administration tools.
Answer: Yes, you can restore your backup with Drush.
Here are Backup and Migrate commands for Drush explained: http://www.only10types.com/2011/03/drush-backup-and-migrate-command.html
I think drush bam-restore command is what you are looking for.

bam-restore Restore the site's database with Backup and Migrate.
Examples: drush bam-restore db manual
  "LCC-31.03.2011-14.01.59.mysql.gz" - restore the default database
  using the given dump file, which can be found in the destination
  called "manual"
Arguments: source - Required. The id of the source (usually a
  database) to restore the backup to. Use 'drush bam-sources' to get a
  list of sources. Defaults to 'db' destination - Required. The id of
  destination to send the backup file to. Use 'drush bam-destinations'
  to get a list of destinations. Defaults to 'manual' backup id -
  Required. The id of a backup file restore. Use 'drush bam-backups' to
  get a list of available backup files.
Comment: It appears that drush bam-restore only handles db backups. I think you will need to extract the files tar.gz file manually (without using drush).
Comment: What if the dump file is on the filesystem and not in the bam list
Answer: I can't comment, but for completeness' sake I'd rather add the official bam-backup command help too.
<code>$ drush help bam-backup

Backup the site's database using default settings.

Examples:
 drush bam-backup                          Backup the default database to the manual backup directory using the default settings.
 drush bam-backup db scheduled mysettings  Backup the database to the scheduled directory using a settings profile called "mysettings"
 drush bam-backup files                    Backup the files directory to the manual directory using the default settings. The Backup and Migrate Files module is required for files backups.

Arguments:
 source                                    Optional. The id of the source (usually a database) to backup. Use 'drush bam-sources' to get a list of sources. Defaults to 'db'
 destination                               Optional. The id of destination to send the backup file to. Use 'drush bam-destinations' to get a list of destinations. Defaults to 'manual'
 profile                                   Optional. The id of a settings profile to use. Use 'drush bam-profiles' to get a list of available profiles. Defaults to 'default'

Aliases: bb
</code>


Why is forecasting of ARMA models performed by Kalman filter

Question: What are the advantages of expressing an ARMA model as a state-space-model and do forecasting using a Kalman filter?
This methodology is for example used in the SARIMAX implementation of python-statsmodels:
https://github.com/statsmodels/statsmodels/tree/master/statsmodels/tsa/statespace
Answer: To me one of the main advantages is handling of missing data and uneven time steps. Kalman filter easily handles the missing observations, and actually can be used to impute them.
OLS and MLE don't handle missing data as easily, and not every package will have this feature support unlike Kalman filter.


Dúvida - Case when dentro de um stuff - SQL Server 2012

Question: Galera, como faço para colocar um case when exists dentro da consulta abaixo. O resultado atualmente está saindo assim:
Clientes
Drogaria,Soccer,Gelagua
Porém, quero colocar um case when exists caso estiver na condição, vir sim,senao, vem não. Exemplo:
Drogaria - Sim, Soccer - Sim, Gelagua - Não
select
(REPLACE(REPLACE(REPLACE((STUFF((
   SELECT
      ':::::: ' + CAST(U.USUNOME AS VARCHAR) + '
 ' FROM Usuario U LEFT JOIN FRM_51 F51C ON U.UsuID = F51C.ContaID LEFT JOIN FRM_52 F52P ON F52P.C01 = F51C.C01  LEFT JOIN Tarefa T ON T.TarID = F52P.TarefaID WHERE  F51C.C04 = 3640 AND F51C.C01 = FRM52.C01 FOR XML PATH('')),1,1,1)),'1::::: ',''),':::::: ',''),' &# x0D;
','')) as Clientes

   from
      usuario

Comment: A informação deve vir na horizontal mesmo? Não poderia vir na vertical?

    Drogaria SIM
    Soccer SIM ...
Comment: na horizontal mesmo
Answer: Cara, eu fiz a query abaixo, veja se isso ajuda (vi que na sua query tinha muitos replaces e esse monte de ":" então preferi montar um exemplo):
select '1' [id], 'a' [texto] into #temp union
select '1' [id], 'b' [texto] union
select '1' [id], 'c' [texto] union
select '1' [id], 'd' [texto]

select distinct stuff((select ', ' + case when [texto] = 'a' then [texto] + ' - Sim'
                                when texto = 'b' then texto + ' - Nao'
                                else texto + ' - talvez'
                                end
        from #temp t
        where t.id = fora.id for xml path('')),1,2,'')
from #temp fora

O resultado disso foi:
a - Sim, b - Nao, c - talvez, d - talvez

Comment: show de bola @cotiovis. Obrigadão


Does the fact that $f(n)$ is not $o(g(n))$ and $f(n)$ is not $\omega(g(n))$ imply that $f(n)$ is $\Theta(g(n))$?

Question: Is this statement true?
$$f(n) \notin o(g(n))~~~\wedge~~~f(n) \notin \omega(g(n))~~\implies f(n)\in\Theta(g(n))$$
I'm thinking that because $f(n)$ is never greater than or less than $cg(n)$, then it must be growing at the same rate? However I don't know how to derive this solution from first principles.
Comment: what's  your definition of those 3 simbols? (If it's what I have in mind, then it's false, since $f(n)=sin (n)$ and $g(n)=1$ are not comparable)
Comment: what is this $\omega$ thing?
Answer: In general, not every two functions are comparable asymptotically.
Consider $f(x) = e^{x\cos(x)}$ and $g(x) = x$.


Android Service onBind method receiving stale intent

Question: I am instantiating a service as follows:
try {
        Intent intent = new Intent(this, SOMEService.class);
        intent.putExtra("key", SOME UUID);
        startService(intent);
        bindService(intent, myServiceConnection, Context.BIND_AUTO_CREATE);
    } catch (Exception e) {

    }

inside my service's onBind method, I check whether the supplied key matches the expected key in the service.
This key is refreshed on every transaction.
The issue is, if i close the app and reopen it (forcing the service to rebind), after that the onBind method receives the previous intent with the stale key and not the newer intent with the new key.
Any ideas why this may be happening?
Answer: When you start Service, it will run indefinetely and restart even if Android stops it due to lack of resources. So, when you close app, Service is kept running - you only onbind from it. If you want your Service running only when app is open, stop it when app closes and then start again.
Comment: as of now i have overridden my service's onStartCommand method as to return START_NOT_STICKY flag. That fixed the issue.
Though in the long run, i should figure out a way to correctly stop my service.
Answer: Did you try checking the intent in onStartCommand ?, since you are starting the service too.
According to docs:

Called by the system every time a client explicitly starts the service
  by calling startService(Intent)
  https://developer.android.com/reference/android/app/Service.html#onStartCommand(android.content.Intent,int,int)

Example:
public void onStartCommand (Intent intent,
            int flags,
            int startId)
{
     String key = intent.getStringExtra("key");
}


Changing from bass to saxophone

Question: I'm a professional, trained musician and yes I know that it's "never too late" to pick up something new. However: I play bass. I started 12 years ago because I actually wanted to play it. But over time that joy has eroded away and turned into anxiety. Bad gigs, bad college experiences, getting passed over for other players left and right, and personal conflicts have stolen it from me. I just look at my upright in the corner and I feel anxiety. The whole story is certainly too long for here, but for everything I've given it, it has abused me in return. But I'm good at it, and everyone who knows me knows that it's what I do. About 4 years ago I got into various sax players, especially Chris Potter. I pulled out my alto sax from childhood and started learning. But I couldn't put it down. I ended up buying a tenor, and started learning that. I truly feel that I have some natural ability for it. And I LOVE how out feels. It feels right, in a word. I've been practicing it off and on since.
So here's the problem: I have students, gigs, and a job. I can't do both. Do I abandon bass and restart on sax, relatively "late"in life (I'm going on 30) our do I stay with the painful, but proven, bass?
Answer: It is important to remember that you are a human being first, a musician second, and a bassist third.  Musical instruments are not monogamous.
As a musician, you feel a need (on some level) to express yourself.  The manner in which you do so may change throughout the course of your life, and that's okay.  Personally, I cycle through several instruments, chiefly tuba, guitar, and piano.  I've been a guitarist most of my life, but I studied tuba performance in college, and I improvise and play piano in a variety of settings.
I have students, a job, gigs, and I am a composer as well, so I'm constantly working on projects.  The manner in which I express myself changes according to my life circumstances, how I'm feeling, and how I'm thinking, but the one immutable fact of expression remains: I can express myself.
Over the years, I have developed enough facility on these instruments where I can set each aside for 6-12 months without touching, pick them up again, and be comfortable after a day or two.
What I'm really saying here is: you should do what's right for you, and not what you think other people think of you as. Human beings are not flat, and you shouldn't pretend to be one-dimensional if you're not. If anything, your family / friends will be even more impressed with you for playing both instruments.
The saxophone is attractive for you because it represents a clean-slate. It also represents a simpler time before all of the bad experiences you had with bass. It also provides a means of expression.  In short, it fills a lot of needs, which is great.
In order to make friends with your bass again, you'll need to create good experiences with it to replace the bad ones.  You'll also need to make peace with those bad experiences.  The answers to that will be your own discovery.  Perhaps the time you spend with the saxophone will help clear the air a bit and help you distance yourself from those experiences; allowing you to look on them more objectively and without anxiety.
Moral of the story: life is long, have fun, don't worry; your bass will come back to you when it is supposed to.
Comment: I see you corrected the edit that removed important information that your answer was based on.  Seems there is a new user on an edit binge who does not understand that background info and relevant detail is often important to a full understanding of the true question.  I have re-edited several of tv's recent overzealous paraphrasing so that the existing answers would still make sense to future visitors.  I was saving this one as an example for moderator - but was planning to re-edit myself - after mod had a chance to review.  But they can see what you did and get the picture.
Comment: @RockinCowboy Yes you are right, there is an edit history, so anyone can look at the changes made (or un-made, as it were). We need to be vigilant about how edits are approved. tv's edits only happened because someone approved the edit.

Changing from bass to saxophone


Filter spreadsheet by exact date (MM/DD/YYYY)

Question: I am building a tool that collects data from a userform and then the end user is supposed to be able to filter the master set of all the data and copy it into an email. For some reason my filter does not refine the set down to the exact day, but rather it only goes down to the month. The date is stored in a userform textbox that autopopulates with the current date, but the user is able to change it if they choose to report on older data. Here is my code for the filter;
    Private Sub CommandButton6_Click()

Sheets("Master").ListObjects("Append1").Range.AutoFilter Field:=1, Operator:= _
        xlFilterValues, Criteria2:=Array(1, date2_txtb)

End Sub

date2_txtb = Textbox containing date
Append1: Amended query making up the "Master Set"
UPDATE:
Private Sub UserForm_Initialize()
date2_txtb.Text = Format(Now(), "MM/DD/YYYY")
End Sub

Comment: Each time I see a question about time or date in Excel I feel compelled to ask the same question: are these actual dates or do they just look like dates? You might want to read through this to better understand dates / times in Excel: http://stackoverflow.com/a/37101358/1153513 This is probably also a good read: http://stackoverflow.com/a/38001028/1153513 Afterwards, please update your question and post and share with us whether you verified if these are **all** actual dates. Also, please include a check into your code to ensure that `date2_txtb` is an acutal date.
Comment: Thank you for posting those links, I was actually really curious about how excel formatted dates as numbers and visa-versa. I updated my question which will hopefully shed some light on this. I do have date2_txtb formatted as a date (I think), but what would you suggest in order to be able to successfully filter all of my data?
Answer: I think this is what you want.
date2_txtb = "11/11/2017"

Dim vDate As Date

Dim lDate As Long

vDate = DateSerial(Year(date2_txtb), Month(date2_txtb), Day(date2_txtb))

lDate = vDate

ThisWorkbook.Sheets("Master").ListObjects("Append1").Range.AutoFilter Field:=1, Criteria1:=">=" & lDate, Operator:=xlAnd, Criteria2:="<" & lDate + 1


How can two positive dependent correlation coefficients differ significantly without differing significantly from zero?

Question: I have  3 variables A, B and C, which are all markedly skewed. Below, I indicate correlations between two variables, e.g., A and B as $r_{ab}$.
Using the following test with with $n-2$ degrees of freedom
$$t= \frac{r\sqrt{n-2}}{1-r^2}$$

$r_{ac}$ is positive but not significantly different from zero,
$r_{bc}$ is positive but not significantly different from zero, and
$r_{ab}$ is significantly different from zero.

Then using Williams t test

$r_{ac}$ and $r_{bc}$ are not significantly different from each other.

How can this be possible?
Shouldn't the difference between two positive correlations always be non-significant when they are both not significantly different from zero?
Comment: There may be a typo because you seem to contradict yourself - are $r_{ac}$ and $r_{bc}$ significantly different from eachother or not?
Comment: @PeterEllis I've edited the question a bit to make it easier to read the key points. I've edited again in response to your comment. Does that make it clearer?
Answer: Let us define the difference between two correlations with one shared variable $C$ as
$$\Delta r = r_{ac} - r_{bc}$$
The standard error of $\Delta r$ get smaller as the absolute value of the correlation between the non-shared variables $r_{ab}$ gets larger. However, the standard error of either of the component correlations $r_{ac}$ and $r_{bc}$ is unaffected by the absolute size of $r_{ab}$. Thus, at a certain absolute size of $r_{ab}$ the standard error of $\Delta r$ will be smaller than the standard error for either $r_{ac}$ or $r_{bc}$. In this sense it is not surprising to get a significant difference between correlations despite the fact that neither of the two correlations are significantly different from zero as long as the correlation between common variables is reasonably large.
An R example:
Here's a simple example where the individual correlations of .05 and .1 with a sample size of 100 would not be significantly different from zero, but where the correlation between the two shared variables is .97, the difference between the two correlations is significantly different.
<code>library(psych)
paired.r(xy=.05, xz=.1, yz=.97, n=100)

Call: paired.r(xy = 0.05, xz = 0.1, yz = 0.97, n = 100)
[1] "test of difference between two correlated  correlations"
t = -2.06  With probability =  0.04
</code>


Sveltekit development with workers KV -- hot reloading

Question: Is it possible to use CloudFlare's Workers KV when developing a Svelte/kit application?
It is possible to build the app then run wrangler dev when using the CloudFlare Workers adapter:
npm build
wrangler dev

However, I haven't gotten hot module reloading working:
npm dev & wrangler dev

Answer: As far as I know, there's no way to emulate Workers KV locally. However, I setup a local Redis instance as a substitute.
Then, I created some wrapper functions for the KV store. In development, it talks to Redis, and in production it talks to Workers KV. For instance, here's the wrapper function for get.
import { dev } from '$app/env'
import redis from 'redis'

const client = redis.createClient()
const get = promisify(client.get).bind(client)

export const getKvValue = async (key: string): Promise<string | null> => {
    return dev ? await get(key) : await KV.get(key)
}

Update: You can actually make things much simpler by just using an object in JavaScript—no need to download and run a Redis binary. Just make sure to JSON.stringify the values before setting them.
import { dev } from '$app/env'

const devKvStore = {}

const devGetKvValue = (key: string) => {
    return new Promise((resolve) => {
        resolve(devKvStore[key] ?? null)
    })
}

const devSetKvValue = (key: string, value: unknown) => {
    return new Promise((resolve) => {
        devKvStore[key] = JSON.stringify(value)
        resolve()
    })
}

export const getKvValue = async (key: string): Promise<string | null> => {
    return dev ? await devGetKvValue(key) : await KV.get(key)
}

export const setKvValue = async (key: string, value: unknown): Promise<void> => {
    return dev ? await devSetKvValue(key, value) : await KV.put(key, value)
}

Comment: Really smart workaround. Rich Harris confirmed on Twitter that there is currently no "real" solution for this, so I think this hack is as good as it gets in the interim. The tweet: https://twitter.com/Rich_Harris/status/1505539552508878849
Comment: Has someone find out a way to use [miniflare](https://github.com/cloudflare/miniflare) instead?
Comment: @trenta3 Yes, see my answer for how to use miniflare with `npm run dev`
Answer: You can use miniflare (via wrangler npm package) to emulate cloudflare bindings, and then use the local dev vite server for very fast hot reloading etc.  This works really well, at least for KV and D1.
For more detail and a working example see this SO answer: https://stackoverflow.com/a/77194403/1129543
The corresponding example project is https://github.com/sdarnell/cf-svelte/


Why dont I get an alert when the text is added?

Question: I know I can achieve this by adding the alert function in the button click listener body but I don't want to do it that way.I want whenever this textbox receives text, i get an alert.
this is the code
<!DOCTYPE html>

        <title>Page Title</title>

        <form>
<input id="check" type="text" name="check" >

        </form>

        <button id="test">ClickMe</button>

Comment: `'input propertychange paste change'` ? You only need `"input"` :)
Comment: If you want the alert when you insert the value with the button use `$('#check').val('N001-01-1356/2017').change()`
Answer: Setting the value with Javascript doesn't trigger an event, so you need to trigger the event manually. Also, you really only need the "input" event. The others are irrelevant or redundant.
$('#check').trigger('input');

Or you can chain it since you're using jQuery:
$('#check').val('N001-01-1356/2017').trigger('input');

Example:

$(document).ready(function() {

  $('#test').click(function() {
    $('#check').val('N001-01-1356/2017').trigger('input');
  })

  $('#check').on('input', function() {
    alert("text added");
  })

})

<form>
  <input id="check" type="text" name="check">
</form>

<button id="test">ClickMe</button>


How do I know when to stop singing?

Question: Assuming you complete a vocal warmup, I'm wondering how you know when you've overdone it and should stop singing.
Is it normal to feel a bit of strain in the vocal chords?  How much strain should you feel?
Answer: First, I've been a professional musician, but I'm not a professional singer - nonetheless, I've recently started working with a teacher that has made a huge difference in my singing, and the lessons are fresh in my mind.
The trick, I believe, is learning to tell the difference between your voice being tired vs. strained. If you are straining, you are tense, you are not getting "good exercise", and pushing more may damage things - you'll have hoarseness the next day, or worse. But if you are simply tired, your voice will recover fully after a good night's sleep, and you will have taken yourself far enough past your to be strengthen it in the long run.
So how do you tell? For me, the sensations are similar, but very distinct. For one thing, strain comes on much more quickly. And I can usually think back about how I have been singing that would lead to stress. And if I've been rehearsing for hours, and the rest of my body is fatigued (good voice teachers will tell you that your whole body is your instrument), well, that's a clue. So just deciding that you are going to learn to tell the difference between the two sensations is a huge step.
A good trick for checking your tension is to put one palm on either cheek, and drag them downwards, caressing your jaw and throat, feeling the tenseness drop out of your face and neck.
In the end, I've been told by several professionals that a good warm-up is the best protection against strain. And then there's all that business about "support" and so forth that I'm working on with my teacher...
Comment: I agree that the sensations are similar but distinct. The main difference for me, is when I'm just "tired," I can feel myself supporting the tone, and my whole body is engaged. When I'm strained, all that is there is the stress/fatigue in my throat.
Answer: None.
If you are feeling strain, then you're doing it wrong.
Since starting with a vocal instructor, I can sing 30 minutes-60 minutes without feeling strain.  A feeling of strain used to onset within 5 minutes of singing.
I'm going to try to describe what I learned, but this should only serve as motivation to get a vocal instructor to teach you.  Really it comes down to sounding your vocal chords, without involving other muscles of the throat.  But you will never get it unless you sit there with a piano and an instructor and she listens to how you sound and corrects you and tells you what you're doing wrong.
You probably cannot learn how to sing without a teacher to show you.  Even if you can, getting an instructor will greatly accelerate your learning.
Yes they are expensive.  But if you want to sing, you really need one.
My advice in selecting a vocal coach:

Don't go for the lame online lessons. The only good one I found was this set by Ariella Vaccarino, but even this isn't enough - she can't listen to you or provide you with feedback, which is absolutely crucial.
Do not go to a vocal coach who you do not like how they sound.  How they sing is the best they know -- so naturally you won't be pleased with the results if you don't like them when you hear them
If there is no recording there is no proof.  Probably keep looking for another instructor -- a musician must have a recording they're proud of somewhere.
Comment: I realise yoiu're maybe not the author of that linked page, but isn't that a bit like saying someone doing a workout shoulnd't ever tire ?
Comment: ["Allow me to say emphatically, a singer should NEVER experience vocal fatigue. If he/she is singing correctly, the voice should not tire."](http://www.voiceteacher.com/damaging.html)

How do I know when to stop singing?


Redirecting 400 URLs with Apache

Question: I need to permanently redirect about 400 URLs. What's the best way to go about it? The most obvious solution would be to add 400 lines of "Redirect 301 old-url new-url" to .htaccess. Is there a better way?
Example URLs:
50 of these:
/category -> /new-category-name-c/

about 350 of these:
/category/subcategory/product.html -> /slightly-different-product-name.html

Edit: added example
Comment: Check this [answer from Jon Lin](http://stackoverflow.com/questions/15579620/how-to-block-100-000-individual-ip-addresses/15580768#15580768)
Comment: You can use regular expression.. Can you post an example of old and new URLs?
Comment: @pandronic: There are ways to avoid writing 400 Rewrite rules but you need to tell us specific details like a small sample of old and new URLs.
Comment: I've added a generic example. We've completely redone a badly done website, changed a lot of the product and category names so there's no obvious pattern between the old and the new URLs. Thanks.
Answer: You may create a PHP(or any other) script which will handle all pages which does not exist. It will detect the old URLs and return 301 redirect to new URL.
If old URLs cannot be parsed by regexp, you will need to create a map, like this:
$urlMap = array(
    '/category1' => '/new-category1',
    '/category2' => '/new-category2'
);

and to look up the new URLs from it. If URL is not in map, then return 404 header or redirect to somewhere else..
You can use the ErrorDocument directive to define custom 404 page:
ErrorDocument 404 /process-urls.php

You can get the path from $_SERVER['REQUEST_URI'].
Update
As suggested by @faa, you can use the RewriteMap apache directive. You need to create a txt file which will map from old URLs to new ones, one mapping per row, space separated:
/category1 /new-category-1
/category2 /new-category-2

Then, in your virtual host file, declare the map:
RewriteMap examplemap txt:/path/to/file/map.txt

And the rewrite rule(may be placed in .htaccess):
RewriteCond ${examplemap:%{REQUEST_URI}|0} !=0
RewriteRule ^(.*) ${examplemap:$1|/not_found.html}

This method is easier to maintain than putting 400 rewrite rules to .htaccess.
Comment: I was hoping to avoid scripting. Would it affect performance badly if I were to add 400 lines of "Redirect 301"?
Comment: @pandronic I think it will affect performance, but don't know to what extent..
Comment: +1 The problem could be with the queries when using mod_alias. I think any of your options is a better solution.

Redirecting 400 URLs with Apache


jQuery pop up box overlay not closing

Question: I am using a pre-existing jQuery popup plugin for a WordPress site.  The popup works great but the only problem is the styling - it didn't include any sort of "overlay" in the design.  Since I want the background to "grey out", I set out to adding some classes and styles to the css to make this happen, but am running into a wall.
Here was the original HTML:

message content

And I added a div above that to create this HTML:

message content

Here is the JS - I added the 2nd line to the removeMessageBox function below after editing my HTML per above:
function removeMessageBox() {
    jQuery(this).parent('#messagebox').removeClass('visiblebox').addClass('hiddenbox');
    jQuery(this).parent('#popupOverlay').removeClass('visiblebox').addClass('hiddenbox');
    return false;
}

function boardReady() {
    jQuery('#closebox').click(removeMessageBox);
    jQuery('#messagebox').css('visibility', 'visible');
}

jQuery(window).load(boardReady);

And here is some corresponding CSS:
div#popupOverlay.visiblebox {display: block;}
div#popupOverlay.hiddenbox {display: none;}
div#messagebox.visiblebox {display: block;}
div#messagebox.hiddenbox {display: none;}

Of course, it's not working.  I barely know any JS so I'm not sure exactly what to add to the right function to get the same effect of the close action when clicked on the close link.
Comment: I'm not entirely sure what `popupOverlay` is supposed to achieve, but could it be that it sits on top of your `closebox` link making it unclickable?
Comment: Could you link us to the actual plugin? Or at least supply us the css for both messagebox and popupoverlay?
Comment: @Tomm - No, the other styles have z-indexes that make them all sit on there in the correct order.  When you click the CLOSE button on the popup, it closes fine, but the OVERLAY behind it (which has an opaque color style applied to it) stays put, rendering the entire site impossible to use.
Comment: @Purmou, actually it's not a free plugin (it's one on WPMUdev), so not sure if I can share the files due to license restrictions?  But I'll paste the css below...
Comment: CSS: http://pastebin.com/FSNFfGF3  -- You can see the problems on the live site by visiting http://www.appthemes.com/showcase/ and then scrolling down to the bottom left image called "Running Horses Classified Ads" -- the reason I'm using this particular popup is because it has an easy referral function to it and I only want the popup to display to people visiting the site from this referrer.
Answer: I see. Why don't you try this
function removeMessageBox() {
    jQuery('#messagebox').removeClass('visiblebox').addClass('hiddenbox');
    jQuery('#popupOverlay').removeClass('visiblebox').addClass('hiddenbox');
    return false;
}

There is no need for all the jQuery traversing (i.e. using the .parents() method) as both elements have unique IDs. The problem with your code is that #popupOverlay is not a parent of closebox.

jQuery pop up box overlay not closing


Negative variance, what is wrong?

Question: I am trying to obtain the variance of a function of two random variables
$$f(\boldsymbol x):= x_A (e^{k(x_A+x_B)}-1)$$
where $\boldsymbol x = [x_A, x_B]^T$. Additionally, I know that $\operatorname{E}[x_A]=\operatorname{E}[x_B]=0$.
My approach is to obtain:
$$\operatorname{Var}[f] = \operatorname{E}[f^2]-\operatorname{E}[f]^2$$
For the expectation of $f$, I followed this post and used
$$
\operatorname{E}[f(\boldsymbol x)] \approx f(\operatorname{E}[\boldsymbol x]) + \frac{1}{2} \operatorname{E}[(\boldsymbol x-\operatorname{E}[\boldsymbol x])^TH_f(\operatorname{E}[\boldsymbol x]) (\boldsymbol x-\operatorname{E}[\boldsymbol x])]
$$
Which for this case should simplify to
$$
\operatorname{E}[f(\boldsymbol x)] \approx \frac{1}{2} \operatorname{E}[(\boldsymbol x)^TH_f(\operatorname{E}[\boldsymbol x]) \boldsymbol x]
$$
The hessian matrix for $f(\boldsymbol x)$ evaluated at $\operatorname{E}[\boldsymbol x]=[0,0]^T$ turns to be
$$ H_f(\operatorname{E}[[0,0]^T]) =\left[  \begin{matrix}
    2k & k \\
    k& 0
  \end{matrix}\right]
$$
so I get
$$\operatorname{E}[f(\boldsymbol x)] \approx \operatorname{E}\left[[x_A, x_B]\left[  \begin{matrix}
    2k & k \\
    k& 0
  \end{matrix}\right] [x_A, x_B]^T\right]= \operatorname{E}[kx_A^2+kx_Ax_B]$$
For $\operatorname{E}[f^2]$, every term in the hessian (evaluated at $\operatorname{E}[\boldsymbol x]$) is null. Because of this I get $\operatorname{E}[f^2]\approx 0$.
Then, as $(\operatorname{E}[kx_A^2+kx_Ax_B])^2\ge 0$, my estimation of the variance is negative.
My questions are:

What I am doing wrong?
How to solve it correctly?

Thank you very much
Comment: What distribution has the property of $\operatorname{E}[f^2]\approx 0$ ?
Comment: @user158565 Thanks for reply, I bet none, although I do not know exactly the distribution of my data, it should be something close to the normal distribution. Although I agree with you in that such expectation is not possible, I cannot find where is the mistake.
Comment: I mean you should not get $\operatorname{E}[f^2]\approx 0$.
Comment: @user158565 I understand that, but I found that the Hessian evaluated at (0,0) is null (please, see the link in the question). Higher order terms maybe helps, or maybe I am doing something wrong in that part. In any case, I found rare that I get $\operatorname{E}[f^2]\approx 0$ up to second order. I would like to try it up to higher orders but I really do not know how to do that (I am chemist).
Comment: I think the covariance between $x_A$ and $x_B$ is needed. Then you can try delta method.
Comment: @user158565 - that's correct.  $E[kx_ax_b] \neq 0$ unless the covariance is zero, and $E[kx^2_A] \neq 0$ unless the variance of $x_A$ is zero.
Comment: @user158565 Sorry, I cannot follow you.
Comment: @jbowman, Thank you for your comment.  Yes, as you said, those expected values are not null. Because of this, the square of their sum is a positive number. This square must be subtracted from $\operatorname{E}[f^2]$ for obtaining the variance. As I get $\operatorname{E}[f^2]\approx 0$, I get a negative variance.
Answer: Suppose you can get the covariance between $x_A$ and $x_B$. Let
$$\Sigma = \left(\begin{matrix} Var(x_A) & Cov(x_A,x_b)\\ Cov(x_A,x_b) &Var(x_B) \end {matrix} \right)$$
$$\frac {\partial f}{\partial x} = \left(\begin{matrix} \frac {\partial f} {\partial x_A}  &  \frac {\partial f} {\partial x_B}\end {matrix} \right)$$
Then by delta method,
$$Var(f) \approx\left(\frac {\partial f}{\partial x}\right)\Sigma \left(\frac {\partial f}{\partial x}\right)^T$$
Comment: Thank you very much! I am not sure about how the derivatives (gradient?) must be expressed. Do they must be evaluated at some point, right? I suppose that at [0,0]. In such case I get Var(f) = 0 ! https://www.wolframalpha.com/input/?i=gradient+of+x*(e%5E(k*(x%2By))-1)

Negative variance, what is wrong?


Esconder uma imagem ao passar o mouse em cima da div

Question: Estou tentando fazer com que uma imagem desapareça ao passar o mouse em cima da div mas estou com um problema: quando passo o mouse a imagem desaparece, mas não consigo clicar no link da div de trás.
Código:

CSS:
.elemento-um {
    background: rgba(0, 0, 0, 0);
     margin-top: -127px;
     height: 107px;
     overflow: hidden;
}

.ico {
     opacity: 1;
     top: -140px;
     transition: .5s ease;
     z-index: 111;
     position: absolute;
}

.ico a{
display: none;
visibility:visible;
}

.ico:hover a {
visibility: block;
}

Comment: Lia só pelo seu relato é impossível te dar uma resposta precisa. Por favor, edite sua pergunta colocando o código HTML e CSS que vc tem. E se possível faça o Tour do site para entender melhor como funciona aqui https://pt.stackoverflow.com/tour
Comment: @hugocsl, desculpe, não sabia. Editei a pergunta com o código.
Comment: Adicionalmente ao comentário do @hugocsl, a página [ask] vai direto ao ponto. É sempre recomendável incluir um [mcve].
Answer: Lia,
Pelo código parece estar ao contrário do que você perguntou, então vou responder baseado na sua pergunta.
A propriedade visibility:block não existe, o correto seria visility:visible. O block é do display. display:block.
O display:none esconde o elemento da tela, já o visibility:hidden deixa o elemento lá só que esconde o conteúdo.
Mas para esse caso não serviria colocar display:none no hover porque quando der hover no elemento vai esconder ele e como escondeu não vai mais estar em hover então o elemento irá aparecer de novo e ficar "piscando" na tela aparecendo e desaparecendo.
o ideal seria colocar um opacity:0 na imagem quando der hover na div.ico.
Ex:
.elemento-um {
    background: rgba(0, 0, 0, 0);
     margin-top: -127px;
     height: 107px;
     overflow: hidden;
}

.ico {
     opacity: 1;
     top: -140px;
     transition: .5s ease;
     z-index: 111;
     position: absolute;
}

.ico:hover a {
   visibility:hidden
}

Segue um fiddle de exemplo:

https://jsfiddle.net/ey0m7rta/9/
Comment: Muitíssimo obrigada por tirar um tempo para me ajudar! Era exatamente isso. Desculpe também pelo erro, me confundi na hora de publicar. Tenha uma ótima noite!


Linear independence, Spanning, Injectivity, and Surjectivity

Question: We were told in class that when we proved that a function between two vector spaces is injective and surjective, essentially we were proving that a basis for the vector space is linearly independent and spanning, respectively. I was just wondering how this works exactly?
I understand the definitions of these concepts, I am just not sure how to use the definitions of linear independence and spanning to prove that a function is bijective.
Answer: Let $T\colon V\to W$ be a linear transformation of vector spaces. Choose a basis $\mathcal{B}$ of $V$. An obvious question is whether the image $T(\mathcal{B}):=\{T(\mathbf{e})\mid \mathbf{e}\in \mathcal{B}\}$ of this basis is a basis of $W$. There are two ways this can fail: (1) $T(\mathcal{B})$ is linearly dependent, and (2) $T(\mathcal{B})$ doesn't span $W$.
Here's what you should prove for yourself:

$T(\mathcal{B})$ is linearly independent if and only if $T$ is injective.
$T(\mathcal{B})$ spans $W$ if and only if $T$ is surjective.

For 1., you'll want to use the fact that $T$ is injective if and only if its kernel is $0$. If that fact is unfamiliar to you, prove it also!
Answer: This basically relies on the following propositions. Let $V, W$ be vector spaces.
Lemma: Given $E \in Hom(V, W)$, $E$ is mono $\iff Ker(E) = {0}$
Proof:
$\implies$ ) Suppose $Ker(E) \neq {0} \iff \exists x \in Ker(E) : x \neq 0$, but then we have that $E(0) = 0 \wedge E(x) = 0$, hence it is not injective.
$\impliedby$ ) Let $a, b \in V : E(a) = E(b)$, this happens iff $E(a) - E(b) = 0 \iff E(a - b) = 0$, but then $a - b = 0 \iff a = b$, since 0 is the only element mapped to 0.
Corollary: Given $E \in Hom(V, W)$ mono, $\{v_i : i \in I\}$ is linearly independent set $\iff$ $\{f(v_i) : i \in I\}$ is linearly independant
Lemma: Given $E \in Hom(V, W), E$ is epi, $\{v_i : i \in I\}$ spans $V \implies \{f(v_i) : i \in I\}$ spans $Im(f)$
Proof:
Take any $v \in V$, then $v = \sum_{i \in I} \alpha_i v_i$, hence $f(v) = \sum_{i \in I} \alpha_i f(v_i) \in \langle \{ f(v_i) : i \in I \} \rangle$
The other inclusion is clear, since $f(v_i) \in Im(f) \forall i \in I$, thus: $Im(f) = \langle \{ f(v_i) : i \in I \} \rangle$
Hence, suppose you prove that a linear transform $f$ is an isomorphism, and you have $\beta = \{v_i : i \in I\}$ a basis of $V$, the first corollary says that $f(\beta) = \{ f(v_i) : i \in I \}$ is linearly independant. Since $Im(f) = W$, we also have that $f(\beta)$ spans $W$, thus $f(\beta)$ is also a basis for $W$.
Answer: There's a few things that are unclear in your question.
First, by definition a basis of a vector space is a linearly independent spanning set. It's cardinality, ie the number of vectors in the basis gives us a measure of the size of the space - it's called the dimension.
Now given two different spaces with the same dimension, we can map bijectively the basis of one to the other; and then by linearity this extends to a linear bijection map between the two.
Answer: I believe your confusion comes from the sentence "we were proving that a basis for the vector space is linearly independent and spanning".
What it is that you're proving is that the image (the set of images) of a base for the first space is again a base for the second.
More precisely: let
$f:V \to W$
a linear map between vector spaces. Say $\mathscr{B}$ is a base for $V$. Then what you have to see is that the set $f(\mathscr{B}) = \{f(b)\in W \textrm{such that } b\in\mathscr{B}\}$ is actually a basis for $W$ iff $f$ is a (linear) bijection.
This is easy. Let's do one of the implications for surjectivity. So assume $f(\mathscr{B})$ is a basis for $W$, and I'd like to see that $f$ is surjective. So we take any $w\in W$ and see it has a preimage. Since $f(\mathscr{B})$ is a basis, we can write
$w = \sum a_i f(b_i)$
for some $a_i$ in the field, and some (finite) $b_i\in\mathscr{B}$. By linearity of $f$, we can write
$w = \sum a_i f(b_i) = \sum f(a_i b_i) = f(\sum a_i b_i)$
But $\sum a_i b_i $ is an element in $V$, since is a (finite) linear combination of elements in the basis. Thus $w$ has a preimage. You can work out the other implications to practice with the concepts!


How do I trick my internet browser that I'm using 32bit Operating System even it's a 64bit application

Question: Some websites detect my operating system architecture automatically and I don't know how they get the value (eg. 32-bit / 64-bit OS). So they can use the value for the following case:
Example of the case:
If I want to download something for Example 'Google Chrome', the Google Chrome Download Page thinks that I'm using 64bit operating system and thus it downloads 'ChromeStandalone64.exe for me. If I want to download the 32bit, I need to be on the 32bit OS OR I need to click on the other platform. This is just a use case example.
So in general, my question is how do I trick the browser (using any scripting language) that I use 32bit OS ? I know there is a chrome plugin that disguises the Chrome browser as different browser like Safari, Internet explorer. it works. but what about tricking the browser as 64bit or 32bit?
Edit: Please do not give me the answer how to download a Google Chrome. I just gave an example of the case.
Comment: This question is off-topic here as it is not related to programming in any way. Any website that offers downloads for multiple platforms has an option to choose the platform to download for.
Comment: And there is no veto power to downvote. Each user has equal right and power to downvote as he or she sees fit. [No explanation mandated](https://meta.superuser.com/questions/7223/downvoting-a-question-should-require-a-comment-upvote-of-a-comment)
Comment: Just ignore the example of Google Chrome and my main question is how do I trick my browser that I use 32 bit OS in certain websites ?
Comment: I have edited my question. That's it.
Comment: why do you need this?
Comment: @bolov For fun!!
Comment: I update my question again.
Comment: This question related to programming. Don't judge the book by its cover.
Answer: Websites can use either the User-Agent string which you can change with a browser extension, or the Javascript window.navigator.platform value which I don't believe an extension can change.
There is a "Download for other platforms" link at the bottom of the page that lets you download Chrome for 32-bit Windows:
Comment: Hai, my question is more about how do I trick the browser that I have 32-bit operating system ? I think I can do this with Google how to download Google Chrome. I just gave an example of the case.
Comment: So it is impossible to change that "window.navigator.platform"
Comment: I know how to download Google Chrome 32 bit and 64 bit
Comment: This post doesn't answer my question
Answer: For Google Chrome, you could try clicking on "Other Platforms" near the bottom of the https://www.google.com/chrome/ page, then choose the 32-bit version. If you install and browse with the 32-bit version, you may automatically get offered 32-bit versions of other software.
Another option would be to edit your user agent string. (Updated with more details:) The user agent string is the text that your browser sends to the web server to identify itself, e.g., "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36". On Chrome, it's a little convoluted to change, but you can find instructions at: http://technipages.com/google-chrome-change-user-agent-string . This may help, but not if the web servers use some other method to identify your machine as 64-bit.
Comment: What do you mean by user agent string in the case of Google Chrome Browser ? I'm using 64 bit Chrome.
Comment: The user agent string is the text that your browser sends to the web server to identify itself, e.g., "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36". On Chrome, it's a little convoluted to change, but you can find instructions here: https://www.technipages.com/google-chrome-change-user-agent-string . This may help, but not if the web servers use some other method to identify your machine as 64-bit.
Comment: I accepted this answer because you mention about 'user agent string'. even that's the small answer how things are done. it's useful.
Comment: But, actually I know how to download Google Chrome 32 bit or 64 bit.
Comment: If you could please put your answer from your comment so that other people can see. I use the extension to put it as old internet explorer and the browser can be tricked as 32bit. Thank you so much.
Comment: Ok, I copied it into the answer. Good luck with your project.


AWS DataPipeline: SellCommandPrecondition does not fail

Question: Using ShellCommandPrecondition for a SQLActivity with Datapipeline. In the python script, if I use sys.exit(0) (success signal) then the Precondition returns successfully and pipeline continues to execute. But if I use sys.exit(1) (error signal) then the Precondition does not return and stays in Running state indefinitely.
But with SellCommandActivity, if I use sys.exit(1) then it fails gracefully and following activities fail.
Why ShellCommandPrecondition does not exhibit same behavior as SellCommandActivity or is this is a bug in AWS Datapipeline and needs to rectified?
Answer: The three properties to look at are:

maximumRetries
retryDelay
preconditionTimeout

If your script fails (with a non-zero return code) on the first attempt, the precondition will not immediately fail. Instead it will pause for retryDelay and execute again up to maximumRetries. The total amount of time the precondition will allow for all attempts is determined by preconditionTimeout.


Inject login details into TwitterKit

Question: I'd like to inject or fake a login into the TwitterKit iOS SDK. I'm trying to write some unit tests for my library (which is kind of a wrapper around the most important Twitter APIs).
Unfortunately Fabric requires the user to have a system account set up or to present the OAuth screen. Is there any way to fake that login to make my test API calls succeed?
Any advice would be really appreciated.
Answer: It depends on what kind of tests you are trying to write and whether you are actually trying to make network requests during your tests.
If you are writing integration tests that have to work through the login flow the easiest way to accomplish this is to just add an account to the ACAccountStore by creating your own ACAccountCredential. One downside to this approach is that it will make a network call behind the scenes which is managed by the system, so there is no way to intercept/mock it which will likely make your tests flaky. Once you have that account added to the store it will get picked up whenever you try to go through the login flow.
If you are making network requests using the -[TWTRAPIClient sendTwitterRequest:completion:] method and you actually need to be logged in during these calls because you are trying to hit the Twitter API you can add a session to the TWTRSessionStore directly by calling [TWTRSessionStore saveSessionWithAuthToken:authTokenSecret:completion:]. Again, this method will make a network call that is hard to mock/intercept but that shouldn't really matter if you are making actual network requests during your tests.
If you are writing unit tests that do not need to make network requests, but you need there to be a session in the TWTRSessionStore you can directly save a session in the TWTRSessionStore. You can call -[TWTRSessionStore saveSession:withVerification:completion:] with a session that you create and without verification. Note, this method is private and is subject to change without notice. With that said, I don't really see any reason why we would change it anytime soon so it should be safe for you to use.
If none of that works for you, let me know more specifically what you are trying to accomplish and I can suggest other options.
Comment: That's a great answer. I'm writing unit tests at the moment and I'll soon try the last two options you mentioned. Thanks!
Comment: Unfortunately the class TWTRSessionStore doesn't have any init method. How can I see my auth token and secret in it?
Comment: You can get them from the session object you get back when you log in. Look at TWTRAuthSession.
Comment: The TWTRSessionStore can't be instantiated from code so it's not possible to create a new instance of it to store my token.
Answer: I used a function similar to this to create a sample Twitter test account insid of unit or integration tests:
static func addTestAccount(completion: ()->()) {
    let credential = ACAccountCredential(OAuthToken: TestAccountToken, tokenSecret: TestAccountSecret)
    let store = ACAccountStore()
    let type = store.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter)
    let newAccount = ACAccount(accountType: type)
    newAccount.credential = credential
    newAccount.username = TestAccountUsername

    store.saveAccount(newAccount, withCompletionHandler: { (success, error) -> Void in
        print(success ? "Saved new account" : "Failed to save account \(error)")
        completion()
    })
}

Inject login details into TwitterKit


Tree structure in R

Question: Is there any package provides tree structure manipulation? E.g. create a tree, get child / parent, add child / siblings /, traverse, etc.
I googled and find several packages such as 'tree', however they are for classification / regression
Comment: Would a general package for graph/network analysis help? If so, you can use `igraph` or `network`.
Comment: You want to look into data.tree . It does exactly what you want.
Answer: The type of operation that you're looking for sounds like the behavior of a directed graph, specifically a directed acyclic graph.
As it happens, there are several packages that allow this type of manipulation-
The gRbase package implements the functionality of several other packages, and the documentation linked above suggests graph, RBGL, Rgraphviz and igraph.
Generally, the term "tree" in R is going to refer you to some variation of the "decision tree" machine learning algorithm, which it sounds like you inadvertently found some resources for.
Answer: Checkout package data.tree to see if it meets your needs.  It creates trees from multiple sources (data tables, JSON, YAML), has traversing capabilities, and aggregation methods. Check the vignettes in the package for many examples.
Comment: Can you say anything more about this package & how it may resolve the OP's issue?
Comment: Yes, it turns out I am working through it's capabilities right now.  It creates trees from multiple sources (data tables, JSON, YAML), has traversing capabilities, and aggregation methods.   Check the vignettes in the package for many examples.
Comment: I don't agree with the comments. I may be l partial as I am the author of data.tree, but I think the answer answers exactly the question.

Tree structure in R


Increasing memory limit in Python?

Question: I am currently using a function making extremely long dictionaries (used to compare DNA strings) and sometimes I'm getting MemoryError.
Is there a way to allot more memory to Python so it can deal with more data at once?
Comment: @Maor That is definitely a lot. You should consider refactoring your code.
Comment: How much RAM are you working with? Can you add details about the data *in the question itself* instead of in the comments? Elaborate a bit more. If if it is a 32bit version of Python, you might benefit greatly by going 64bit. Depends.
Comment: Python 64-bits have **a lot more** memory support. I would say real numbers but I don't remember (I see this in a StackOverflow Question.)
Comment: I'm comparing strings in lengths of 3-5 million characters, in the process creating a dictionary for each containing roughly as many keys as its length. Does that count as a lot?
Comment: Hey, if it's DNA, then how these dictionaries have so many keys?
Comment: Bear in mind that Python objects incur some memory overhead on top of the "raw" data size. An empty string in 32 bit Python 3 consumes 25 bytes, each additional ASCII char will add 1 byte. If you use `bytes` strings instead the cost of an empty `b''` drops to 17 bytes. You can get this info via the `sys.getsizeof` function. Python 3.6 dicts are more space-efficient than previous versions, but they still have some unavoidable overheads.
Comment: python libraries like [resource](https://docs.python.org/3/library/resource.html) _can_ impose a limit though.
Answer: Python doesn't limit memory usage on your program. It will allocate as much memory as your program needs until your computer is out of memory. The most you can do is reduce the limit to a fixed upper cap. That can be done with the resource module, but it isn't what you're looking for.
You'd need to look at making your code more memory/performance friendly.
Comment: Or until the limit in the OS is reached (e.g. on linux you can easily impose limits via configuration)
Answer: Python has MomeoryError which is the limit of your System RAM util you've defined it manually with resource package.
Defining your class with slots makes the python interpreter know that the attributes/members of your class are fixed. And can lead to significant memory savings!
You can reduce dict creation by python interpreter by using __slot__ . This will tell interpreter to not create dict internally and reuse same variable.
If the memory consumed by your python processes will continue to grow with time. This seems to be a combination of:

How the C memory allocator in Python works. This is essentially memory fragmentation, because the allocation cannot call 'free' unless the entire memory chunk is unused. But the memory chunk usage is usually not perfectly aligned to the objects that you are creating and using.
Using a number of small string to compare data. A process called interning used internally but creating multiple small strings brings load on interpreter.

The best way is to create Worker Thread or single threaded pool to do your work and invalidate worker/kill to free up resources attached/used in worker thread.
Below code creates single thread worker :
__slot__ = ('dna1','dna2','lock','errorResultMap')
lock = threading.Lock()
errorResultMap = []
def process_dna_compare(dna1, dna2):
    with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
        futures = {executor.submit(getDnaDict, lock, dna_key): dna_key for dna_key in dna1}
    '''max_workers=1 will create single threadpool'''
    dna_differences_map={}
    count = 0
    dna_processed = False;
    for future in concurrent.futures.as_completed(futures):
        result_dict = future.result()
        if result_dict :
            count += 1
            '''Do your processing XYZ here'''
    logger.info('Total dna keys processed ' + str(count))

def getDnaDict(lock,dna_key):
    '''process dna_key here and return item'''
    try:
        dataItem = item[0]
        return dataItem
    except:
        lock.acquire()
        errorResultMap.append({'dna_key_1': '', 'dna_key_2': dna_key_2, 'dna_key_3': dna_key_3,
                          'dna_key_4': 'No data for dna found'})
        lock.release()
        logger.error('Error in processing dna :'+ dna_key)
    pass

if __name__ == "__main__":
    dna1 = '''get data for dna1'''
    dna2 = '''get data for dna2'''
    process_dna_compare(dna1,dna2)
    if errorResultMap != []:
       ''' print or write to file the errorResultMap'''

Below code will help you understand memory usage :
import objgraph
import random
import inspect

class Dna(object):
    def __init__(self):
        self.val = None
    def __str__(self):
        return "dna – val: {0}".format(self.val)

def f():
    l = []
    for i in range(3):
        dna = Dna()
        #print "id of dna: {0}".format(id(dna))
        #print "dna is: {0}".format(dna)
        l.append(dna)
    return l

def main():
    d = {}
    l = f()
    d['k'] = l
    print("list l has {0} objects of type Dna()".format(len(l)))
    objgraph.show_most_common_types()
    objgraph.show_backrefs(random.choice(objgraph.by_type('Dna')),
    filename="dna_refs.png")

    objgraph.show_refs(d, filename='myDna-image.png')

if __name__ == "__main__":
    main()

Output for memory usage :
list l has 3 objects of type Dna()
function                   2021
wrapper_descriptor         1072
dict                       998
method_descriptor          778
builtin_function_or_method 759
tuple                      667
weakref                    577
getset_descriptor          396
member_descriptor          296
type                       180

More read on slots please visit : https://elfsternberg.com/2009/07/06/python-what-the-hell-is-a-slot/
Answer: Although Python doesn't limit memory usage on your program, the OS system has a dynamic CPU and RAM limit for every program for a good power and performance of a whole machine.
I work on graphic fractal generate and it required as much billion characters array as possible for speed generate.
And I found out there was a soft limit per one python program set by OS that decrease the real performance of the algorithms on machine.

When you increase RAM memory and CPU usage (buffer, loop, thread), the total speed of process decrease. The useful thread quantity and thread frequency decrease, it cause the result took longer time to process. But, if you reduced the resource usage to 50...75% of the old config (smaller buffer size, smaller loop, less threads, lower frequency or longher threading timer ) and split the task to multiple part then run multiple console python program to process all task parts in the same time. It will took much less time to finish, and when you check the CPU and RAM usage, it will reach much more higher the old method single python program multi thread.

It's mean when we make a program dealing with high performance and speed and giant data processing, we need to design the program that has multiple background program and each background program has multiple thread running. Also, combine disk space to the process, rather than use memory only.

Even when you reach max physical memory, dealing with giant data at once will slower and limit application than dealing with giant data by splitting it to several part.

Optional, if your program is a special application, please consider to:

Apply Graphic card computing ability to the program, use OpenGL and graphic accelerate for Intel graphic or CUDA for NVIDIA.
Switch to OS and python 64 bit
Switch back to older operating system (but not too old): Windows 7 64bit or older Ubuntu, linux . Because higher OS has more costly luxury features and service consume computer resource. You will see a dramatically improve python ability and operation speed when using SSD drive and switch from windows 11,10 back to 7.
Switch to Safe Mode if you use Windows.

By create multiple background programs, it's allow you to create high speed graphic application that not require user to install graphic card. This is also a good choice if you want your program easy distribute to end user that integrate AI and costly compute power. It's cheaper to upgrade RAM  in the range 4-16GB than a Graphic card.

    ##//////////////////////////////////
    ##////////// RUNTIME PACK //////////  FOR PYTHON
    ##//
    ##//                                  v2021.08.12 : add Handler
    ##//
    ##//  Module by Phung Phan: firstname.lastname@example.com
    ##
    ##
    import time;
    import threading;
    # var Handler = function(){this.post = function(r){r();};return this;}; Handler.post = function(r){r();}

    ERUN=lambda:0;

    def run(R): R();
    def Run(R): R();
    def RUN(R): R();

    def delay(ms):time.sleep(ms/1000.0); # Control while speed
    def delayF(R,delayMS):
        t=threading.Timer(delayMS/1000.0,R)
        t.start();
        return t;
    def setTimeout(R,delayMS):
        t=threading.Timer(delayMS/1000.0,R)
        t.start();
        return t;

    class THREAD:
        def __init__(this):
            this.R_onRun=None;
            this.thread=None;
        def run(this):
            this.thread=threading.Thread(target=this.R_onRun);
            this.thread.start();
        def isRun(this): return this.thread.isAlive();

    AInterval=[];
    class setInterval :
        def __init__(this,R_onRun,msInterval) :
            this.ms=msInterval;
            this.R_onRun=R_onRun;
            this.kStop=False;
            this.kPause=False;
            this.thread=THREAD();
            this.thread.R_onRun=this.Clock;
            this.thread.run();
            this.id=len(AInterval); AInterval.append(this);
        def Clock(this) :
            while not this.kPause :
                this.R_onRun();
                delay(this.ms);
        def pause(this) :
            this.kPause=True;
        def stop(this) :
            this.kPause=True;
            this.kStop=True;
            AInterval[this.id]=None;
        def resume(this) :
            if (this.kPause and not this.kStop) :
                this.kPause=False;
                this.thread.run();

    def clearInterval(timer): timer.stop();
    def clearAllInterval():
        for i in AInterval:
            if i!=null: i.stop();

    def cycleF(R_onRun,msInterval):return setInterval(R_onRun,msInterval);
    def stopCycleF(timer):
        if not Instanceof(timer,"String"):
            try: timer.stop();
            except:pass;

    ##########
    ## END ### RUNTIME PACK ##########
    ##########

    import subprocess;

    def process1(): subprocess.call("python process1.py", shell=True);
    def process2(): subprocess.call("python process2.py", shell=True);
    def process3(): subprocess.call("python process3.py", shell=True);
    def process4(): subprocess.call("python process4.py", shell=True);

    setTimeout(process1,100);
    setTimeout(process2,100);
    setTimeout(process3,100);
    setTimeout(process4,100);

Answer: Try to update your py from 32bit to 64bit.
Simply type python in the command line and you will see which your python is. The memory in 32bit python is very low.

Increasing memory limit in Python?


Harmonium (Indian accordion) Synth, Sound design

Question: I wanted to design the harmonium sound in Logic Pro and I needed some help. If some of you have idea of how to make the sound, which might be according to me as follows.
There would be a saw tooth oscillator(or many) whose filter is primarily on a low pass and there would be an LFO which will modulate the cut off frequency of the same, with some speed, naturally related to the quality of the sound (Bear the sound in mind). I have tried this approach but could not approach the sound of the real harmonium. Any suggestions please? I am using Logic Pro DAW.
Comment: I'm torn between this belonging here (since it is closely tied to a specific musical instrument) and belonging at sound design (http://sound.stackexchange.com/) -- but please don't cross post.
Answer: The waveform from a single free reed is more like getting one "puff" of air each time the reed reaches its full excusion.  I would probably start with a square-wave and if possible modify the pulse width down (or up) to increase the higher harmonics.  Then I'd apply some equalization (mostly low pass) to round things out and to get the "wigglyness" in the waveform.
The effect that you are trying to achieve with the LFO modulated filter is the amplitude modulation that comes from the multiple reeds that sound when a single key is pressed.
This effect could be (approximately) achieved by using the LFO to modulate the amplitude of the signal (approximately because the beat rate of the modulation will go up with pitch if we assume that the reeds are tuned to +/-XXX cents of one another).  This  has some advantages in terms of simplicty.
Alternately, one could explicitly model the separate reeds, and put a slight tuning difference between them (on the order of a few cents) to get the modulation.  This would allow you to directly model the fact that in most harmonium music, there are multiple reeds sounding when a single key is pressed.  Registration changes/differences can also be accommodated in this approach by adding additional, octave separated, generators (probably with different filtering characteristics).
To summarize:

starting with a (pulse width modulated) square wave is probably better.
part of the sound comes from the mixing of multiple imperfectly tuned reeds sounding at the same time (sometimes even within a given reed bank); this  results in amplitude modulation.
some registrations involve reeds at different octaves (different reed banks) sounding at the same time.


If the function $f(x)=x^3 + e^{{x}/{2}}$ and $g(x)=f^{-1} (x)$ then find the value of $g'(1)$.

Question: If the function $f(x)=x^3 + e^{\frac{x}{2}}$ and $g(x)=f^{-1} (x)$ then find the value of $g'(1)$.
How to get the inverse of $f(x)$?
Comment: You don't need to get the inverse of $f$: https://en.m.wikipedia.org/wiki/Inverse_functions_and_differentiation
Answer: This means $f(0)=1$ or $g(1)=0$. Since $f(x)$ is a bijection $f: R \rightarrow R$ its inverse exists, here it is called $g(x)$. So $$f(g(x))=x \Rightarrow f'(g(x)) g'(x)=1 \Rightarrow g'(1)=\frac{1}{f'(g(1))}= \frac{1}{f'(0)}=2.$$
Note Here the inverse exists but it is not obtainable. Let $y=f(x)$, you can find $g'(y_0)$ only at good points: $(x_0,y_0): (0,1), (1, 1+e^{1/2}), (2, 8+e)..$ for instance $g'(8+e)=1/f'(2)=\frac{2}{24+e}.$ $g'(2)$ exists but it is not obtainable! analytically. This is so becauase $y_0=2$ is not a good point i.e. we do not know the corresponding $x_0$. In general, $$g'(y_0)=\frac{1}{f'(x_0)},$$ where $(x_0, y_0)$ are known good points on the curve $y=f(x)$.
Answer: We know $g$ is inverse of $f$ so we have $g(f(x))=x$ . Differentiating we have $g'(f(x)).f'(x)=1$ we want $g'(1)$ so in above equation we want $f(x)=1$. Observation suggests that $f(x)=1$ at $x=0$ thus $g'(f(0)).f'(0)=1$ thus $g'(1)\frac{1}{2}=1 $ $g'(1)=2$.
Answer: Derivative of inverse function :
$g(f(y))=f^{-1}\circ f (y)=y$ so that chain rule is $$
 g'(f(y))
f'(y) =1
$$
Hence $$ f(0)=1,\ g'(1)=g'(f(0))= \frac{1}{f'(0)} =2$$


Compare current time to file date time last modified in Windows Batch File

Question: I would like a command in a batch file to only execute if it has not been ran for the last 15 minutes. To achieve this I can create a "last_run" file to log the time last ran.
Where I am stuck is comparing the time last modified to the current time and taking action if the time last modified.
Here is my current code:
@echo off
set filename=last_run.txt
if not exist %filename% (
   rem NOT EXISTS, CREATE FILE THEN PRINT THE LIST
   echo.>"%filename%"
   GOTO PrintList
) else (
   rem FILE EXISTS, GET TIME LAST MODIFIED
   FOR %%? IN (%filename%) DO (set filetime=%%~t?)
   echo %filetime%
   rem IF TIME LAST MODIFIED > 15 MINS PRINT THE LIST
   if timediff??(%filetime%, current) > 15 mins {
      GOTO PrintList
   } else {
      GOTO End
   }
)

:PrintList
rem PRINT THE LIST
echo now print the list
rem WRITE TO THE FILE TO UPDATE TIME LAST MODIFIED
echo.>"%filename%"
GOTO End

:End

Comment: This is a script I wrote previously for this purpose. With a few modifications, minutes could be included in the comparisons. Minor adjustments will allow for operation of the program on your logfile without input being required `https://pastebin.com/hNCgcLLa`

The script demonstrates conversions and substring modifications that can be used to create comparable date time information between current time and file time
Comment: with regards to comparison operators in your example script, `GTR GEQ EQU LEQ LSS` and `If "%Var%"=="value"`  or `If Not "%Var%"=="value"` are valid, `<` and `>` are not - in batch they are redirection characters.
Answer: Besides the missing time calculation, your code has a delayed expansion problem. (My solution below doesn't need delayed expansion)
cmd is incredibly crude when it comes to date/time calculation (it can be done, but...).
Better use the help of another language (like PowerShell):
@echo off
setlocal
set "filename=last_run.txt"
set "minutes=15"
if not exist "%filename%" (
   break>"%filename%"
   goto :PrintList
)
for /f %%a in ('"powershell Test-Path %filename% -OlderThan (Get-Date).AddMinutes(-%minutes%)"') do set "older=%%a"
if "%older%" == "True" (
  echo %filename% is older than %minutes% minutes; print list
  break>"%filename%"
  goto :PrintList
) else (
  echo %filename% is younger than %minutes% minutes; exiting
  goto :eof
)
:PrintList
echo insert your payload here.

Comment: given the much simpler solution and less work involved in processing the information into useful form in batch... It's time I started learning more powershell
Answer: You could use total minutes with a powerhell command.
@echo off
set error=0
if not exist last_run.txt echo File not yet existed, first run will be now & set /a error+=1
    for /f "delims=," %%i in ('powershell -command "(New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date)).TotalMinutes"') do set "now=%%i"
    if "%error%" == "1" goto :run
    for /f %%a in (last_run.txt) do set earlier=%%a
    set /a result=%now%-%earlier%
    if %result% geq 15 (
        :run
           echo RUN COMMANDS HERE
           echo %now%>tmp.tmp
    )

The concept is simple. We get the epoch time in minutes. Store the value in a file. Then compare the current minutes with the minutes in the file. if %now% is equal to or more than 15 from %earlier% the command will run. Additionally, if the file does not yet exist, it will create it and run the command first time. From there it will only run if the seconds in the file is 15 or less than current minutes.
Answer: Another implementation using powershell from your batch-file:
@Echo Off
Set "filename=last_run.txt"
Set "minutes=15"
If Not Exist "%filename%" GoTo :PrintList
"%__APPDIR__%WindowsPowerShell\v1.0\powershell.exe" -NoProfile If(((Get-Date)-(Get-Item ".\%filename%").LastWriteTime).Minutes -LT %minutes%){Exit 1}
If ErrorLevel 1 Exit /B
Rem Your payload below here.

:PrintList
CD.>"%filename%"

If you are happy to accept that the PC running this code will always have the appropriate entries in %PATH% and %PATHEXT%, you can change "%__APPDIR__%WindowsPowerShell\v1.0\powershell.exe" to just PowerShell.