Is anything inherently random?

Question: Is anything inherently random? Or is all randomness observed in data either "errors in measurement" or "lack of understanding"? Assume we could measure everything with infinite precision and had a complete understanding of all the deterministic processes. Would there be any process that would appear "random" in the data or would every dataset be deterministic at that point?
Comment: Ah, in statistical analysis 'random' is often used as short hand for 'population, process and measurement effects that we don't understand but are orthogonal to the signal of interest and the disparate effects interact in such a way that the pattern of variance can be approximated by a stochastic variable'. It flow off the tongue a bit easier. As @Tim says, the question as asked is more philosophical. In a deterministic universe nothing is truely random. In a stochastic one, it is still likely that the randomness is buried a few layers deep in the contributing processes.
Comment: Look first to what you mean by "anything."  In what sense, for instance, is a repetition of an experiment really the *same* experiment?  Such a philosophical investigation is needed before you can even talk about randomness.
Comment: Moreover, it falls more into philosophy and is answered on philosophy Q&A https://philosophy.stackexchange.com/q/2439/27388 and https://philosophy.stackexchange.com/questions/29364/does-true-randomness-actually-exist
Comment: Have you seen this thread https://stats.stackexchange.com/q/286853/35989
Comment: https://plato.stanford.edu/entries/determinism-causal/ may be of interest
Comment: It depends on whether the universe is deterministic or stochastic. Which is what you want to distinguish. Would it be useful to ask what a thought experiment that would reveal the differences would look like? Or maybe you want to formulate a falsefiable hypothesis about how they would diverge?
Comment: @ReneBt: My question is inspired by this answer https://stats.stackexchange.com/a/558334/198058
Comment: Related: [Are randomness and probability really logically dependent notions?](https://stats.stackexchange.com/questions/549914/are-randomness-and-probability-really-logically-dependent-notions).
Comment: @Tim: Thank you very much for the links. They were on point and really helpful. whuber: great point! BruceET in his answer talks about the difficulty of repeating the same experiment; it makes sense that this would be a key ingredient here. ReneBt: thank you; I am not sure I understand your sentence "in a deterministic universe nothing is truly random"... BruceET has provided an example of a truly random process and then there is this answer about another one https://philosophy.stackexchange.com/a/2443 Are you saying these are random only because we don't currently understand them?
Comment: Regarding measuring a deterministic universe, consider the difficulty of collecting everything to know about the universe in a small part of that same universe.
Comment: radioactive decay is an example of inherently random process. you can measure its parameters with nearly infinite precision, but each event is random
Comment: @whuber [*"History doesn't repeat itself but it often rhymes"*](https://quoteinvestigator.com/2014/01/12/history-rhymes/). Our repeated experiments must be identified by equivalence relations often unequal to the identity relation.
Comment: @2.7182818284590452353602874713 Sure--but that seems a little too glib to be useful.  Exactly what aspects of an experiment must be reproduced in order for two instances to be considered "equivalent"?  Philosophers of science, such as Mario Bunge, have focused on the role of this "experimental preparation" as crucial to understanding the meaning of physical law and of "randomness."
Comment: @whuber I doubt there is a general answer available to which exact equivalence class would hold for any experiment. In practice we use the equivalence classes that are identified *ad hoc* (e.g. treatment vs placebo).
Answer: In some ways this may be a philosophical question.
My view is that the randomness a statistician sees in
data analysis is often real. Randomness might result from random sampling or from inherent randomness or instability.
Either way, statistical procedures of estimation might be useful.
Let's look at two
entirely different situations.
(1) We wonder whether the true average height of women high school
seniors in a US state is 65 inches. At noon on a particular day, one might carefully measure each
of them (thousands or hundreds of thousands, depending on the state), round to the nearest tenth of an inch, and take the mean.
Even
with perfectly accurate measuring and record keeping,
the result would likely be different on another day. Some students
might have grown just a bit. Also, there is some evidence that
a person's height may depend (slightly) on how much sleep they got the previous night. Does it make sense to say that the true statewide average height fluctuates constantly in some random way?
More realistically, one might take a random sample of $n = 400$ women for the measurements and averaging. In this case,
random sampling has clearly induced randomness. It would not
be surprising if another random sample of $400$ resulted in a different mean. Using such a random sample we could
make a 95% confidence interval for heights of senior women.
Perhaps this CI would be about $0.7$ inches wide, but we
could be fairly sure that the interval contains the right
answer for the heights of senior women in the state. For
practical purposes that might be sufficiently close to the 'correct' answer. Perhaps some probability model such as
$\mathsf{Norm}(\mu = 65, \sigma=3.5)$ is approximately correct.
If so, then our two samples of size $400$ might (at random) have been
$65.2$ and $65.0.$
round(rnorm(2, 65, 3.5/20) ,1)
[1] 65.2 65.0

(2) You have a small specimen of some radioactive material
with a long half-life (several thousand years). You use an appropriate counter to
count particles emitted in one particular minute to be $746.$
Using exactly the same experimental set-up several minutes later the count is $721.$
Monitoring the specimen over
several hours, you believe the hourly rate of particle emission
in your experiment is distributed $\mathsf{Pois}(\lambda=750).$ As far as is known, the number of particles
emitted into our counter per minute is truly random, and $\mathsf{Pois}(750)$ is a reasonable model. Both of our one-minute measurements could be exactly correct, but it would be wrong to
expect them to be exactly the same. (But not often fewer than 697 or more than 804.)
set.seed(1226); rpois(2, 750)
[1] 746 721
qpois(c(.025,.975), 750)
[1] 697 804

Comment: +1: Thank you for this great answer, Bruce. One clarification. You state "Randomness might result from random sampling or from inherent randomness or instability." To which of these would you ascribe the random experiment of flipping of a coin?
Comment: Ah yes! Right to the nub of it. [Diaconis et al.](https://statweb.stanford.edu/~cgates/PERSI/papers/dyn_coin_07.pdf) have shown that results of coins tossed by humans are remarkably non-random--partly or largely explainable by the physics of tossing. Experiments with carefully calibrated mechanical coin tossing machines have shown that essentially deterministic coin tossing is possible. Such physical analyses notwithstanding, if a coin tumbles many times before it is captured or 'hits ground', then results are largely unpredictable. So coin tosses to start ball games can be taken as "fair."
Comment: [See also](https://news.stanford.edu/pr/2004/diaconis-69.html).
Answer: Independently of the question of existence of randomness, you simply cannot measure anything to arbitrarily high precision, because your measurement will necessarily disturb it by a greater amount if you wish to have greater precision. This is already true in classical mechanics and remains true in quantum mechanics.
But your real question is whether there is anything inherently random in the world. Although this is not a mathematical question, it suffices to say that till today there is simply zero evidence for any truly random process. Quantum mechanics does not at all suggest, not to say imply, randomness in anything in the real world. Given this, it is reasonable to ask why so many real-world processes do appear to be probabilistic.
Well, the answer is that purely deterministic processes can amplify very small perturbations, so if there is an amplification process followed by a folding process then the result can appear chaotic even if it is fully determined by the initial state. Furthermore, symmetries in the folding process may strongly dictate the limiting distribution of the result as the amplification is increased.
For example, the logistic map has chaotic behaviour for certain parameters, for which just a slight perturbation in the input results in exponential divergence of the output. Essentially, the logistic map shows that repeated application of a continuous stretch-and-fold operation on a metric space can result in unpredictability in the limit. This has implications for the real-world, in that almost all measurements are of quantities arising from innumerable iterates of some physical process (e.g. particle-particle interactions).
Comment: Neither is there evidence against a non-deterministic universe. One thing that quantum mechanics implies/suggests is that our current description of physical laws does *not* allow a deterministic description. The best description of our *experience/observation* of nature is currently describing this nature as non-deterministic. It will be like that as long as we do not find a testable scientific theory of hidden variables. Such theory would go beyond our current scope of observation and is at the moment only speculation. It is not for nothing that it is called '*hidden* variables theory'.
Comment: Thank you for the answer. It looks like you disagree with this post about a quantum mechanics process that is truly random.  https://philosophy.stackexchange.com/a/2443
Comment: @ColorStatistics: No, the author of that post makes it very clear that that process "does not appear to be (**locally**) deterministic" and "the decisive proof is only against **local** hidden variables". This is why there is so far no evidence against a deterministic universe, because QM is actually **non-locally deterministic**!
Comment: You're mistaken about quantum physics.  Consider the https://en.wikipedia.org/wiki/Stern%E2%80%93Gerlach_experiment
Comment: @ColorStatistics: My correct comments got removed. Other commenters are mistaken about QM. The best description we have so far involves **non-local** wave-functions that evolve **globally**. There is absolutely **zero** evidence of any such thing as "wave-function collapse"; it is indistinguishable from a purely fictional construct. This is totally obvious from the fact that the [Galton board](https://en.wikipedia.org/wiki/File:Planche_de_Galton.jpg) can be simulated by deterministic classical mechanics showing that the apparent randomness there simply is an **illusion**.
Answer: Yes, there are "inherently" random processes in the universe.  As far as I know, it's impossible to determine in advance the collapse of a wave function.  For example, which slit a particle will go through in the two slit experiment.
This question should really be asked on physics.stackexchange.
Comment: For an introduction to superdeterminism at the popular science level, [watch this video](https://www.youtube.com/watch?v=ytyjgIyegDI).
Comment: Hidden variables theories are difficult to consider. One way in which they have not been strictly ruled out by [empirical tests of Bell's theorem](https://physics.aps.org/featured-article-pdf/10.1103/PhysRevLett.115.250401) is to allow [superdeterminsm](https://en.wikipedia.org/wiki/Superdeterminism) which is introduced and discussed in [*Rethinking Superdeterminsm*](https://www.frontiersin.org/articles/10.3389/fphy.2020.00139/full) and [*Superdeterminsm: A Guide for the Perplexed*](https://arxiv.org/abs/2010.01324).
Comment: @2.7182818284590452353602874713 I find it enjoyable to consider superdeterminism alongside [the strong free will theorem](https://www.ams.org/notices/200902/rtx090200226p.pdf). Toodles!
Answer: We do not know and may never know.  (and possibly we can not know*)
Statistics is not about the nature of reality. Statistics describes observations and these observations happen to have a random appearance due to unknown variable factors that are involved in the model descriptions.
The question whether the reality is intrinsically non-deterministic is more like philosophy than statistics.

*One may argue that the question about the deterministic nature of the world is actually not something that can be answered by a consciousness within this reality, and it may even not have any meaning at all. If the physical processes occur with some random nature, that means that the future state of the world can not be determined based on the present state, then still something makes the current state evolve into the future state and it is in some way determined. It is only not determined by an entity that can be known by the objects in the observable world. Whether or not something is deterministic is a matter of perspective.

Is anything inherently random?


Referencing Entity

Question: Is there no current way to get a referencing entity from a view? When clicking on relationship it only shows content referenced from the field, not from the referencing entity.
Answer: This is not ready yet:
Implement Entity Reference Backreferences
But you can start from the other side. Start in views with the referencing entity and use a contextual filter with the referenced entity nid and then make the relationsship to get the fields of both entities.

Referencing Entity


RegEx Pattern Matching

Question: Here's the Pattern:
((?<active>\*\s)*(fcid\s(?<fcid>0x[0-9a-f]{6})\s)*\[)?pwwn\s(?<pwwn>(([0-9a-f]{2}:){7})[0-9a-f]{2})(]\s\[(?<alias>\w*))*

Here's the possible input - each of those would be a line:
 1/ *fcid 0xce36c3 [device-alias N2F07D08]
 2/ pwwn c0:50:76:04:52:7e:00:2b [ARAH2KDBP04_STA_2b]
 3/ *fcid 0x19176a  [pwwn c0:50:76:04:52:7e:00:2a] [ARAH2KDBP04_STA_2]

It currently matches lines 2 and 3.  I need it to match the first line also.  I am having issues getting what is in the second line as optional.  If I try to make it optional, then the last 2 lines don't match either.  I know I don't have anything in the pattern yet to match the device-alias line but I am trying to get the input in the second line as optional first.
Comment: you should give more info about your input.. **Do you want to match only those 3 inputs**
Comment: something is missing..cant understand ur question
Comment: try now.  I made some edits to fix formatting.
Comment: This does not match the whole lines, just parts of them and incoherently so. What exactly do you need to pull out from these lines?
Comment: for this part of the file I am parsing, yes. Those are the 3 possible inputs.  I could split the pattern up but would rather try to get it all in one match, that way I can test each line once. Those are the possible inputs, each line will contain one of those 3.
Comment: @DavidGreen this would match them all

`(fcid|pwwn).?(0x[0-9a-f]{6}|[a-f0-9:]{23}).?\[(.*)\]`
Comment: In the fist line, I need to match the leading asterisk (if there is one) the 6 characters after the 0x, and any number of characters after device-alias, stopping at the closing ]  in the second line I need what is between pwwn and the opening [ excluding spaces.  in the last line I need the leading asterisk, the 6 characters after 0x and then the same as the second line
Comment: @DavidGreen Check out the expression here http://gskinner.com/RegExr/?31ulg
Answer: it doesn't match the first line because the regexp requires pwwn information to be present.
Answer: This is ugly
((\*\s*)?fcid\s*0x\w{6}\s*\[(device-alias.*?|pwwn\s\w{2}(\:\w{2}){7})\]|pwwn\s\w{2}(\:\w{2}){7})

works here
Comment: @DavidGreen - That's pretty common.  RegExr uses the ActionScript regex engine and Regex Hero uses the .NET regex engine.  And there are differences / incompatibilities between the two engines.
Comment: thanks so much.  it didn't work here:  http://gskinner.com/RegExr/ - that is the site I have been using. I assumed it was that site I have been using so  I wrote a quickie app in C# and tested, it works there.
Answer: Try this regex with IgnoreCase and MultiLine options checked and your named groups:
^(?<active>\*\s?)*(?:fcid\s(?<fcid>0x[0-9a-f]{6})\s+)?(?:\[?pwwn\s(?<pwwn>(?:[0-9a-f]{2}:){7}[0-9a-f]{2})\]?\s+)?\[(?<alias>[^[]+)\]$

You can test this here at RegexHero
The C# code could be:
string strRegex = @"^(?<active>\*\s?)*(?:fcid\s(?<fcid>0x[0-9a-f]{6})\s+)?(?:\[?pwwn\s(?<pwwn>(?:[0-9a-f]{2}:){7}[0-9a-f]{2})\]?\s+)?\[(?<alias>[^[]+)\]$";
RegexOptions myRegexOptions = RegexOptions.IgnoreCase | RegexOptions.Multiline;
Regex myRegex = new Regex(strRegex, myRegexOptions);
string strTargetString = @"*fcid 0xce36c3 [device-alias N2F07D08]\npwwn c0:50:76:04:52:7e:00:2b [ARAH2KDBP04_STA_2b]\n*fcid 0x19176a  [pwwn c0:50:76:04:52:7e:00:2a] [ARAH2KDBP04_STA_2]";

foreach (Match myMatch in myRegex.Matches(strTargetString))
{
  if (myMatch.Success)
  {
    // Extract your named groups here
  }
}

RegEx Pattern Matching


View with partial view that also has IEnumerable

Question: I have an application for college football fightsongs.  I want to display a single teams's details like school name, mascot, conference, etc... but also have a partial view on the same page where the partial view loops through the teams's fight songs.  I was able to achieve this with using an IEnumerable for the fight songs and Viewbag for the data, but I don't believe that is best practices.
I want my code to be as lean as possible and having 30 Viewbags in my view is probably not the best way to do it.
My code blows up on @Html.Partial("_FightSongDetails")
Here is the error:

Additional information: The model item passed into the dictionary is
  of type 'SportSongs.Models.ViewModels.ConferenceTeamViewModel', but
  this dictionary requires a model item of type
  'System.Collections.Generic.IEnumerable`1[SportSongs.Models.ViewModels.ConferenceTeamViewModel]'.

I believe this is saying my main view needs to have an IEnumerable of ConferenceTeamViewModel but then how do I pull data in without putting the entire page in a foreach loop?
ConferenceTeamViewModel is just my viewmodel with team, conference, and fightsong data.
My current Details Action is:
public ActionResult Details( int id = 0)
        {
            var team = _db.Teams.Find(id);
            var conference = _db.Conferences.FirstOrDefault(x => x.ConferenceId == team.ConferenceId);
            if (team == null)
            {
                return HttpNotFound();
            }

            return View(new ConferenceTeamViewModel()
            {
                Teams = team,
                Conference = conference
            });
         }

My Details View (I am able to pull in the single Model data, just not the fightsongs):
@model SportSongs.Models.ViewModels.ConferenceTeamViewModel

          @Model.Teams.School

          @Html.Partial("_FightSongDetails")

Here is my PartialView:
@model IEnumerable<SportSongs.Models.ViewModels.ConferenceTeamViewModel>

@foreach (var song in Model)
{

        @song.Fightsong.songname

}

Comment: I'm confused - does one team have multiple fight songs?  Or are you wanting to show _one_ team's detail but _other_ team's fight songs?
Comment: It would also be more clear if your variables were named properly - e.g. you have a `Teams` property that seems to only hold one team.
Comment: @DStanley Yes each team can have multiple songs, but the details page will only show one team.  So the view will have a single team's name, mascot, conference, but will have X amount of fightsongs.  Thanks
Comment: But is X _that_ team's song or _all_songs, including other teams?
Comment: One team can have multiple songs.  No two teams share the same song.
Comment: You need to show your model so we can understand what your tring do do. If a team has a collection of songs, then `class Team` should have property `IEnumerable` in which case you just loop through the songs and display each one - something like `@foreach(var song in Model.Teams.Fightsong) { ...}` but your naming conventions make it impossible to understand your structure
Answer: It sounds like you want to show the songs for that team in a partial view.  If that's the case, make the model type for the partial view a collection of songs, not the team).
Change your partial view to
@model IEnumerable<FightSong>

@foreach (var song in Model)
{

        @song.songname

}

and pass the collection to the sub-view:

          @Html.Partial("_FightSongDetails",model.Teams.FightSongs)

Comment: the model.Fightsongs is not avaialble in that partial call.
Comment: Yes, you should add to ConferenceTeamViewModel a property that contains all the fight songs for the team. In this answer ,that property is called Songs, and the object is FightSong. Sounds like if it's just the song, you could have IEnum.
Comment: @coggicc Try `model.Teams.FightSongs`.  I updated my answer.


How to move line segments to eliminate intersections with minimum movements?

Question: Is there any algorithm or related work for the following problem?
Given a set of line segments in 2D, how to move line segments (horizontally or vertically) to eliminate intersections so as to minimize the overall movements? Intersections at endpoints can be allowed.
Comment: How do you define minimal? The minimum number of movements or the minimum of the sum of distances/squares of the distances?
Comment: Also, can you move line endpoints separately, or is the length and orientation of the lines const?
Answer: If you want to minimize the number of segment movements:
You can transform the line segment problem to a graph problem:
Each segment is a vertex of the graph and there is an edge between two vertices if the two segments intersect each other. You want to find the minimum number of vertices that contain at least one endpoint of all the edges (because if you move all of these segments there will be no more intersections). This is the vertex cover problem, which is unfortunately NP hard, buth there exist approximation algorithms.
see: http://en.wikipedia.org/wiki/Vertex_cover_problem


Javascript function not returning false

Question: This function is only returning true. I have added a console.log in the if block and it is called but the function doesn't return false.
function isUniform(List)
{
    var ele = List[0];
    List.forEach(function(item)
    {
        console.log(ele);
        if(ele !== item)
        {
            return false;
        }
    })
    return true;
}

Comment: what does this list have?
Comment: What are is the value of `ele`/`item`?
Comment: Possible duplicate of [How to short circuit Array.forEach like calling break?](http://stackoverflow.com/questions/2641347/how-to-short-circuit-array-foreach-like-calling-break)
Comment: Just some numbers like [1,2,2,2]
Comment: Post a minimal verifiable example. [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)
Comment: ele is always equal to first element of the list and then it is compared with every element of list through a foreach loop @thebluefox
Comment: @Vamsi yes for the first element it will be equal but then for the rest of the elements it is not equal.
Comment: Quick Note: There is no way to stop or break a forEach() loop other than by throwing an exception. If you need such behaviour, the .forEach() method is the wrong tool, use a plain loop instead. If you are testing the array elements for a predicate and need a boolean return value, you can use every() or some() instead. Taken from MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
Comment: @JJJ so you are saying return false will not return the function and foreach will still run despite the return statement?
Answer: You need another method for testing unifomity. Better use Array#every, which checks every value with the first item of the array and return true, if all elements are equal and false if not. The iteration stops with the first unequal element.
function isUniform(list) {
    return list.every(function(item, _, array) {
        return item === array[0];
    });
}

The used Array#forEach returns always undefined:

forEach() executes the callback function once for each array element; unlike map() or reduce() it always returns the value undefined and is not chainable.
Comment: Cool! Learned a new thing. Thank you :D
Answer: I think you can use this code;
function isUniform(List)
{
    var res = true;
    var ele = List[0];
    List.forEach(function(item)
    {
        console.log(ele);
        if(ele !== item)
        {
            res = false;
            return;
        }
    })
    return res;
}

Comment: the `return;` is as redundant as in the original question :p

Javascript function not returning false


how does the key signature work (not reading it)

Question: If I find the key signature contains, let's say,  E flat, does that only mean only E's are E flat or every note on the staff of the key signature are flats? I've looked up multiple things but I am not having any success.
Answer: When at Eb appears in a key signature, it means that every E appearing in that music — no matter which line or space it is written on — will be played as an Eb unless otherwise indicated. The Eb in the key signature does not affect any other note.
In a key signature, each letter-named key (a "pitch class") gets its own sharp or flat.
For example, in the key signature below, every B and E in the piece would be played as Bb and Eb, but all of the other pitch classes (A, C, D, F, G) would be played as usual, without alteration. The flat signs affect, for example, an E written on the bottom line of the staff, or a B written above the staff.

In a piece with the above key signature, if a B or E natural is needed, then a natural sign would be placed before that note at the time the change is required.
Comment: @kianmyers Yes, that's right.
Comment: thanks, I'm still a little confused. you saying that all the notes that appear on the key signature will be played as flat right
Answer: Showing just one flat (on E) in the key signature couldn't possibly indicate all notes are flat. That would be madness, and non-sensical!
Maybe it's the way you've phrased the question.
When the key signature shows just one flat in one place on one staff, it's shorthand for all those notes with that letter name (pitch class) to be affected throughout the piece. In other words, a flat sign on top space, treble clef, means not just those Es, but every E in every octave in that piece must be flattened. If needed, some could be natural, but would have to be signalled as such where they are.
As an aside, where there is an E♭ in the key signature, there's sure as heck going to also be a B♭ - having both signifying keys B♭ major or G minor.
Comment: In proper "formal" music notation, the key signature will appear at the start of each line for which it is applicable, but to expedite transcription of parts which would probably be sight-read once from start to finish and never used again (e.g. parts for simple advertising jingles) it is acceptable to include the key signature on only the first line where it is used.  Having key signatures at the start of every line can be very useful if someone may need to start reading a piece of music in the middle, but if one is writing out ten parts with eight staves each...
Comment: ...of a piece in Eb major (three flats), and it takes 1.5 seconds to draw each flat sign, writing out all the extra key signatures would require an extra five minutes of work.  This convention has been extended to some printed music which is supposed to appear informal, such as the Real Book.
Comment: @supercat - I used to work with a band which used numbers with key sigs, only on the first line  - and the #/b were usually in the wrong places! It didn't really matter, as we all knew 3# = A, etc. But I often question why the key sig. needs to be stated on each line. Time sig. isn't! Obviously if there's modulation/key change, it needs showing, but...
Comment: If musicians will often start playing in the middle of a piece (e.g. during practice or rehearsals), that will be greatly facilitated if the marks are printed at the start of each line.
Comment: @supercat - I'm doing that all the time. If I'm not aware of that detail, really, I shouldn't be there.
Comment: A lot depends on the length of the piece.  If a piece fits on one page or a pair of facing pages, it may be easy to figure out what key signature is effective at any particular place, but if a piece has 5 pages in Bb major, and then switches to Eb major for the next 3 pages, someone who's starting playing at measure 514 in the middle of page 7 would have some trouble figuring out what key signature was effective if the key signatures were only printed at the beginning and on page 5.
Comment: As for why the key signature (and clef) is repeated on every line while the time signature generally isn't - you should be able to tell what the time signature is by looking at any arbitrary measure in the middle of the piece and simply counting beats.  You can't do the same for the key, so the reminder can be useful.
Comment: Key signatures (and even, sometimes, clefs) are omitted after the first appearance in just one convention, that of commercial music copying, USA, mid/late 20th century.   It has acquired a quite unjustified cachet of being 'professional'.    You can trick a notation program into doing this.  Don't.
Answer: My music theory is not super strong, but I'm going to put this out there as a baseline answer to be improved by the community...
For the sake of argument (and to make intervals more visual), I'm going to use a piano keyboard for explanation.

If you are playing in the key of C Major, there are no sharps or flats. So first you play the C on the far left, then the D, then E, and so on, pressing all the white keys.
In case you don't play piano, I will point out that the musical distance between each adjacent key (black or white) is a half step. So if you count out the distance between the keys you play in the key of C on a piano, you get a whole step from C to D (C, C#, D), then another whole step (D, D#, E), then a half step, etc. So all together you get whole-whole-half-whole-whole-whole-half to make up the entire C Major scale.
Anytime you want that "major" sound, you can construct a major scale from whatever starting note you want, you just have to follow those same relative gaps between notes. So if I wanted to start with B♭ and make a major scale, I would do the same pattern whole-whole-half-whole-whole-whole-half: B♭ is the first note, and then going up a whole step we get C (B♭, B, C). After following the whole pattern you should get B♭, C, D, E♭, F, G, A, B♭, arriving back at the root note of the scale.
You'll notice that in the B♭ Major scale we've constructed, there are two flat notes: B♭ and E♭. If you want someone to play a piece of music in this key, you would mark those two flats on the sheet music, just the way Aaron describes. The person playing the sheet music would understand that they are playing in B♭ Major, and they will know that no matter what octave they are playing in, they must make sure they play B's and E's flat.


Como evitar que uma simples query trave todo o banco MySQL

Question: Tenho uma aplicação em Rails que usa um banco de dados MySQL com uma tabela com milhões de linhas. As vezes, acontece de alguma parte da minha aplicação fazer uma query muito pesada, travando todo resto da aplicação. Como fazer para evitar que essas queries pesadonas travem meu banco de dados, ou talvez limitar para que o banco fique travado por no máximo 30 segundos, derrubando a query se ela demorar muito?
Comment: Tem certeza que o gargalo é no banco? Talvez seja o Rails. Qual servidor você usa em produção? O Webrick não é bom para produção.
Comment: Sim, ele trava o banco, não consigo nem fazer queries direto no banco. Com o comando SHOW PROCESSLIST Vejo varias conexões em lock por causa da query pesada
Comment: Você já tentou implementar *eager loading* com `includes`? Veja [aqui](http://guides.rubyonrails.org/active_record_querying.html#eager-loading-associations) e [aqui](http://apidock.com/rails/ActiveRecord/QueryMethods/includes).
Comment: Verifica se não estão faltando índices nas tabelas.
Answer: Tudo isso depende muito de como está configurado o ambiente, da modelagem do banco de dados e da consulta realizada e da forma.
Ambiente
Se banco de dados e sua linguagem executam na mesma máquina podem ocorrer uma condição grave de disputa por recursos.
O MySQL precisa ler muitos dados do disco e transferir para a memória e, ao mesmo tempo, o processo Ruby comunica-se com o processo MySQL.
Tudo isso numa mesma CPU e num mesmo barramento pode causar uma grande degradação de desempenho.
Se for este o caso, tente separar servidor de banco de dados e servidor de aplicação em dois hardwares distintos conectados por uma rede de alta velocidade.
Modelagem do Banco de Dados
É difícil falar em problemas de desempenho e otimização sem falar do modelo.
Uso inadequado de tipos (usar VARCHAR como chaves primárias ou para armazenar números e datas), falta de índices adequados, excesso de normalização (necessitando juntar muitas tabelas para recuperar informações) são fatores que contribuem para um desempenho sofrível.
Consulta (Query)
Com hardware e modelagem adequados, resta então verificar o plano de execução da consulta.
A causa mais comum de lentidão em consulta é o chamado table scan, isto é, quando uma query precisa ler todos os registros de uma tabela para retornar os resultados.
Isso ocorre sempre que se usa uma condição WHERE que não esteja vinculada a um índice. Pode ainda ocorrer em outras situações, como em subqueries, joins ou mesmo durante a ordenação.
Usando índices
Por exemplo, se tiver uma consulta assim:
select id, nome, idade, sexo, endereco
from cliente
where idade = 30
order by nome

O ideal nesse caso seria criar dois índices: um por idade e outro por nome com ordenação ascendente.
Isso faria com que o MySQL não precisasse ler a tabela para filtrar os resultados. Olhando no índice por idade ele determinaria quais registros deveria buscar na tabela de verdade e, olhando no índice por nome, ele não precisaria fazer a comparação de todos os nomes para determinar a ordem, já que o índice é ordenado.
Veja outro exemplo:
select id, nome, idade, sexo, endereco
from cliente
where idade = 30 and sexo = 'M'
order by nome

No caso acima, o MySQL poderia fazer o filtro por idade e depois olharia registro a registro para filtrar o sexo. Isso é melhor que nada, mas poderia ser ainda mais eficiente com um índice incluindo idade e sexo.
Enfim, os índices possibilitam ao banco de dados saber de antemão quais dados exatamente deverão ser recuperados para o usuário, sem que ele precisa varrer toda a tabela carregando os valores e realizando comparações.
E algo a se atentar é que, mesmo com bons índices, usar operações de conversão de tipos ou funções de transformação nas cláusulas de comparação pode fazer com que eles não sejam usados. Aí existem inúmeras possibilidades, por isso é sempre bom testar a query com uma ferramenta que mostra o plano de execução.
E o Ruby?
Se o servidor de banco de dados está travado, então a culpa não deve ser do Ruby.
Pelo que entendi, o servidor fica indisponível, então o gargalo de processamento deve estar nele.
Se a query estivesse sendo executada rapidamente e então o Ruby fosse lendo as informações recuperadas, provavelmente o processo bloqueado seria do próprio Ruby.
Porém, há ainda algo a se considerar...
Nível de isolamento
Os bancos de dados relacionais trabalham com determinados níveis de isolamento, que controlam como diferentes sessões e transações conseguem ver os dados umas das outras.
O fato de não se conseguir ver os dados enquanto a query é executada pode ser causada por sobrecarga no sistema ou simplesmente porque o nível de isolamento bloqueia a tabela quando ela está sendo lida.
Algo que pode otimizar a leitura concorrente é permitir "leitura suja". Para fazer isso no MySQL é necessário executar o comando abaixo:
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

Ao executar isso, você deveria ser capaz de consultar a tabela enquanto a mesma é lida ou alterada.
Para maiores detalhes sobre o comando veja a documentação.


Static variables in jmeter

Question: I have the following question for Jmeter. Request your help.

Across my test plan(within the same thread group) I have created multiple HTTP requests which in turn uses multiple Java sampler to process the information and puts it into a certain user defined variable which finally goes into these HTTP requests body. All these java samplers are classes, while some of them has static variables which I have used as counters and also to hold some request specific data. All these classes are jar files which I have placed inside the lib\ext folder of Jmeter.

I would like to know w.r.t static variables/classes in the sampler I have used & assuming One loop inside a thread group is termed as one run

Will the static variables populated in run-1 be present for run-2 and
further runs as well since it is static?
Since these runs are going    to be concurrent, will the static
values get messed up?

Many thanks.
Comment: Thanks. I just logged in.
Answer: The answers are:

Yes
Yes

2 solutions:
1/ In a Setup Thread Group call, use a Beanshell to reset your static variables
2/ Synhronize access to static variables

Static variables in jmeter


Boxplot with a symmetric box, but with whiskers of different lengths

Question: From Figure 2 of Ferreira et al. (2016) "Graphical representation of chemical periodicity of main elements through boxplot", we can see the taxonomy of some common cases of symmetrical and asymmetrical distributions, with their corresponding boxplots:

Now, if the box of the boxplot is symmetric (i.e. same distance from the median to both hinges), but one whisker is longer than the other one, as in the following picture, are the following (A) and (B) boxplots asymmetric/skewed?
Comment: Nothing stops a distribution being approximately symmetric in its middle half but asymmetric overall.  In fact, the tongue-in-cheek  generalization that distributions tend be approximately Gaussian in the middle is attributed to C.P. Winsor.
Comment: Statements about skewness should generally refer to the entire distributions. The point is that a central box that appears symmetric itself says nothing about the entire distribution. If is often true that a distribution that is strongly skew will have a skewed box as well, but that is not guaranteed.
Comment: The bottom plot is consistent with the idea that the data are integers. If they are, box plots can fail to be informative because tied values can lead to small artefacts.
Comment: We are often get confused questions here about box plots that arise from not thinking carefully about the implications of data that have only a few distinct values, such as small counts or ordinal grades. Pleased to note that isn't an issue in this thread.
Comment: You might get some value from the cautionary example I gave [here](https://stats.stackexchange.com/a/137982/805), which shows four data-sets with very different histograms$^\dagger$ and yet identical, completely symmetric boxplots (constructed to emulate the examples in Choonpradub & McNeil q.v.). One of the example histograms is quite distinctly asymmetric. $\:$ $\dagger$: however a little caution is required in interpreting the histograms as well; they are themselves a little misleading for some of the data sets, such as two distinct peaks hiding within one "box: in one of the histograms.
Comment: Thanks a lot @NickCox! From your statement "Nothing stops a distribution being approximately symmetric in its middle half but asymmetric overall." I understand that a distribution represented by the boxplot B in my question can be considered as skewed (at least by eye), even though the central half is symmetric, right or wrong? (Maybe the skewness of boxplot A might be unclear)
Comment: About the line of numbers at the very bottom, I did it with integers just to have a rough reference, but my question would apply to any real number (i.e. the current line, where integers are showed, would need to be replaced by the line of real numbers)
Comment: I am very grateful for your additional comments, which bring further clarity to my question, thanks a lot!
Comment: This is a simplified version of the question addressed at https://stats.stackexchange.com/questions/96553, which I believe (therefore) answers your question.
Comment: The question addressed at stats.stackexchange.com/questions/96553, does not answer my question at all (I read it before). My question is not a simplified version of that one. Btw, both Nick Cox and Peter Flom answered my question. Thanks to both of them.
Comment: Thanks a lot for your comment @Glen_b!
Answer: This will depend on your definition and measure of skewness. There are several different ones. They can be grouped into ones that use all the data and ones that use part of the data. For the former, B will be skewed. For the latter, it may not, depending on the particular choice of measure. (A shows relatively little skewness, so it may be harder to detect).
The most common measure that uses all the data is Fisher-Pearson skewness.
$g_1=\frac{∑^N_{i=1}(Y_i−\bar Y)^3}{N_s}$
which is sometimes given with an adjustment for sample size.
The most common of the latter is probably Bowley's measure:
$\frac{Q_1 + Q_3 - 2Q_2}{Q_3 - Q_1}$
where the Q are quartiles. But this can be varied to use any symmetric quantiles.
Comment: $g_1$ is usually scaled by the cube of the SD to give a unit-free measure. Otherwise its sign is informative, but the magnitude just depends on the unit of measurement. Pleased to see the attribution to Bowley. Literature often credits Galton with this measure, but he didn't use it, or Yule and Kendall, who did use it, but much later.
Comment: More or less, yeah.  The thing is, "symmetry" isn't a yes/no proposition, unless you mean exactly symmetric, but even if the population is distributed perfectly normally, a sample from it may not be. So, *how* non-symmetric is it? And in what ways?
Comment: Thanks a lot @Peter Flom! With "This will depend on your definition and measure of skewness" I understand the following: If we use the Fisher-Pearson measure, the boxplot B is positively skewed (asymmetric), while if we use the Bowley's measure (for the central half of the distribution), the boxplot B is symmetric. Is this what you wanted to say? Did I understand correctly?
Comment: Note that (mean $-$ median) / SD is also sometimes used. It has a feature which has often surprised people: like Bowley's measure it varies in $[-1, 1]$. Note that the mean CAN equal the median in a skewed distribution, in which case the measure fails absolutely to quantify skewness, just as Bowley's measure can give a misleading sign.  Always look at a graph too!


Max and min of a function $f(x,y,z)=x^2+y^2-z^2$ on a set E

Question: I have a set E=$\{x,y,z): x^2+y^2+z^2\le1, y\ge0\}$ and the function $f(x,y,z)=x^2+y^2-z^2$
There isn't stationary points inside E : $\nabla f=0$ for $(x,y,z)=(0,0,0)$ but the origin is a point of the boundary of E.
How  can i use lagrange multipliers method to study the boundary?
Comment: Why do you need Lagrange methods? It is immediate from the inequalities that $-1\le f(x,y,z)\le1$. Anyway Lagrange methods don't really help on the boundary.
Comment: but if I use lagrange multipliers?
Answer: For the conditions of optimallity for the inequality constraints look at the Karush–Kuhn–Tucker conditions.
Replace one inequality constraint with an equality constraint and you get a part of the boundary. Then we look at the conditions (here for maximizing $f$):
$$ x^2 + y^2 + x^2  = 1 , y \geq 0 \\
\Rightarrow \nabla f(x,y,z) = \begin{bmatrix}2x\\2y\\-2z\end{bmatrix} =\mu \begin{bmatrix}0 \\ -1 \\ 0\end{bmatrix} + \lambda \begin{bmatrix}2 x\\2y\\2z\end{bmatrix}\\ \mu \geq 0, \ y \geq 0\\
 x^2+y^2+z^2=1,\ \mu (x^2+y^2+z^2) =0 $$
As we know $x^2+y^2+z^2=1$ we get
$$\mu = 0\\
\begin{bmatrix}2x\\2y\\-2z\end{bmatrix} =\lambda \begin{bmatrix}2 x\\2y\\2z\end{bmatrix} \Rightarrow 0=\begin{bmatrix}2 x (\lambda - 1) \\2y(\lambda -1)\\2z(\lambda +1)\end{bmatrix}
\\ y \geq 0,  x^2+y^2+z^2=1$$
Now $\lambda$ has to be either -1 or 1, else the equations cannot be fulfilled. For $\lambda=1$ we get $z = 0, y = \sqrt{1 - x^2} \Rightarrow f(x,y,z) = 1$ and for $\lambda=-1$ we get $x =0, y =0, z = \pm 1 \Rightarrow f(x,y,z)= -1$,
thus the maximum on the first part of the half sphere is on $y = \sqrt{1 - x^2}$ with value $1$.
You need to do this again for minimization (see in the Karush-Kuhn-Tucker conditions that you need to change the sign in the equation for $\nabla f$) and for the other part of the boundary.


Wordpress: How to redirect to a blank page so inline/browser PDF creation will work?

Question: I'm working with mPDF inside Wordpress.
I create a wordpress template and I have this code in it:
echo '<form name="MyForm" method="post">';
echo '<input name="download" type="submit" value="Download PDF" />';
echo '</form>';

if(isset($_POST['download'])) {
    include('mpdf/mpdf.php');
    $mpdf=new mPDF();
    $mpdf->WriteHTML($my_html_stuff);
    $mpdf->Output('my_file.pdf', 'D');
}

This doesn't work because Wordpress outputs stuff BEFORE $mpdf->Output(). I need something BLANK before $mpdf->Output() for this to work.
I'm thinking of first redirecting to a completely blank page and then doing the $mpdf->Output(). Any suggestions on how to best approach this?
Comment: Create another template without `get_header()` and `get_footer()` and put the mPDF code. It should do the job.
Answer: It looks like the problem is you're outputting your form before you attempt to output the PDF.
Try outputting the PDF first and then killing the script:
if(isset($_POST['download'])) {
    include('mpdf/mpdf.php');
    $mpdf=new mPDF();
    $mpdf->WriteHTML($my_html_stuff);
    $mpdf->Output('my_file.pdf', 'D');
    exit;
}

echo '<form name="MyForm" method="post">';
echo '<input name="download" type="submit" value="Download PDF" />';
echo '</form>';

Also, make sure you do not have any output before your form processor. If this is a template in your theme do not call get_header. Best practice would be to take your form processor out of the template file. You could put it in your theme's functions.php file or implement it as a plugin. Keeping your backend processing separate from your frontend helps avoid situations like this.
Comment: As I mentioned you may want to separate the form processing from the template. Add your form processing code to the functions.php file and then you can keep get_header and get_footer in your template without causing any issues.
Comment: I have the get_header() and get_footer() in the template (so it looks pretty), which gives me the problem. So should I just create another template without headers/footers with the mpdf stuff in it, then just an  link from my "pretty" template page to the blank page?
Comment: If for some reason you must keep the form processing in the template file, move it above `get_header()` and it should work.


Java: Check if every single digit of a number is within a range

Question: I am making a method of a class that takes two integers as arguments. It checks every single digit of the first one and makes sure they are less than or equal to the second one.
public static boolean digitRange(int x, int limit) {
    String number= Integer.toString(x);
    char[] digits=number.toCharArray();
    boolean result=false;
    for(char c: digits) {
        if(Integer.parseInt(String.valueOf(c))>limit) {
            result=false;
        }
    }
    return result;
}

The expected output for say 0 and 5 would be:
public static void main(String[] args){
    System.out.println(digitRange(0,5));//0 is les than or equal to 5.
                                        //Therefore true is printed.
}

However, I am getting false in every single scenario and I cannot find why.
Could someone help me correct the digitRange method, please.
Answer: String number= Integer.toString(x);
char[] digits=number.toCharArray();
boolean result=false;
for(char c: digits) {
    if(Integer.parseInt(String.valueOf(c))>limit) {
        result=false;
    }
}
return result;

You never set result to true anywhere.  Change to
boolean result=true;

However, consider a totally different approach:
public static boolean digitRange(int x, int limit)
{
    int t = Math.abs(x);
    while (t > 0)
    {
        if (t % 10 > limit)
            return false;
        t /= 10;
    }
    return true;
}

Answer: You never set the result value to true. Simply return once you have established false as you no longer need to check, and if you make your way out of the iteration return true.
public static boolean digitRange(int x, int limit) {
    String number= Integer.toString(x);
    char[] digits=number.toCharArray();

    for(char c: digits) {
        if(Integer.parseInt(String.valueOf(c))>limit) {
            return false;
        }
    }
    return true;
}

Answer: The function accepts two numbers and checks each digit is within the range of the second number and return true if all digits are less than the second number or it returns false.
public boolean check(int one,int two){
    while(one>0){
        if(one%10>two)
            return false;
        one=one/10;
    }
    return true;
}


Django-HTMX: on form validation error render to diferent target

Question: I'm starting to mess around with HTMX and found a wall I haven't been able to climb on my own:
I used HTMX to manage the creation/edition form and post the data to the corresponding view and update the item list. It works marvelously. But when the form raises Validation Errors the list is replaced by the form html.
Is there a way to set a different render target for when the form has validation errors?

{% if object %}Edit{% else %}Create{% endif %} Object

    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>

    <form hx-post="{{targetURL}}" hx-target="#Object_List" method="POST">
    {% csrf_token %}
        {{form.as_div}}

            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
            <button type="submit" class="btn btn-primary">Save</button>

    </form>

from django.views.generic import TemplateView, ListView, CreateView, UpdateView, DeleteView
from django.urls import reverse_lazy
from project.mixins import HtmxRequiredMixin, ResponsePathMixin
from .models import Object_
from .forms import Object_Form
# Create your views here.

class Object_Main(TemplateView):
    template_name = 'Main.html'

class Object_List(HtmxRequiredMixin, ListView):
    model = Object_
    template_name = 'Object_List.html'
    queryset = Object_.objects.all().order_by('as_group','as_name')

class Object_Create(ResponsePathMixin, HtmxRequiredMixin, CreateView):
    template_name = 'Object_Form.html'
    model = Object_
    form_class = Object_Form
    success_url = reverse_lazy('list-object')

class Object_Update(ResponsePathMixin, HtmxRequiredMixin, UpdateView):
    template_name = 'Object_Form.html'
    model = Object_
    form_class = Object_Form
    success_url = reverse_lazy('list-object')

Those are the template where the form is placed and my views.
If there is no way to set different targets based on the response then I would thank any suggestion.
I checked different sources but none were approaching the issue of form validation from the same angle. I don't need real time validation right now.
I asked Bing for some insight but was unable to find a satisfying/let alone working solution. So I thought to ask for help among my fellow human programmers.
Comment: You could simply override the `form_invalid()` method in your view and return a different template.
Comment: @McPherson, the form_invalid() by default renders again the form adding the list of errors. The success_url, in the other hand guaratees that my valid form renders a different template. The solution was to add the header Hx-Retarget to the response in form_invalid() as mariodev pointed out.
Answer: You can do that by modyfing your response header using HX-Retarget. In case of CBV you can override form_invalid method:
def form_invalid(self, form):
    """If the form is invalid, render the invalid form."""
    reponse = self.render_to_response(self.get_context_data(form=form))
    response['HX-Retarget'] = '#other-id"
    return response

Ref:
https://htmx.org/reference/#response_headers

There's also quicker, if you're using django-htmx:
https://django-htmx.readthedocs.io/en/latest/http.html#django_htmx.http.retarget
Just a side note. When dealing with htmx FBV approach is much better then CBV, so you might consider switching, to avoid all these method overriding.
Comment: Sorry I've put url by mistake. It's corrected. And yes - you provide any css selector as value for the header.
Comment: HX-Retarget would contain the ID of your form, right @mariodev ?


Display immediately data from csv file to handsontable

Question: I want to display data from a *.csv file in an array on my web page. So, when the user click on the button, I want my data to appear in my array immediately.
This is how I get the data from the *.csv :
<?php
        $file=file('Classeur1.csv');

        foreach ($file as $ligne)
        {
            list($index,$id_essai,$nom_local,$nombre_traitement,$nombre_blocs,$type_rotations,$essai_ou_suivi,$thematique,$annee_debut,$annee_fin)=explode(";",$ligne );

        }

    ?>

Now, when I click on the button, I call a javascript function like this :


Setup Postfix Mail Server in Ubuntu 10.xx for a VirtualHost

Question: I want to work with Postfix in Ubuntu 10.xx (.04 or .10) so that one of my virtualhost is the domain name or "mail name" as the configuration calls it for Postfix. How do I do this? ANd how do I configure the SMTP username and SMTP password for this?
Thanks in advance, and if this happens to be a duplicate, feel free to close it and point me to the related question.
Answer: http://wiki.mediatemple.net/w/Setting_up_an_email_server_in_CentOS
http://workaround.org/ispmail/etch
very useful links mayl help :)


Deploying Outlook Plugin C#

Question: I developed an outlook plugin using C# and Visual studio Outlook addin template, that retrieves data from databases and generates a report off of the data.
Plugin works perfectly fine on my local machine. But when I distribute the plugin as an executable to the users, it does not work on the user's machine.
Meaning the addin is not checked by default and even if I check it manually, it does not show up on outlook in the addin bar.
I am unable to figure out if its due to the certificates or anything else.Do I need to install any certificates on the users machine ?
Could some one please help me out ?

EDIT
I right click on the solution file in solution explorer and publish to a folder to generate the setup.exe . My other team mate uses the same steps with the same project checked out of perforce and publishes a setup.exe. Now, his plugin works as expected on the user's machine and mine doesnot work (mine works only on my machine). So, I am not able to figure out what the difference is. Because we both are using the same framework (4.0) and VS (VS 2010 premium).It has something to do with the my machine. not sure if I am missing any installation
Comment: possible duplicate of [Deploying/Installing an outlook addin](http://stackoverflow.com/questions/9172970/deploying-installing-an-outlook-addin)
Comment: Check [this](https://msdn.microsoft.com/en-us/library/ff937654.aspx) out.
Comment: as it is a possible duplicate I have added my answer in the link Avantol13 posted
Answer: Hope the following steps will help you solve this problem. I assume you are using Outlook 2013 or 2010.

Run the deployed setup with administration rights.
If it is not shown under Add-ins, again open the setup folder and double click on the correct .vsto file then select install.
If you can see your add-in among others, and is not functioning, it means your add-in is disabled. To enable it go to File -> Slow and Disabled Add-ins, and you should see your add-in on the pop-upped window. Enable it.

Edit:
If your plug-in is shown in Disabled Add-ins try applying the following steps:

Enable your plug-in by File -> Slow and Disabled Add-ins, and you should see your add-in on the pop-upped window. Enable it.
Right click on your add-in bar and select Customize the Ribbon.
Then on the pop-upped window, choose All Commands from the left hand side combo box. You should be able to find your command in the list box.
When you find your command click on the Add button between the lists. This will add your command to the chosen category on the right hand-side list. Then click OK.

Your command should appear under the chosen tab.
Comment: Tried this already but did not work. It disables the add in after the outlook start up and say even if I enable the add in, add in is not shown up.
Comment: @user2569524 can you please check if you are able to implement the new solution of mine ?
Answer: Did you have a chance to check out the Trust Center settings on the problematic PC? Are the VBA macro settings applied to COM add-ins? Is the Office application configured to load only signed add-ins?
Microsoft Office applications can disable add-ins that behave unexpectedly. If an application does not load your add-in, the application might have hard disabled or soft disabled your add-in.
Hard disabling can occur when an add-in causes the application to close unexpectedly. It might also occur on your development computer if you stop the debugger while the Startup event handler in your add-in is executing.
Soft disabling can occur when an add-in produces an error that does not cause the application to unexpectedly close. For example, an application might soft disable an add-in if it throws an unhandled exception while the Startup event handler is executing.
When you re-enable a soft-disabled add-in, the application immediately attempts to load the add-in. If the problem that initially caused the application to soft disable the add-in has not been fixed, the application will soft disable the add-in again.
Read more about that in the How to: Re-enable an Add-in That Has Been Disabled article.
Also you may find the Troubleshooting COM Add-In load failures article helpful.
Answer: How are you deploying the add-in? You need to be sure you have configured the installations settings so when you execute the installer MS Outlook knows were to find it and all of its installations components.
In my example I am using MS Project, Visual Studio 2012 with Install Shield.
Below is an example of the registry settings I use for my add-in. You will notice I have configured the manifest to point to installation directory and points to vstolocal.
You will also need to add your .vsto file to your build when constructing the installer.
Comment: Thanks for your reply. I right click on the solution file in solution explorer and publish to a folder to generate the setup.exe . My other team mate uses the same steps with the same project checkedout of perforce and publishes a setup.exe. Now, his plugin works as expected on user's machine and mine doesnot work (mine works only on my machine). So, I am not able to figure out what the difference is. Because we both are using the same framework (4.0) and VS (VS 2010 premium).It has something to do with the my machine. not sure if I am missing any installation.
Comment: If you are using VS 2010 I assume you are deploying this via the 'Setup Project' component bundled with VS 2010? Have you tried taking a copy of your teammates Setup Project, loading it into your project and try building it from his and see if it works or it you can find the missing piece?
Comment: I am not adding a separate setup project (template on other project types on VS) to my solution/project file. I right click on the solution file and choose publish from the options and it creates a setup for me.My team mate is following the same procedure to publish.

Deploying Outlook Plugin C#


Reference a filename in form validation for an image

Question: I am new to Drupal and am making a module to alter a content type. I have a content type that allows a user to submit an email and an image and I want to change the filename of the image to the email before it submits to the database. I figured I can do this in the form validation but I am having trouble finding the right code to access the filename value using $form_state. I am using the form alter hook and adding to the validation.
Answer: I think you can get value using Form API
<code>$upload = $form_state->getValue('file');
$file = File::load($upload[0]);
$file->setPermanent();
$file->setFilename('test');
$file->save();
</code>


Spring authentication with HandlerInterceptor or AbstractAuthenticationProcessingFilter

Question: What is the difference usage of spring org.springframework.web.servlet.HandlerInterceptor and  org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
I am plan to add authentication for my application.
But in HandlerInterceptor Doc it says,

In an async processing scenario, the handler may be executed in a
  separate thread while the main thread exits without rendering or
  invoking the postHandle and afterCompletion callbacks.

So in this case if handler execute in a seperate thread, i find the HandlerInterceptor in not suitable for authentication.
What would be the best way to implement authentication?
Answer: Short answer: Use Spring Security. It supports Servlet 3.x Asynchronous Request Processing out of the box. See the documentation.
Long answer: HandlerInterceptor and AbstractAuthenticationProcessingFilter may be used for the same purpose but normally in a Spring based project authentication/authorization is handled by Spring Security (AbstractAuthenticationProcessingFilter).
HandlerInterceptor belongs to Spring MVC and - what I've seen so far in my career - used for custom logging, time measurement, HTTP header manipulation or (user) request context enhancement. A HandlerInterceptor may be placed before all or a specific Spring MVC controller and "lives" within the DispatcherServlet.
In contrast, Spring Security's filter chain integrates with javax.servlet.Filter. A simplified request flow looks like this:
Container connector
         V
Filter (Spring Security)
         V
DispatcherServlet (Spring MVC)
         V
HandlerInterceptor (Spring MVC)
         V
Controller (Spring MVC)

Spring Security may be used independently from Spring MVC (Take a look at AbstractAuthenticationProcessingFilter and you can see that it derives from GenericFilterBean which in turn implements Filter). That said, you can incorporate authentication/authorization with Spring Security in any other web framework e.g. JSF, GWT, Vaadin.
Primarily, Spring Security is used in

a Java EE-based enterprise software application

but you can use it in a desktop application like Swing too. Honestly, I didn't see it so far.
In my opinion, you should rely on a matured and feature rich framework like Spring Security or Apache Shiro for authentication/authorization. Most of the time such frameworks already have all the features your project requires. A popular framework that is used by many people reduces the probability of severe bugs or security holes due to frequent bug reports and security checks. Please don't reinvent the wheel which usually can't keep up the pace in regard to software quality and flexibility of a grown framework.


Are two solutions to the wave equation equal, if they have the same absolute value?

Question:
Question. Suppose that $u_1, u_2\in C^2(\mathbb R^{d+1})$ are real-valued, satisfy $\partial_t^2 u = \Delta u$, and
  $$|u_1(t, x)|=|u_2(t, x)|, \qquad \forall (t, x)\in \mathbb R^{d+1}.$$
  Does it follow that either $u_1=u_2$ or $u_1=-u_2$?

This property holds for real-analytic functions. Indeed, either $u_1=u_2=0$ identically (trivial case), or there is $z_0=(t_0, x_0)$ such that $u_1(z_0)\ne 0$. Now, if $u_1(z_0)=u_2(z_0)$, then, by continuity, $u_1=u_2$ on a neighborhood of $z_0$, and so they coincide everywhere, because they are analytic. Otherwise, by the same argument, $u_1=-u_2$.
However, solutions to the wave equation need not be real-analytic. Instead, they satisfy the finite speed of propagation; if $u_1= u_2$ or $u_1=-u_2$ on the cylinder $\{(t, x)\ |\ |t-t_0|<a, |x-x_0|<a\}$, then the same is true on the cone
$$
\{|t-t_0|<2a, |x-x_0|<2a-|t-t_0|\}.$$
This implies that the property holds if the zero set $Z=\{u_1=u_2=0\}$ is a space-like hypersurface. Indeed, by assumption it must be either $u_1=u_2$ or $u_1=-u_2$ on either side of $Z$, but there are cones that cross $Z$, so it must be $u_1=u_2$ or $u_1=-u_2$ everywhere; see picture. However, this argument cannot be applied if $Z$ is a time-like or light-like hypersurface.
Answer: The answer appears to be negative. The functions
$$
u_1(t, x)=(t-x)^3, \qquad u_2(t, x)=|t-x|^3$$
satisfy the wave equation $\partial_t^2 u=\partial_x^2$ on $\mathbb R^{1+1}$, belong to $C^2(\mathbb R^{1+1})$, satisfy $|u_1(t, x)|=|u_2(t, x)|$ at all $(t, x)\in \mathbb R^{1+1}$. However, it is not true that $u_1=u_2$ or $u_1=-u_2$.
Remarks. The function $u_2$ is not real-analytic, and the zero-set of $u_1$ and $u_2$ is light-like. We expected that; see the OP.
More examples can be generated by taking $u_1=f(x-t)$ and $u_2=|f(x-t)|$ for suitable functions $f\colon \mathbb R\to \mathbb R$; the only requirement on $f$ is that it is odd and that it vanishes at $0$ sufficiently rapidly, so that $|f|$ is differentiable. This way, we can produce examples in $C^\infty$ with initial data of compact support.


zsh command line editor: go back to previous lines when entering a command

Question: Note that I'm NOT talking about previous lines in the history. I'm talking about previous lines in the current multiline command.
When I type a multiline command in zsh, for instance (_ indicates the cursor):
$ for i in {1..5}; do
for> echo i_

At this point I might change my mind and want to let i loop through {1..10} instead, so I need to go back to the previous line. However, I can't figure out how to do this, as ⌫, or ←, or C-b, or whatever I can think of all stops at the beginning of the second line. So, is it possible at all to move back? Thanks in advance.
In fact, this is not limited to zsh. For instance, I've never figured this out in bash either.
I've already spent a fair amount of time Googling without any findings, so please excuse me and blame my Google-fu if this is obvious.

For your reference, I'm using Emacs keybinding, and
$ bindkey | grep delete
"^D" delete-char-or-list
"^H" backward-delete-char
"^[[3~" delete-char
"^?" backward-delete-char

Not sure whether this will help.
Comment: If you want to edit multi-line commands frequently without putting them into a shell script, at least in `bash`, if you are in `vi` mode, you can type `v` to open the editor whose path is stored in `$VISUAL`. I am not sure of the equivalent for emacs key bindings.
Comment: I do not think this is possible in `bash` at least, but not sure about `zsh`. The problem is that once you have hit `Enter` after typing the first line, `bash` will remember that line but no longer accepts input from that line.
Comment: @merlin2011 Thanks for the info. I'm not very familiar with `vi` though, could you please explain "type `v` to open the editor..."? I mean, what exactly do I type to open the editor (certainly not a single `v`, is it)?
Comment: I'll write this as an answer, not because it addresses your question, but because I need multiline.
Comment: For those who vote close: this question *is* about programming, at least tangentially. Plus, there are a ton of command line editing questions on SO; better close them first if you insist.
Answer: Here is how you would visual mode in bash's vim mode.
Inside .bashrc put the following lines.
set -o vi

# I do not remember which one of these is used by `v`, so I set both
export VISUAL=/usr/bin/nano
export EDITOR=/usr/bin/nano

Reload bash, and then push Esc to go into normal mode.
Type v, and nano should load. You can now enter your multiline command into nano. When you save and exit, the multiline command will be executed.

For zsh, the following lines in your rc may do it. I stole the last three lines from this answer and tested it on my zsh.
bindkey -v
autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line

Comment: This is actually not a bad answer at all. It solves a possible XY problem.
Comment: @Qix, The problem is that he is asking about `zsh` and this describes a solution with `bash`. I guess the OP will tell us whether it helps his situation. :)
Comment: Can you find a similar solution in `zsh`? I've yet to come across something `bash` can do that `zsh` can't.
Comment: Thanks for the answer! It indeed works. I'll continue to hunt for an Emacs solution though (unfortunately Emacs is my favorite). By the way, there's a typo in the bash code: should be `export VISUAL` rather than `export $VISUAL`.
Comment: @Qix Do you know a zsh way to `export -f`? That's the first barrier I encountered after switching to zsh, and I haven't found a solution to this day. That's why I write bash scripts instead zsh scripts when I need something like GNU Parallel.
Comment: @KevinSayHi How I see it `export -f` is an ugly hack which does two things: 1. adds another attack vector (you can export a function named `echo` or `cat`!) and 2. makes it impossible to obtain values of specific environment variables directly (see output of `env` after `export -f` and try to obtain new variable with usual `$var` syntax). I think you may use `command_not_found_handler` in zsh to emulate `export -f` behavior (search for this name in `man zshmisc`) if you want, but for me `export -f` sounds like yet another argument against using bash.
Comment: @ZyX To me it's an ugly and somewhat strange but sometimes rather useful hack. I'll try to figure out the `command_not_found_handler` thing.
Comment: @KevinSayHi By the way, why do you need `export -f` for this? I just used usual subshells: e.g. [my implementation of job pool](https://sourceforge.net/p/vimpluginloader/dev-tools/ci/3e1f47879483fab32afe834cc7942b9c83ec14dc/tree/parjobs.zsh). Usage is as easy as prepending `addjob` to the command and adding `waitjobs` where you need to wait for all jobs to finish (and `kill -USR1` this script to print running jobs). This implementation was only intended to be used from scripts (specifically in testing framework), do not try it in interactive shell.
Comment: @ZyX Sorry, I didn't quite get it: why do I need `export -f` for what? I mean, I use `export -f` for [GNU Parallel](http://www.gnu.org/software/parallel/), which is a nifty perl script that does much more than parallelizing. I use it all the place as a super powerful version of `xargs`.
Comment: @KevinSayHi Parallel looks good, but it lacks some flexibility even on the tasks I use parallel execution for. I do not need some advanced features like distributed execution, but I want to configure reaction on signals and its output (--bar). By the way, I have not mentioned how to get function body in zsh: use `whence -f`, you can just literally pass it to `zsh -c`.
Comment: @ZyX Yeah, although I don't typically make use of signals, I also find some other limitations in my usage cases. But the point is it's just way better than xargs. And it's actively developed, so you can suggest features if you'd like to. `whence` looks nice (looks like it came from `ksh`? Never heard of it in bash...), I'll look into it.
Comment: @KevinSayHi AFAIR zsh developers know features of all other used shells out there. `whence` is a command that is used almost for everything `which`-related: `which` is officially an "alias" to `whence -c`, so is `type` and `where` (though with different arguments instead of `-c`). If you do not like name `whence` you can replace `whence -f` with `type -f` (`which` and `where` do not work even though `whence -cf` and `whence -caf` do work: most likely they were limited to emulate only features of other implementations, one cannot thus add `-f` just in case other implementation will).
Answer: Actually this is possible.
While on that second line, pres Esc + X in order to execute a command,
and type push-line-or-edit (note that you can use Tab key for completion)
, then press return.
The prompt will change to a traditional one ditching your for> part from
continuation line, and you will have a new buffer filled with all your
previously typed lines, which of course now you can easily edit using well
known C-a or C-b keys.
Comment: @kYuZz This is a good answer, and as I pointed out in the comment above, I've figured it out by the time the answer was posted (but the "usually bound" part is technically incorrect; it's unbound by default, but Prezto binds it to `M-q`, shadowing `push-line`). However, I deem it rude to cancel an acceptance on an answer more than a year after it was awarded. If you like this answer, just award an upvote.
Comment: Yes. And `push-line-or-edit` is usually bound to `C-q` and `M-q` (I believe), or one can set a custom keybinding using `bindkey`. (I was a total newbie to ZLE when I asked this question.)
Answer: I do not think this is possible, but here are other workarounds:

You can just write everything in one line. It is not easy to edit, but multiline strings are not easily editable either.
You can bind some key (e.g. <C-Enter> if you can tell your terminal not to output <C-m> in this case) to
function _-add-newline()
{
    LBUFFER="$LBUFFER"$'\n'
}
zle -N add-newline _-add-newline
bindkey "\Ca" add-newline

. This way if you press <C-a> newline will appear in the buffer, but it will not trigger accept-line widget and previous line will still be editable. You can e.g. use left/right arrows to move to it.
If you type for x in y ; do<CR>echo foo<CR><C-c><Up> you will see for x in y ; do\necho foo in your buffer and all text will be editable. Note: you need <CR> to preserve last line (line aborted by <C-c> is not saved) and <C-c> to abort input; this variant will not work if you have already typed done (first <CR> will run the cycle). In last case you may discard last line with <C-c> and retype it.
Theoretically you may override accept-line widget with a code that parses your input and determines whether you have written command completely and if not then it will just append \n to the buffer (like in the above function) and do not run original accept-line, otherwise original accept-line is run. This variant is much harder to implement though, so I am saying "theoretically".
Comment: Thanks for the help! Your answer is good enough for this question, and I'm accepting it. However, you know what, the question is actually kind of deceptive. Secretly the most important reason I need to go back is that sometimes I screw up by accidentally hitting the enter prematurely ;) So solution (1) is ruled out. Solution (3) is what I've been doing, which leads to a ugly command line and dirty history. (2) is very interesting (I'd point out `C-a` is already bound), but still does not prevent accidents from happening. I guess the overall answer is "no"... I'm stuck with (3).


Minimum distance in linear code

Question: Imagine I have $C (n,k,d)$ - linear code above $GF(q)$. Consider I know all words of this code.
$c_1, ..., c_M$ -- vectors from it.
If matrix H -- checking matrix (so any word from code will give zero in this way: $vH=0$ for this code will be
$H = [ c_1^t,...,c_M^t ] $
How can I find minimum distance in this code with such $ H$
Comment: From the definition of the parity-check matrix, $H$, it directly follows that the minimum distance of the code is the minimum number $d$ such that every $d - 1$ columns of a parity-check matrix $H$ are linearly independent while there exists $d$ columns of $H$ that are linearly dependent.
Comment: If you actually have a list of **all** the codewords you just need to spot a lowest weight non-zero word. But, it actually sounds like you just have a description of the code in terms of a family of check equations. The bad news are that in the **general** case the problem of finding the minimum distance is pretty much impossible. It is known that answering the question whether there are words of weight less than a given constant is NP-hard (or some other nasty category of decision problems).
Comment: Moreover, we have the result that minimum distance of a linear block code is equal to the minimum hamming weight of all the codewords generated from that linear code.
Comment: You can, of course, look for a minimal set of linearly dependent columns of $H$. Have fun checking out $\binom M d$ sets of columns :-/
Comment: @JyrkiLahtonen I actually have list of all code words. And in this question we suppose that matrix H consist of those words as well. Hm, why do I need to spot word with the lowest weight?
Comment: Oh, you are defining another code? And $M=q^k$? Sounds a bit strange. But then $c_i=(0,0,0,\ldots,0)$ for some $i$, and that check matrix automatically defines a code of length $q^k$ and minimum distance $1$. It still sounds strange.
Comment: Or are you just trying to define the dual code of the original code?
Comment: @Jyrkilahtonen no, I just have code and I know all codewords from it and in this code matrix H is given as was said above.
Comment: I am trying to find this number of independent columns in thus matrix
Comment: With the word every,  heh
Comment: You said that I need to spot word with the lowest weight in my case. Why do I need this?
Comment: Well, are you not trying to find the lowest weight word? And, if there is just one code in this exercise, namely the one defined by the check equations, then the vectors $c_i$ are not from the code.
Comment: @Jyrkilahtonen My task is to find this minimum distance $d$ in this special code which consists of M words and matrix H consist of M columns where each column is transposed codeword from the code
Comment: But what has $H$ got to do with it if you already have all the codewords? I can't make sense out of this.
Comment: @Jyrkilahtonen I think that the case if this task that I don't exactly those words. I just know that matrix H can be presented in that way.
Comment: @JyrkiLahtonen Haha, I got it. It's just about linearity of this code. So every two of codewords will sum up for the third vector from this code. So, it means that in this matrix EVERY two columns are independent, and some sets of three columns are dependent. So $d-1 = 2$.
Answer: Suppose you have a $k\times n$ generator matrix $G$ of the code. Then by elementary row operations and column permutations (which means you consider an equivalent code with the same minimum distance), the matrix has the form $G= (I\mid A)$, where $I$ is the $k\times k$ identity matrix. Then the $(n-k)\times n$ matrix $H = (-A^T\mid I)$ is a check matrix, since $GH^T=0$.  Now proceed to find the minimum number of linearly independent columns of $H$. If this number is $d-1$, the minimum distance is $\geq d$ (with equality if the code has a word of Hamming weight $d$).
Comment: Usually, the number of codewords, $M=q^k$, is much larger than the length, $n$, of the code, where the underlying field has $q$ elements.
Comment: My task is to find this $d$ in this special code which consists of M words and matrix H consist of M columns where each column is transposed codeword from the code

Minimum distance in linear code


Difference between a mixture of distributions and a convolution. Interpretation in a applied setting

Question: From what I could gather

Mixture: if $X_i\sim^{iid} f_i$, then W is a mixture with $f_W =\sum \frac{f_i}{n}$. This definition could also be for the CDF instead of the density.
Convolution: To make it simpler, lets assume if $X_i\sim^{iid} N(\mu_i,\sigma^2_i)$, then $W=\sum X_i\sim N(\sum \mu_i,\sum \sigma^2_i)$. We could write this in terms of densities.

What I don't get is the practical intuition for these definitions.
For example: We have two machines, each producing observations $X_i\sim f_i$.
If there's probability $p$ that machine 1 is chosen, how do we model our final observation $W$? As a convolution or a mixture? And what changes should we do to our problem/situation to model it as the other possibility?
Any help would be appreciated.
Comment: Convolution is for when you *add* independent variables. ("What's the distribution of the total score or both tests?"). A mixture is for when there's a chance of seeing something from *this* distribution or *that* one. Your example at the end is clearly not a sum.
Comment: @Glen_b by the way, is it usual notation for mixtures to write for example $X=0.5N(\mu_1,\sigma^2_1)+0.5N(\mu_2,\sigma^2_2)$? Is this notation also possible for sum of r.v.?
Comment: Well, no. X does not *equal* that mixture, X has that distribution, OR it's the *distribution of X*.that equals that mixture.  So you could write $X\sim ...$ or you might write say $f_X(x)=...$ if you see $N()$ as representing the density function of a normal. For a sum of random variables you write the sum in terms of the random variables. e.g. define independent $X_i\sim N(\mu_i,\sigma_i^2)$, then $Y=X_1+X_2$. In each case you're adding quite different things (a random variable is quite distinct from its density or its distribution). You have to keep straight what it is that you're adding!
Comment: In short: a linear combination of random variables is very different from a linear combination of densities or a linear combination of distribution functions. [If you wanted to add together something when you need to perform convolution, you would add the cumulant generating functions. If $Y$ and $Y$ are independent and $Z=X+Y$ (so we'd use  convolution integral to get the density of $Z$), then $K_Z = K_X+K_Y$ ... as long as the cumulant generating functions exist]
Comment: @Glen_b my mistake... I meant $X\sim$.

Thanks for the help.
Answer: The mathematical difference is simple (and you probably got that already). A mixture distribution has a density which is a weighted sum of other probability densities (often from the same class) whereas a convolution is a sum of random variables.
The intuition for a mixture can be illustrated (in line with your example) as follows: Let's say you have $k$ sensors each of which draws an independent measurement $X_i\sim f_i$ (for $i=1,\ldots,k$). Furthermore, let's say that you are only observing the measurement $W$ of one of these sensors $s$, i.e. $W=X_s$ by choosing the sensor s randomly (from $1,\ldots,k$) using a discrete uniform distribution. Then, the density of $W$ given that $s$ is known corresponds to $f_s$. Now, as $s$ is not known, we can consider all possible values for s and we obtain for the density a mixture distribution
$$f_W(x) = P(s=1)\cdot f_1(x) + \ldots + P(s=k)\cdot f_k(x)=\frac{1}{k}\sum_{i=1}^k f_i(x)$$
In the sensor example you would have a convolution if you would take all measurements (assuming them to be independent) and sum them up,i.e., $W=X_1+\ldots+X_k$. This may happen as part of averaging the sensor measurements. Then, the resulting density is
$$f_W(x) = f_{X_1+\ldots+X_k}(x) = (f_1 * f_2 * \ldots*f_k)(x)\ ,$$
where $*$ denotes the convolution operation.
Side note: For the actual averaging procedure, we would have to divide the sum by the number of sensors. That is $W=k^{-1}(X_1+\ldots+X_k)$ and
$$f_W(x) = f_{k^{-1}(X_1+\ldots+X_k)}(x) = k^{-1}(f_1 * f_2 * \ldots*f_k)(k\cdot x)\ .$$
Comment: Igor, thanks for your answer. How would we change that situation of the sensors to make it a convolution, i.e., a simple adding of r.v.? Would we *only* take *one* measurement with prob. $p_i$, instead of the the $k$ measurements in your narrative?
Comment: I just added that information to my original response.


Preventing SQL injection

Question: In Drupal 6, queries are issued with db_query(). Using %-modifiers, query arguments are substituted into the query after being filtered. Strings %s (and only strings) are ultimately run through mysqli_real_escape_string() (using db_escape_string()).
Looking at the php docs for mysqli_real_escape_string(), I see the following security warning:

The character set must be set either at the server level, or with the API function mysqli_set_charset() for it to affect mysqli_real_escape_string().

The answer to another question about mysql_real_escape_string / SQL Injection explains that:

Another way to get yourself into hot water using
mysql_real_escape_string is when you set the database connection
encoding using the wrong method. You should do this:
mysql_set_charset('utf8', $link);
You can also do this though:
mysql_query("SET NAMES 'utf8'", $link);
The problem is that the latter
bypasses the mysql_ API, which still thinks you're talking to the
database using latin1 (or something else). [...] This can be used for
injection attacks in certain multibyte string situations.

Drupal does not call mysqli_set_charset(), and instead issues the query 'SET NAMES utf8'. This can be seen in db_connect().
In order to properly protect Drupal 6 against SQL Injection, does the charset need to be set at the server level?
Answer: This answer to a stackoverflow question does a great job at explaining the attack that can get around mysqli_real_escape_string() using multi-byte character sets.
I've concluded that when running Drupal 6, we do not have to set the charset at the server level in order to be safe from the attack.
Drupal always sets the client to UTF8 (and not the GBK or BIG-5 charsets that are required for the exploit). Newer versions MySQL (> 5.1) are also not vulnerable.
HOWEVER, although Drupal is safe from this exploit, we should still follow the installation documentation which states, "The database should be created with UTF-8 (Unicode) encoding, for example utf8_general_ci.".
One helpful comment on the installation docs outlines how to create your database with UTF8 encoding, and how to ensure that UTF8 is used when performing a backup/restore:

To achieve this by the mysql command line interface use the following commands:
$ mysql -u root -p # Login
mysql> CREATE DATABASE databasename CHARACTER SET utf8; # Create with utf-8
When using mysqldump/mysql for backup/restore also force both server and client to utf8 by inserting into /etc/mysql/my.cnf:
default-character-set = utf8 # Server
skip-character-set-client-handshake # Force client

Preventing SQL injection


Is there any advantage to playing two home games versus one away game in a "tiebreaker?"

Question: The baseball season is coming to a close, and with several clusters of closely matched teams, "tiebreaker" rules are coming into consideration, especially for three teams with identical records playing for the second wild card spot.
In that case, the three teams will be designated A, B, and C, with A and B playing at A's home field, and C playing the winner in the winner's home field.
The choices are made by the teams, with the teams getting choices in (descending) order of their head-to-head record.
The "natural" choice is C (only one game to play). I can't see anyone choosing B (worst of both worlds).
But might some teams choose A (two home games to qualify) over C (one road game)? Perhaps someone with a large home media market like the New York Yankees or Mets? (Neither are candidates this year.) Or perhaps a team that plays WAY better at home than on the road?
Answer: Assuming games are purely random chance, and assuming there aren't major external factors such as the second team having a single ace starter that there is a huge advantage to avoiding, C is favored.
Chance of winning, assuming home team is 54% road team 46%:
A: .54*.54 = .29
B: .46*.54 = .25
C: .46     = .46
A and B are splitting almost-evenly the chances of the home team winning, while C gets the whole road chance.  A much better odds indeed.
As such, I'd always choose C, unless I were facing a team like the White Sox or the Indians, who have a single starter who is so far above the other starters on the team as to justify avoiding playing that starter.  Even then, their #2 (Quintana and Carrasco) aren't exactly rubes.
Answer: No, in fact you're likely a distinct disadvantage, but game theory comes into play here.
When teams A and B play, they are almost certainly going to each pitch their best starter in the game. If A wins, they are pitching their #2 starter vs C's #1.
Because home field advantage in baseball isn't a strong indicator of success Home teams only win about 54% of their games (same in postseason and regular season) at home. However, usually teams match up their best starters against each other in a playoff series.
So the first game favors team A by about 4%. Team C is going to have an advantage in the second game, even though they are the away team, because their #1 gets to go against the #2 of the team that won. Depending on the quality of team A's #2 starter, this may give team B enough of an edge to at least turn the game into a coinflip affair.
However, there is an additional consideration here. It's all about how much time passes between the tiebreaker game and the start of the first playoff series (or the wild card game). Team C might look at the matchup, and run out their #2 having confidence that he can beat the other team's #2 and save their rotation from getting out of whack in the first playoff series. This is a game theory decision and should be informed by way more math than I can pack into this little post (at least without running on for several pages and doing a lot more research that's not directly relevant here). If this happens, and we assume that #2 starters are equivalent, we're back to that 54% edge for the home team.
So, depending on how much of an impact you believe starting pitchers have on the outcome of a game (I tend to think it's a fair amount), the tie breaker situation either favors team C, but not by very much, or team A, but again, not by very much.
The reality is that playoff baseball is a crapshoot.


Multiple persons flip biased coins multiple times

Question: I've been trying to solve this seemingly easy problem for some time, but I'm not that well-versed in probability, so I thought I would ask.
Let there be $N$ persons each with identical biased coins that land heads with probability $p$ (and tails $1-p$). In each trial all persons flip their coins simultaneously and each person whose coin lands on heads is eliminated.
Then the question is the following:

What is the probability that every person is eliminated after $t$ trials?

It should be equivalent to the probability of everyone landing heads at least once in the $t$ first trials, and just ignoring that people are eliminated.
I'm also interested in the slightly different question:

What is the probability that the people are eliminated as a group in exactly trial number $t$? (In the sense that there still was at least one not eliminated in trial $t-1$, but everyone eliminated in trial $t$).

I understand that if we were simply looking at one person, we could just use the binomial distribution to calculate the probability of having one "success" in $t$ throws, but I did not know how to continue after introducing multiple people.
Thanks for any help.
Comment: Let $T$ be time of elimination. Then $P(T\le t)=(1-q^t)^N$ and $P(T=t)=P(T\le t)-P(T\le t-1)$.
Answer: You have the right analysis of the first problem.
We do the details because once we know how to solve the first problem, the second problem is easy.
The probability that after $t$ trials everybody is eliminated is the probability each has at least one head in $t$ trials, for we can imagine that even after being officially eliminated they keep flipping in another room.
The probability of at least one head in $t$ trials is $1-(1-p)^t$, so the probability they are all eliminated is $(1-(1-p)^t)^N$.
The probability that the last elimination occurs on the $t$-th trial is the probability they are all eliminated by time $t$, minus the probability they are all eliminated by time $t-1$. This is
$$(1-(1-p)^t)^N-(1-(1-p)^{t-1})^N.$$
Comment: +1. Thanks so much! Usually I would wait a little before accepting the answer, however this answers everything :).
Comment: You are welcome.


Migrate files from directory to Drupal using Migrate

Question: I have a folder with a large amount of files in. I need to migrate this into Drupals file system so I can then reference them in the content.
The ID of the file is the actual name e.g. 1234.jpg
What's the best method of doing this? I think I have the destination method set using MigrateDestinationFile()
I could write a script to create an xml document which defines every file in the folder and then extend the XMLMigration class and use that but it seems a bit overkill? Are there any source methods that would help with this?
Answer: If you are now using migrate_extras to set media as destination, you can take a look to the following links:

An useful example to import images using media as destination
A thread on drupal.org that deals a question very similar to yours
Answer: Drupal manages files on "usage" basis - files imported to it's managed files table but not used by anything will get deleted on next file garbage collector, or what it's official name is, run.
There are modules like Media supposed to act as an owners and browsers for files like that. And this one actually supports both mass import and inserting it to content, too.
This will not, however, assure you predictable ID. Hardly any solution can, as your filesystem don't know about IDs currently used in your file table, and your Drupal don't know about your filesytem. Thus, modules like Node Export only looks for an actual file name in files directory on import, and then create needed file information in system tables, letting other files to get deleted. So, if your need is one-time import, check the docs of a tool you are using for import. It should be covered there.
Comment: Thanks, I'm now using migrate_extras to set media as my destination which allows me to import the files in.


could not stat config file "slapd.conf" to add entries to LDAP

Question: I got a problem when I adding some entries in LDAP
slapadd -l /etc/openldap/root.ldif -f slapd.conf -d 10
slapadd -l /etc/openldap/people.ldif -f slapd.conf -d 10
slapadd -l /etc/openldap/testuser.ldif -f slapd.conf -d 10

and here is the error
could not stat config file "slapd.conf": No such file or directory (2)
slapadd: bad configuration file!
and
/etc/openldap/slapd.conf
include         /etc/openldap/schema/core.schema
include         /etc/openldap/schema/cosine.schema
include         /etc/openldap/schema/inetorgperson.schema
include         /etc/openldap/schema/nis.schema
include     /etc/openldap/schema/eduperson.schema
include     /etc/openldap/schema/schac.schema
include     /etc/openldap/schema/iris.schema

allow bind_v2

pidfile     /var/run/openldap/slapd.pid
argsfile    /var/run/openldap/slapd.args

database    bdb
suffix      "dc=example,dc=com"
rootdn      "cn=admin,dc=example,dc=com"
rootpw      <secretpassword>

# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory   /var/lib/ldap

# Indices to maintain for this database
index objectClass                       eq,pres
index ou,cn,mail,surname,givenname      eq,pres,sub
index uidNumber,gidNumber,loginShell    eq,pres
index uid,memberUid                     eq,pres,sub
index nisMapName,nisMapEntry            eq,pres,sub

Comment: also asked on stackoverflow: http://stackoverflow.com/q/17431577/7552
Answer: I'm going to assume that the -f argument expects an absolute path to the file and interprets the path as relative otherwise. Are you running those commands from in /etc/openldap? Does using slapadd -l /etc/openldap/root.ldif -f /etc/openldap/slapd.conf -d 10 work? Are you running the commands as a user that can read that file?
Comment: when I run the commands from in /etc/openldap
here the result
bdb_monitor_db_open: monitoring disabled; configure monitor database to enable ... I run the commands from root
Comment: That doesn't sound like an error as much as a warning to me. Does the command fail or succeed at this point?

could not stat config file “slapd.conf” to add entries to LDAP


Show table header in views (Bootstrap table)

Question: I need to show header table in a view (bootstrap table) like: title, image, descripton, etc. But i can't find the option. I compare this view to an old one and everything seems normal. Any idea? Thanks!
Comment: there is option in view i,e format you can select table or edit from backend http://www.webwash.net/drupal/tutorials/modify-content-directly-using-editable-views-module
Answer: You can check if your label of the row is enabled or checkbox is checked which shows Show Label. Go to fields in view, and click on any field, you can see that option.


Organize shows and episodes

Question: I'm moving from years after using joomla to drupal and i've hit the learning curve.
My question is below.
I want to create content like this:
Many shows
Each show has many episodes
Each show has many tags (genres)

Shows should be listable
Episodes should be listable per show
Shows should be listable per genre

It's basically a database for tv shows. But I want to hit the ground running.
I'm currently stuck with taxonomy and content types. Would a show and episode each be a content type? How can I relate them to each other?
I'm running drupal 7.x
Answer: It looks like two content types: Show and Episode. You'll want to look into the Entity reference module to relate episodes to shows. This adds an Entity reference field type. And you'll be using Term reference fields for tagging.
Comment: sweet thanks! That's exactly what I needed to know!

Organize shows and episodes