How to optimise a MySQL Game Leaderboard - Massive Subquery problems

Question: I have a huge bottle neck on my Game Server for the following query which is used to store the current leaderboard.
I am currently only calling this query via cron once every 5 mins, but would love to optimise it enough to be called every minute or when needed.
The query is taking 30 seconds and currently only ~2000 users and 7000 games played (stored in Games and TopPlayerScores). I'm afraid it will only get worse!!
Please Help me Overflow-Kenobi! Your my only hope!
SET @rank=0;
INSERT INTO Board (TopScorePKID, GamePKID, UserPKID, UniquePlayerID, PlayerName, TopPlayerScore, Position, Date)
(SELECT bad.ID AS TopScorePKID, bad.GamePKID, bad.UserPKID, bad.UniquePlayerID, bad.PlayerName, bad.TopPlayerScore, @rank:=@rank+1 AS Position, bad.Date
FROM (
    SELECT g.GamePKID, g.TopPlayerScore, l.ID,  l.UserPKID, u.UniquePlayerID, u.PlayerName, (l.Date) AS Date
    FROM Games g, TopPlayerScores l, UserDetails u
    WHERE l.GamePKID = g.GamePKID
    AND u.UserPKID = l.UserPKID
    AND u.SECRET_DETAIL = 0
    AND g.TopPlayerScore >= (SELECT DISTINCT k.TopPlayerScore AS Highest
        FROM Games k, TopPlayerScores t
        WHERE t.UserPKID = l.UserPKID
        AND k.GamePKID = t.GamePKID
        ORDER BY k.TopPlayerScore DESC
        LIMIT 1)
    GROUP BY l.UserPKID
    ORDER BY g.TopPlayerScore DESC, Date ASC)
AS bad);

Please someone help!! Should I break it up onto views? Or use Inner Join keywords? What is the best approach?
Thanks so much for even looking at this mess :D!
UPDATED 1.0 :
EXPLAIN EXTENDED Results:

id  select_type table   type    possible_keys   key key_len ref rows    filtered    Extra
1   PRIMARY   ALL NULL    NULL    NULL    NULL    1521    100.00
2   DERIVED l   ALL NULL    NULL    NULL    NULL    6923    100.00  Using temporary; Using filesort
2   DERIVED u   eq_ref  PRIMARY PRIMARY 4   DBNAME.l.UserPKID   1   100.00  Using where
2   DERIVED k   eq_ref  PRIMARY PRIMARY 4   DBNAME.l.GamePKID   1   100.00  Using where
3   DEPENDENT SUBQUERY  t   ALL NULL    NULL    NULL    NULL    6923    100.00  Using where; Using temporary; Using filesort
3   DEPENDENT SUBQUERY  g   eq_ref  PRIMARY PRIMARY 4   DBNAME.t.GamePKID   1   100.00  Using where

UPDATED 2.0:
Limited Schema for querying tables
Using the Games to store game scores and other information about a game
`Games` (
  `GamePKID` int(11) NOT NULL AUTO_INCREMENT,
  `TopPlayerScore` int(11) NOT NULL,
  `OTHER_MISC_STUFF_REMOVED` int(11) NOT NULL
  PRIMARY KEY (`GamePKID`)
)

Using the following to link the user to the Game and store the time/date
`TopPlayerScores` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `UserPKID` int(11) NOT NULL,
  `GamePKID` int(11) NOT NULL,
  `Date` datetime NOT NULL,
  PRIMARY KEY (`ID`)
)

Used to store each unique player
`UserDetails` (
  `UserPKID` int(11) NOT NULL AUTO_INCREMENT,
  `UniquePlayerID` char(40) NOT NULL,
  `PlayerName` char(96) NOT NULL,
  `SECRET_DETAIL` tinyint(1) NOT NULL DEFAULT '0',
  `isPlayer` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`UserPKID`)
)

Comment: Do you currently have any indexes on your database? Also have you looked at the query execution plan?
Comment: You should post the table schema and the indices you have defined.  What does the MySQL query analyzer say (EXPLAIN EXTENDED...).
Comment: I feel you can get some performance gain by rewriting that nested query on g.TopPlayerScore >= (SELECT... however it would help to know what you are trying to achieve in this query and by getting an idea of the table structure
Comment: Okay just getting the explain extended now, will add to the main question. 40~ seconds later :P!
Answer: The first thing I would note, although this will not improve performance is that the JOIN syntax you are using was replaced more than 20 years ago by the ANSI 92 expcict join syntax, it is entirely subject of course, but Aaron Bertrand explains some very good reasons to switch to the newer syntax.
The second thing to note is that your results will be non deterministic. You are selecting columns not contained in either an aggregate or a group by. While MySQL allows this, you are not using the feature as MySQL intended. The MySQL docs state:

MySQL extends the use of GROUP BY so that the select list can refer to
nonaggregated columns not named in the GROUP BY clause. This means
that the preceding query is legal in MySQL. You can use this feature
to get better performance by avoiding unnecessary column sorting and
grouping. However, this is useful primarily when all values in each
nonaggregated column not named in the GROUP BY are the same for each
group. The server is free to choose any value from each group, so
unless they are the same, the values chosen are indeterminate.

However, some of the columns you have included (g.GamePKID, g.TopPlayerScore, l.ID, l.Date), do not satisfy the condition are the same for each group, therefore, as stated, MySQL is free to choose whichever values it likes, and even though you have ORDER BY g.TopPlayerScore DESC, Date ASC this does not influence the single row for each group MySQL chooses.
Thirdly, MySQL has limitations with correlated subqueries and it this can hinder performance. If you can change these to JOINs you should see a performance improvement.
With all this in mind I would rewrite your query as so:
SET @rank=0;
INSERT INTO Board (TopScorePKID, GamePKID, UserPKID, UniquePlayerID, PlayerName, TopPlayerScore, Position, Date)
SELECT  bad.ID AS TopScorePKID,
        bad.GamePKID,
        bad.UserPKID,
        bad.UniquePlayerID,
        bad.PlayerName,
        bad.TopPlayerScore,
        @rank:=@rank+1 AS Position,
        bad.Date
FROM    (   SELECT  g.GamePKID,
                    g.TopPlayerScore,
                    l.ID,
                    l.UserPKID,
                    u.UniquePlayerID,
                    u.PlayerName,
                    l.Date
            FROM    Games g
                    INNER JOIN TopPlayerScores l
                        ON l.GamePKID = g.GamePKID
                    INNER JOIN UserDetails u
                        ON u.UserPKID = l.UserPKID
                    INNER JOIN
                    (   SELECT  TopPlayerScores.UserPKID, MAX(games.TopPlayerScore) AS MaxPlayerScore
                        FROM    TopPlayerScores
                                INNER JOIN Games
                                    ON Games.GamePKID = TopPlayerScores.GamePKID
                        GROUP BY TopPlayerScores.UserPKID
                    ) MaxScore
                        ON MaxScore.UserPKID = l.UserPKID
                        AND MaxScore.MaxPlayerScore = g.TopPlayerScore
            WHERE   u.SECRET_DETAIL = 0
        ) AS bad
ORDER BY bad.TopPlayerScore DESC, bad.Date ASC;

Example on SQL Fiddle
The subquery MaxScore should have the effect of limiting the results to one row per player (only their highest score), although additional logic may be required to handle ties (e.g. where the player has the same topscore in more than one game). Without knowing exact requirements I can't correct this.
EDIT
In order to remove duplicates where a player has the same top score on 2 or more games, and make it truly deterministic you need to add a further subquery:
SET @rank=0;

SELECT  bad.ID AS TopScorePKID,
        bad.GamePKID,
        bad.UserPKID,
        bad.UniquePlayerID,
        bad.PlayerName,
        bad.TopPlayerScore,
        @rank:=@rank+1 AS Position,
        bad.Date
FROM    (   SELECT  Games.GamePKID,
                    Games.TopPlayerScore,
                    TopPlayerScores.ID,
                    TopPlayerScores.UserPKID,
                    UserDetails.UniquePlayerID,
                    UserDetails.PlayerName,
                    TopPlayerScores.Date
            FROM    Games
                    INNER JOIN TopPlayerScores
                        ON TopPlayerScores.GamePKID = Games.GamePKID
                    INNER JOIN UserDetails
                        ON UserDetails.UserPKID = TopPlayerScores.UserPKID
                    INNER JOIN
                    (   SELECT  TopPlayerScores.UserPKID, MAX(games.TopPlayerScore) AS TopPlayerScore
                        FROM    TopPlayerScores
                                INNER JOIN Games
                                    ON Games.GamePKID = TopPlayerScores.GamePKID
                        GROUP BY TopPlayerScores.UserPKID
                    ) MaxScore
                        ON MaxScore.UserPKID = TopPlayerScores.UserPKID
                        AND MaxScore.TopPlayerScore = Games.TopPlayerScore
                    INNER JOIN
                    (   SELECT  TopPlayerScores.UserPKID, games.TopPlayerScore, MAX(Date) AS Date
                        FROM    TopPlayerScores
                                INNER JOIN Games
                                    ON Games.GamePKID = TopPlayerScores.GamePKID
                        GROUP BY TopPlayerScores.UserPKID, games.TopPlayerScore
                    ) MaxScoreDate
                        ON MaxScoreDate.UserPKID = TopPlayerScores.UserPKID
                        AND MaxScoreDate.TopPlayerScore = Games.TopPlayerScore
                        AND MaxScoreDate.Date = TopPlayerScores.Date
            WHERE   UserDetails.SECRET_DETAIL = 0
        ) AS bad
ORDER BY bad.TopPlayerScore DESC, bad.Date ASC;

Example on SQL Fiddle

N.B. This query will become much simpler if/when MySQL introduce analytical functions such as ROW_NUMBER(), or if you switch to a DBMS that already supports them, so just in case either of these things happen, here is a solution using ROW_NUMBER()`
SELECT  bad.ID AS TopScorePKID,
        bad.GamePKID,
        bad.UserPKID,
        bad.UniquePlayerID,
        bad.PlayerName,
        bad.TopPlayerScore,
        ROW_NUMBER() OVER(ORDER BY TopPlayerScore DESC) AS Position,
        bad.Date
FROM    (   SELECT  Games.GamePKID,
                    Games.TopPlayerScore,
                    TopPlayerScores.ID,
                    TopPlayerScores.UserPKID,
                    UserDetails.UniquePlayerID,
                    UserDetails.PlayerName,
                    TopPlayerScores.Date,
                    ROW_NUMBER(PARTITION BY UserDetails.UserPKID
                                ORDER BY Games.TopPlayerScore DESC,
                                        TopPlayerScores.Date DESC) AS RN
            FROM    Games
                    INNER JOIN TopPlayerScores
                        ON TopPlayerScores.GamePKID = Games.GamePKID
                    INNER JOIN UserDetails
                        ON UserDetails.UserPKID = TopPlayerScores.UserPKID
            WHERE   UserDetails.SECRET_DETAIL = 0
        ) AS bad
WHERE   bad.RN = 1
ORDER BY bad.TopPlayerScore DESC, bad.Date ASC;

Example on SQL Fiddle using ROW_NUMBER()
Comment: Thanks so much GarethD! I'll try this out now. Thanks for explaining everything that was wrong with the Query, my main problem was it worked and everything else I tried failed so I stuck with that old style. However WOW at the GROUP BY details! Hopefully others can learn from this as well :D! Also I would if I were you change the 'bad.' to 'good.' :)
Comment: Yeah having a few counts of a user having the same score multiple times! What can I do?
Comment: It depends on how you want to resolve this, e.g. in [this example](http://sqlfiddle.com/#!2/d2e34/1) user 1 has a top score of 11 in game 1 and game 5, which of these two games should be shown? Similarly user 2 has a top score of 20 in games 2 and 4, which of these should be displayed?
Comment: I think last played based on l.Date as the table is sorted in this manner too.
Comment: Now whole query takes 5.7421629428864s (with server loaded down too) :D instead of 30 seconds :D!!
Comment: Oh no!! Now with a userbase of 5000+ and over 25,000 Games and Highscores this is really dying again. 130 seconds to generate. I just re-designed TopPlayerScores to store the TopPlayerScore as well (now down to 30 seconds). Next optimisation is to store the best player TopPlayerScores.PKID in each user detail and update that automatically when they have a better one.


Does there exist a pole on the unit circle?

Question:
Show that a power series $\sum _{n\ge 0} a_n z^n$ where $a_n \to 0 $ as $n \to \infty  $
  cannot have a pole on the unit circle.

Is the statement true with the hypothesis that $(a_n )$ is a bounded sequence?

As $a_n\to 0$ so the radius of convergence of the power series is greater than or equal to $1$. So the power series converges on the unit disc and hence defines an analytic function say $f$  therein.
Hence the power series can't have any isolated singularity on the unit disc and hence neither can have a pole.
Though I feel the second answer is NO ,I am unable to find a counter-example
I would have been happy to find some help from someone.
Comment: Please ... it's $\sum a_n z^n$
Comment: Don't mix unit circle and unit disc.
Comment: This first part is much subtler than that: A series with your condition _can_ have a singularity _other than a pole_ on the unit circle. Consider for example $$z+\frac12z^2+\frac13z^2+\frac14z^4+\cdots = -\log(1-z)$$ which has a _branch point_ at $z=1$.
Comment: Related: http://math.stackexchange.com/questions/17932/about-the-limit-of-the-coefficient-ratio-for-a-power-series-over-complex-numbers
Comment: @zhw. Good point, but it would have been quicker to edit the question than to post your comment... :)
Answer: What you need to show is this: Let $D$ be the open unit disc. Suppose $z_0\in \partial D, r > 0,$ and $f$ is analytic on $\{z|<1\} \cup D(z_0,r).$ Suppose further that in $D,$ $f(z) = \sum_{n=0}^{\infty}a_nz^n$, with $a_n \to 0.$ Then $f$ does not have a pole at $z_0.$
Here's a hint: WLOG, $z_0=1.$ Show $\lim_{x\to 1^-}(1-x)f(x)=0.$ Could any function with a pole satisfy this?
Comment: $\lim_{x\to 1 ^{-}}(1-x)f(x)=(1-x)(a_0+a_1x+...+a_nx^n)$ ;How could you say that this limit is zero
Comment: With each $a_n=1,$ the limit is $1.$ Now what do you think happens if $a_n \to 0?$
Answer: Consider the constant sequence $a_n=1$.
(I assume the question means assume $a_n$ bounded instead of the assumption $a_n\to0$.)


What determines how hard it is to press a guitar string?

Question: When playing on different steel string acoustic guitars over the years, I noticed a huge difference in how hard it was to press down a string. This made me wonder why.
There are two obvious factors that come into play: thickness of the strings and the action of the instrument. I guess length of the neck also plays a role, however probably a minor one.
My question now is: are there more things about a guitar that influence how hard it is to press down the strings? Some things that I overlooked? And when looking for an instrument that is the easiest to play, what should I look for in particular?
Comment: The straightness of the neck has nothing to do with the tension.
Comment: You are correct about the length of the neck having a factor, but underestimate just how significant. There are "baritone" guitars with 27" scale length that exist solely for the increased tension they provide.
Comment: "The straightness of the neck has nothing to do with the tension.", yes, but it can have a lot to do with how hard it is to press a guitar string. If it's pulling forward the action will be higher, increasing the difficulty of fretting. If it's bowing backwards, the action can be improved, improving the fretting. That's basically why we adjust the relief of the neck.
Comment: in addition to these things, what also comes to mind is the straightness of the neck. when the neck is more bowed, the string tension will of course be a little less.
Answer:
String tension is probably the most important factor, dictated by the gauge and tuning mainly.
The action will affect how hard or easy the strings are to press, as a high action means further to move.
The neck itself will have some bearing on this as a deep neck uses up more of your hand thus grip. A thin neck - both back to front and side to side, will make pressing easier.
Even how you hold the guitar will affect pressure. The fingerboard angle, both to vertical and horizontal, will make a difference. Although if that attitude is the same for different guitars, you will have a direct comparison.
As you state, two guitars with different scale necks but the same gauge strings will need different pressures.
The relief in the neck- related to action- will affect pressure at different points on the neck. A closer to the fingerboard string at fret 2 will be different to press than the same string at fret 12. The tension is the same, but the distance to press may be a factor of 2 or 3.
A cambered fingerboard will probably be easier to play than a flat one.
Answer: If we read "how hard" as meaning "how much force is required to push the string far enough onto the fret that it sounds cleanly", then there are only two factors:

The tension of the string
The distance the string has to move - that is, the action.

The tension is itself a factor of three variables:

the length of the string (longer = more tension, for the same pitch and gauge)
the gauge of the string (heavier = more tension, for the same pitch and length)
the pitch of the string (higher pitch = more tension, for the same length and gauge)

So, if you want "easier" fretting, one or more of:

lower the action
use lighter strings
tune down
use an instrument with a shorter scale

However, lower tension has some disadvantages - flabbier sound, fret buzz, easy to bend accidentally.
One further factor is the wideness of the string. A very narrow string bites into your finger. A wider string distributes the force across more surface area. If two strings have the same tension, but one is thicker, the thicker one is likely to be more comfortable to press down. There may be cases where a wider string, despite needing more force to press down, is more comfortable for the finger because of its width.
Comment: @Tim Width and weight aren't the same thing. Two strings could have equal weight and tension, but one could be wider (made of a lighter material).
Comment: Yeah we're hovering between the practical and the hypothetical. Nylon is obviously lighter than steel. Other metals have different densities to steel - but AFAIK nobody's making non-wound strings from metals other than steel. And if they did, the difference would definitely be measurable, but I'm not sure it would be big enough to notice when playing.
Comment: a narrower string at the same pitch will be slightly looser, so will probably counteract the bite. The thicker one will have more tension, so feel harder. I think one will cancel the other.
Comment: true, I generalised, as say, an .010 string from a set will probably be the same material as an .014.Don't know whether there's going to be a marked difference, for example would a phosphor bronze .010 have much different tension for the same pitch/length   as a steel .010 ?
Answer: Your own findings are correct. The action is the most important factor, and thickness as well to a lesser extent.
Another noteworthy factor is the tension of the string. You'll notice that a string takes a bit more force to press down if its tension is higher.
Comment: The tension is not significantly different across the strings. They are close to balanced. There are string sets that are even closer to exactly balanced, check out D'Addario's BT series ('Balanced Tension'). The difference is  due to string geometry, simply that, all else being equal, a thicker object requires more force for a given deflection.
Comment: I also agree with your own findings, however I will emphasize that the scale of the neck DOES make a difference. Longer necks (such as the traditional 24.5" Fender) will require more tension for the same strings than a shorter scale (such as a typical Gibson 23.75" or so). The increase in total string weight requires higher tension to reach the same pitch. For instance, the signature Eric Clapton Martin has a shorter scale than many of Martin's other models; the shorter scale bends more readily.
Comment: @Fergus, I have removed that part from the answer. This still makes me wonder why the lowest strings are *easier* to press down than the others, though.
Answer: Theory notwithstanding, nearly all guitars have the same scale length, and string weights are limited to about three choices, and action has constraints limiting how low you can get it. So, in the real world we have to make some trade-offs.
Many acoustic players prefer medium action, not low. Lower the action to the cusp of buzzing, and you will limit the volume and the kinds of playing you can do without causing it to buzz. It's a trade-off. If you want really easy-to-play guitar, get an electric. On an acoustic, the goal is not to have it be super-easy to play so much as having it not be particularly difficult. A very low action will limit your dynamic range by limiting how much room the string has to vibrate -- not a big deal in some situations, especially when plugged in, but still. Talk to someone who has been playing twenty years, and super-low-action is not likely to be on their shopping list.
There is one more thing that ought to be mentioned: the quality and condition of the fretwork. We have so far assumed that the frets are all basically level with one another and are unworn. If this is not the case, it can cause buzzes even with not-too-low action.
Part of this is the curvature of the neck, and part of it is the leveling of the frets. This is normally a non-issue on all but the cheapest new guitars, but if you buy secondhand you need to look for places where the frets have worn down. That, and "sight" the neck (put your eye over the bridge and look toward the headstock, slowly tilting the guitar backward and watching the frets converge. From this angle you'll see if the frets all settle evenly behind one another, or if whole groups of them disappear behind one another (which would indicate you've got trouble.)
Note also that the action at the nut end is just as important as the action at the bridge end. If the bridge end is too high, it will be a bit tough to play but you'll get good tone and it will be forgiving of exuberant playing styles. If the nut is too high, it will be hard to play and, well, it will just suck.
So, in the end, get a decent guitar and have it set up professionally. Show the guitar to your setup guy before pulling the trigger, and make sure he says it will come out okay. He will know in a minute, just by looking it over.
If a professionally set up good quality guitar in decent condition is too hard to play, then keep playing until it isn't hard anymore.
Comment: String weight choices can vary a lot. .007 is favoured by some, up to .013 by others. A factor of nearly 100%,so I guess nearly 100% difference in tension for the same given note. This makes an incredible difference to the feel of the action.
Answer: I can't believe no other answers your final and most important question with any detail!

And when looking for an instrument that is the easiest to play, what
  should i look for in particular?

You shouldn't look solely for an acoustic guitar that is easy to play.
The play-ability of an acoustic guitar is the only thing that can be easily adjusted!
Nearly all mass produced retail guitars (including very expensive ones) are set-up terribly from the factory and  benefit greatly by a set-up from a good luthier. Any guitar, cheap or expensive, can be made to play very well provided it doesn't have any serious defects (eg warped neck, uneven frets) in which case you can return the guitar to the shop.
Buy a guitar you like the look and sound of. These are the properties that cannot be altered easily. Get it set-up by a good luthier to match your specific needs, it will be easier to play and sound even better. (see here for more info: Will a more expensive electric guitar be more consistently harmonious? )

My question now is: are there more things about a guitar that
  influence how hard it is to press down the strings? Some things that i
  overlooked?

This question is analogous to a combination of a simple beam deflection problem found in all engineering mechanics textbooks and the backpack on a cable problem found in 100 level physics texts. If you want a complete answer try physics stack exchange, All of the current answers are missing key variables. (from my comment).
This is really beyond the scope of this website but I will try to explain the basics in lay-mans terms.
A vibrating string is a physical system. Different strings (even of the same gauge) sound different because they have different material properties.
The same material properties that affect (the sound of) vibration affect how it acts under other forces such as a point load (ie fretting pressure). The main properties are stiffness and density, these properties form the specific modulus. Stiffness affects force required for deflection, density affects mass per length of the string (a value in the frequency of vibration (pitch) of a string equation).
http://en.wikipedia.org/wiki/Elastic_modulus
http://en.wikipedia.org/wiki/Specific_modulus
For a given mass per length a less dense string will have a greater area moment of inertia which affects deflection.
http://en.wikipedia.org/wiki/Area_moment_of_inertia
Which brings me to the other factor: Which fret you are fretting-
Compare the equations for a centre loaded beam and an intermediately loaded beam here:
http://en.wikipedia.org/wiki/Deflection_(engineering)#Center_loaded_beam
As a given force is moved from the mid point to the anchor points the deflection decreases.
Or in other words, the force required to fret increases nearer the anchor points (the nut and bridge). This can be demonstrated easily by bending (which like fretting, requires deflection of the string or 'beam'): Try a whole step bend at the 12th fret (mid point) and then at the first or second fret, the required force is vastly different.
There are other less important points which I've left out. If you want to understand this problem completely I suggest you do a physics or mechanical engineering degree ;-)
Answer: There's also what the string is made of. Usually nylon is really easy to press down on regardless of string thickness, but steel kills your fingers.
Answer: I was never able to play guitar because of how hard it was for my fingers to correctly hit that neck, I discovered a Keith urban guitar and the steel strings were very close to the neck,,and I promise, that helped my delicately fingers play without cramping and making my fingers sore. I'm not sure the correct term for it, but maybe if u ask a professional, they will definitely know where to steer you
Answer: Sorry all these answers are pretty much BS, its the action that's the end of it. When did you last get a tension meter out to see how a instrument feels. Lower gauge strings will help , but not that much, a thinner string will cut your fingers up if played a lot. After all quality is what you paying for on more expensive guitars, the wood and frets are harder and last longer and the action is tighter. If you have a reasonable quality instrument the action will improve as it wears in, I have a Yahama that is 40 years old and has had good use and the action is very smooth. I have another guitar of similar age, but inferior quality and the action is awful, and a complete bitch to play.
The other thing I don't think you have stopped to consider is the width of the neck as a narrow neck can make guitar with great action awkward to play, if the strings are close together it makes it suitable for only certain types of music and is partly the reason I prefer to practise on a classical guitar.
Comment: I don't have enough rep to downvote on this site, but this answer contains almost no useful information, and many pieces of incorrect information presented as fact. Look to Tim and Slim for accurate information.
Comment: Please read more carefully before lambasting !  I use .008s and my fingers have never get'cut up'. Actions don't improve as they wear in. They usually get adjusted. Not down marking, but someone will !
Comment: Action is only a part of it. Try tuning bass strings to guitar pitch, then try fretting them. Even though they could be close to the neck, their tension would make it *really* hard to press them down. Action improving with age? Action shouldn't change at all, especially on an old guitar, as changing is a bad sign that the guitar is unstable and needs inspection.
Comment: This answer is complete nonsense. Action does not improve with age; in fact, it commonly gets _worse_ with age. Truss rod adjustments are often needed as an instrument gets older and the neck moves a bit. I don't at all see how this got two upvotes, but calling out the other answers as BS is pretty cheeky.


Decision tree : handle attribute with many nominal values

Question: I would like to build a decision tree from a training data. I have an attribute with many nominal values. For example, the department name attribute has about 20-30 values.  I would like to group these values to 4-5 groups or any appropriate amount.  How can I do this (in Weka is preferable)? Should I do this in preprocessing phase or/and learning phase?
Answer: That is an interesting question. Virtually all tree growing methods (to mention just 3 classic - CHAID, CRT, QUEST) do merging of predictor categories which, as predictors, behave similarly. So, during the analysis you acquire optimal binning you ask for.
However, in CHAID or CRT [=CART] such process of category merging at each branch level is synchronous with the selection of the best predictor variable at that level. Due to this, variables with initially more categories get a handicap to be selected as a best predictor simply by chance, - because with many categories they just produce more combinatoric variants of merging which to test.
QUEST is insured against that bias and is quick. But QUEST has its own limitations (nominal DV; no ordinal IVs are usually supported; only dichotomous splitting available).
So, if QUEST won't suit you, you may do CHAID or CRT first for preprocessing, to merge categories optimally: perform analyses one at a time separately with every IV (which categories you want to merge) as either the only predictor or the predictor forced to be the first-level predictor. When you're through, and categories are merged, you may turn to the main analysis of building a tree with all the IVs.


square on the top of a square

Question:

i am stuck with a question of mensuration for three days and i posted it on facebook and asked friends but no correct solution yet.
please help .
Comment: answer is 125.44
Comment: How far have you gotten? Did you , for example, manage to determine $PQ$ at least?
Comment: Please show us your own attempts.
Comment: Please show us how far you've come with your own attempts; MSE is not "Do-My-Homework Central".
Comment: @MundronSchmidt  i have added an image of  my approach
Comment: @астонвіллаолофмэллбэрг yes. that is radius multiplied by square root of 2
Comment: i am having difficulty in determining the area of small region between the square and the circle
Comment: The length of the side of the small square is immediate from Pythagorean theorem. How come you didn't try it?
Comment: @Ennar thanks. can u tell me how to find the area of the small region between the circle and the smaller square?
Comment: I could, but why?
Answer: $(14+a)^2 + (a/2)^2=(14*2^{0.5})^2
$
From geometry...
Comment: This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/1037138)
Comment: @Taroccoesbrocco, yes it does provide an answer.
Answer: You must have $|XY|=2\cdot(|WX|/2)$, which is
$(\sin(v)-\sin(45))\cdot14\cdot\sqrt{2} = 2\cos(v)\cdot14\cdot\sqrt{2}$
Which you can solve for $v$ and substitute back into $|XY|$. Then the area is $4|XY|^2$.
Comment: which angle is v here ?
Comment: @VindhyachalVindhyachal Angle of OX relative to x-axis
Answer: Hint: Use symmetry and the Pythagoren Theorem for $\triangle AOT$, where $O$ is the center of the circle and $T$ is the intersection between $AB$ and the line through $O$ perpendicular to $AB$.
This directly gives you everything you need

square on the top of a square


The "strongest password"

Question: I have an app which is protected by a four-digit-PIN and the user got five attempts at logging in before the account is locked.
Now, one of my customers wants to "strengthen" the security and advocate for another solution:

six-digit-PIN
NO "same digit next to each other": e.g.: 113945 or 395594
NO "three-running numbers": e.g.: 123654 or 537893

Now to the question: Which solution is the strongest?
I can calculate the four-digit pretty easy, but how do I calculate the other one?
Thanks!
Update
You get what you ask for - especially when working with math :)
So, what I was asking for was the number of combinations for both number sequences.
Reading through the answers and comments it has come clear to me that it really doesn't matter. If you have 5 guesses then it doesn't matter if you have 10.000 or ~800.000 to choose from.
More important is ruling out 1234 and day of birth. In my situation, I actually have the users day of birth so I have something to check against.
Thanks for a great discussion!
Comment: Taking a historical perspective, you should acquaint yourself with the cryptanalysis of the Enigma machine. In particular, the Enigma algorithm never encrypted a letter to itself. This was thought to make it more secure by its engineers, but it had the effect of making the machine dramatically less secure. This was one of the many steps which allowed the Allied Powers to break Enigma. I'm not an expert in crypto by any means, but the general notion is that you want your keyspace to be as large as possible.
Comment: Theoretically---if you are focused solely on brute force attacks---more possibilities means more security so restrictions such as the no-same-digit or no-runs-of-3 reduce the number of possibilities thus they are strictly weaker. However, practically (as user777 touches on) people aren't choosing random pins. If the users are lazier than they are paranoid, many of them may choose pins such as "000000" or "123456", which then makes things less secure.
Comment: I think this belongs on [crypto.SE], not here.
Comment: Casper, please clarify -- are you primarily concerned about it as a security issue (e.g. there's considerations related to more than just probability), in which case it may be a better fit elsewhere -- or are you asking a primarily probability question (which fits here)?
Comment: I am voting to (temporarily) close this question as unclear, on the grounds that the OP's intentions are not yet obvious. I'd really prefer to see @Glen_b's question answered, so we know whether this should be treated as a combinatorics/probability question or as something that is better migrated.
Comment: This is **not a statistical issue**, you should asked this question rather on: http://security.stackexchange.com Most password cracking software **will not** do simple brute-force attack (try all the possible combination of numbers) but will take into consideration commonly used passwords and patterns (letters near by on keyboard, letters on extreme ends of keyboard) etc. so the only password that is secure is **long and truthfully random** or at least **long and unguessable** (e.g. "correct horse battery staple", c.f. https://xkcd.com/936/)
Comment: I think it's probably a question about crypto, but I think that this can be framed out as a probability question. If OP is concerned about security practices more than the mathematics, then it should be migrated. Otherwise, I think it's a great way to get neophytes to think about combinatorics.
Comment: But the 5-try-then-lockout rule would highly mitigate the risks of a brute-force attack, so additional steps to mitigate that attack seem mostly pointless. I agree with Gregor that the larger hazard, given the lockout policy, is lazy users.
Answer: You've asked a statisticians forum for help on this question, so I'll provide a statistically-based answer. Thus it's reasonable to assume you're interested in the probability of guessing a PIN at random (for some definition of random), but that's reading more into the question than is provided.
My approach will be to enumerate all possible options without restricting, then subtract the void options. This has a sharp corner, to it, though, called the inclusion-exclusion principle, which corresponds to the intuitive idea that you don't want to subtract the same thing from a set twice!
In a six-digit PIN with no restrictions and a decimal number system, there are $10^6$ possible combinations, from $000 000$ to $999 999:$ each digit has 10 options.
Consider what "two adjacent, identical" digits looks like: $AAXXXX$, where the positions labelled $A$ are the same and $X$ can be any decimal digit. Now consider how many other ways the string $AA$ can be arranged in six digits: $XAAXXX$, $XXAAXX$, $XXXAAX$, and $XXXXAA$. So for any particular ordering (one of those options), there are at least $10^4$ combinations, since there are $10^4$ digits without restriction. Now, how many choices of $A$ are there? We're working with decimal digits, so there must be 10. So there are $10^5$ choices for a particular ordering. There are five such orderings, so there are $5\times10^5$ arrangements that satisfy this definition. (What this means in terms of security might be measured in terms of an information-theoretic measure of how much this reduces the entropy of the PIN space.)
Now consider what consecutive numbers look like. In the string $ABCXXX$, if we know A, we also know B and C*: if A is 5, then B is 6 and C is 7. So we can enumerate these options:

012XXX
123XXX
234XXX
456XXX
789XXX

and at this point it's unclear if there's a "wrapping around." If there is, we also include

890XXX
901XXX

Each solution has $10^3$ associated combinations, by the same reasoning as above. So just count out how many solutions there must be. Keep in mind to count alternative orderings, such as $XABCXX.$
Now we get to the sharp corner, which is the inclusion-exclusion principle. We've made the set of all six-digit PINs into three sets:
A. Permissible PINs
  B. Void PINs due to "adjacent digits"
  C. Void PINs due to "sequential digits"
But there's an additional subtlety, which is that there are some 6-digit numbers  which can be allocated to both $B$ and $C$. So if we compute $|S|=|A|-|B|-|C|,$ we're subtracting out those numbers twice, and our answer is incorrect. The correct computation is $|S|=|A|-|B|-|C|+|B\cap C|,$ where $B\cap C$ is the set of elements in both $B$ and $C$. So we must determine How many ways can a number fall in both $B$ and $C$.
There are several ways this can occur:

$AABCXX$
$ABCXDD$
and so on. So you have to work out a systematic approach to this as well, as well as a way to keep track of alternative orderings. Using the same logic that I've applied above, this should be very tractable, if slightly tedious. Just keep in mind how many alternative ways there might be to satisfy both B and C.

Slightly more advanced approaches would take advantage of basic combinatoric results and the fundamental theorem of counting, but I chose this avenue as it places the smallest technical burden on the reader.
Now, for this to be a well-formed probability question, we have to have some measure of probability for each arrangement. In the assumption of a naive attack, one might assume that all digit combinations have equal probability. In this scenario, the probability of a randomly-chosen combination is $\frac{1}{|S|}$ If that's the kind of attack you're most interested in preventing, though, then the proposed set of criteria obviously weakens the system, because some combinations have are forbidden, so only a dumb attacker would try them. I leave the rest of the exercise to the reader.
The wrinkle of "five until lockout" is decidedly the better guard against unauthorized access, since in either the 4-digit or the 6-digit scheme, there are a very large number of options, and even five different, random guesses have a low probability of success. For a well-posed probability question, it's possible to compute the probability of such an attack succeeding.
But other factors than probability of sequences of numbers may influence the security of the PIN mechanism. Chiefly, people tend not to choose PINs at random! For example, some people use their date of birth, or DOB of children, or some similarly personally-related number as a PIN. If an attacker knows the DOB of the user, then it will probably be among the first things they try. So for a particular user, some combinations may be more likely than others.
*The sequences you list are strictly increasing, and it's unclear whether both increasing and decreasing when you say "three-running number."
Answer: Obtaining a closed formula seems complex. However, it is quite easy to enumerate them. There are 568 916 possible codes for the second solution. Which is bigger than the number of solutions with a four digit PIN code. The code to enumerate them is below. Though not optimized, it only takes seconds to run.
Note. I assumed that the sequence had to be in increasing order (which can be easily modified in three_running)
N = 999999

candidates = range(N)

def same_consecutive_digits(x):
    x_string = str(x).zfill(6)
    for i in range(1,len(x_string)):
        if x_string[i] == x_string[i-1]:
            return True
    return False

def three_running(x):
    x_string = str(x).zfill(6)
    for i in range(2,len(x_string)):
        if int(x_string[i]) == int(x_string[i-1]) + 1 and int(x_string[i-1]) == int(x_string[i-2]) + 1:
            return True
    return False

def valid(x):
    return not same_consecutive_digits(x) and not three_running(x)

assert(same_consecutive_digits(88555))
assert(same_consecutive_digits(123))
assert(not same_consecutive_digits(852123))
assert(three_running(123456))
assert(not three_running(4587))
assert(valid(134679))
assert(not valid(123894))
assert(not valid(111111))
assert(not valid(151178))
assert(valid("031278"))

accepted = [i for i in range(N) if valid(i)]
print(len(accepted))

Comment: Implicit in the code, but not in your description, is the assumption that PINs will never begin with the digit "0".  That's not usually true of PINs or passwords.  The correct answer, allowing for such zeros, is 568,916.  Let's bear in mind, though, that the *relevant* answer would consider that attacks on the PIN in this constrained problem can be made much more efficient by exploiting the constraints, implying that this mere enumeration of the possibilities does not adequately represent the "strength" of the system, as pointed out in comments to the question.

The "strongest password"


How to create a share folder for multiple domains on Dreamhost

Question: I have a Virtual Private server with Dreamhost.  I'm trying to create a shared folder that all of my domains can access. In the folder I'd like to put PHP classes, and even static files like javascripts.
I've created a directory on the same level as my domain folders.  I'd like to call a file via something like this... /home/username/shared/file.php. This isn't working however for static files, and I'm hoping some magic (like .htaccess maybe) will make this work.
This works:
<?php include('/home/username/shared/file.php'); ?>

This doesn't work:
<link rel="stylesheet" type="text/css" href="/home/username/shared/reset.css" media="screen" />

Alternatively, I realize that I could just place my static files inside of a domain, and simply point to them, but I'd like to know how to make this other configuration work.
Answer: You will never be able to include a server path-based file in an HTML file like that because the path is outside of the scope of public_html.
I know what you're trying to do, but I honestly don't think it's easily accomplishable. Why not just set up a subdomain on a 'master' domain from which all domains source the files? Less desirable perhaps if you're going for the perfect SEO (because I believe it's technically classed as cross-domain referencing) but having certain globally-required files (images etc) on files.primarydomain.tld works very nicely for me.
Also given the way Dreamhost handles different users' files, it can be a real pain. Probably best with their setup to just set up one username with one subdomain and have it handle just the global files, particularly as if you have one username per site, that username won't have filesystem permissions to access files held in another username's directory. (and .htaccess-mod-rewrite based rules will just be digging a hole for yourself, even if it is possible!)
Comment: Yeah, S3/Cloudfront is probably more desirable for what you're trying to achieve - having gone through many hours of pain trying to wrestle this setup out of Dreamhost, and failing dismally, I hope nobody else has to put themselves through the same pain! Dreamhost really is bloody annoying, you can have files in /public_html/subfolder/ uploaded by two usernames - and of course, in true Unix style, one username can't see the other files (nor can it serve them in public). UNIXy behaviour is great except when it gets in the way ¬_¬ It's impossible to reassign ownership too, really frustrating.
Comment: Also, I guess if I put them on a service like Amazon S3 / Cloudfront it would essentially accomplish the same thing plus give me the benefits of a CDN.  The main reason why I asked was because I am coming from a LAMP environment with Coldfusion, and I was able to perform the above methods to get to static files.  Then again, these were Private Servers (not through Dreamhost), not Virtual Private Servers.  Thanks for the input.
Answer: Use a Symbolic Link (symlink).
I originally asked this question on StackOverflow (I didn't know about this site yet), and it has now been answered.  The answer and explanantion can be found HERE


How to set a pending Rollback on a Transaction?

Question: I've been working with MySQL Transactions to encapsulate the several read/writes that execute throughout my method.
private void ReceiveOrderConfirm(object sender)
{
    Db.BeginTransaction();
    //succeeds
    Thing1();

    //canceled by user
    Thing2();

    //succeeds
    Thing3();
    Db.CommitTransaction();
}

So here's my example situation, simplified for clarity's sake.
I've got a method which does several things inside of it, occassionally passing off control to other methods to execute and return. All three of these methods don`t error in this example. but the user is given the option to press a Cancel button in Thing2(). Right now if I were to just simply call a Rollback on my transaction when the user presses cancel, then Thing3 will execute and succeed, being automatically wrapped in it's own new trasnaction that autocommits.
My question is, is there a way to set a condition that will automatically fail the commit when it is attempted at the end of all three of these methods. So that they all rollback together, as opposed to simply the first half.
Answer: You could let Thing2 return a bool for success:
if (Thing2())
{
    //
    // success, continue
    //
    Thing3();
    Db.CommitTransaction();
}
else
{
    //
    // cancelled, rollback
    //
    Db.RollbackTransaction();
}

Comment: This is what I was thinking of as well, but I was hoping for a more overarching solution that I could append to the cancel command or use in a broader scope of scenarios. I'd have to do this in many places throughout the system.


iSCSI initiator cannot remove session on boot drive

Question: I'm very new to iSCSI so forgive me if I use the wrong terminology.
I have two nics on my host with IP addresses that can see my iSCSI device (DELL MD3200 if it matters).
We are booting the system off the SAN itself using the broadcom NIC's iSCSI initiator.
I was trying to set up the multipath IO in the Microsoft iSCSI initiator software but I made a mistake and added a copy of the same connection.
So I have multipath working, but I have two paths which are the same nic to same controller (3 sessions in total).
I would like to remove the session (by clicking on the target, selecting the session and click disconnect.  However as this is part of the MPIO for the c:\ I receive the error: The session cannot be logged out since a device on that session is currently being used.
As this is the c:\ for the server I cannot disconnect the target.  I have tried rebooting and windows recreated the duplicate session.
Is there any way to remove the session before the system boots or do you know some other way to get rid of it?
Answer: Since you're using iSCSI boot, the NIC should have some type of configuration menu available at system startup that can be accessed via a key combination.  You would need to modify your connections via this setup interface, since you can't drop the connection once it's in use.
Comment: Makes sense.  Edit the bootup, change it to use a different path, this will then reset the MPIO connections allowing me to drop them for C:\.
Answer: Just for prosperity, in the MD3200 Modular Disk Storage Management:
Open the Array.
Under the window that opens:
Storage Array -> iSCSI -> End Sessions
This allows you to remove any session to the iSCSI controllers.


How can I draw multiple vertex array on a single draw call in OpenGL?

Question: I want to simulate a bunch of balls' movement. These balls are rendered as 12 vertices with GL_TRIANGLE_FAN. In my design, every ball object maintains an array of its own vertices attributes. However, every time I invoke glDrawElements, it only draws one Vertex Buffer Object. 1000 balls need 1000 draw call. It's not efficient. If I draw points instead of triangle fan, I could draw it as follow:
class Ball
{
public:
    GLfloat x, y;
    // ...
}

Ball balls[] = {Ball(100, 100), Ball(80, 120), ...};

void display()
{
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT, sizeof(Ball), 0); // stride

    glDrawArrays(GL_POINTS, 0, vertex_num);
    //...
}

With stride parameter, I could 'choose' x, y from balls array and skip other members. I wonder how could I do the same thing when every object maintain an array of vertex attributes? Or I should extract all vertex attributes and combine them into a single VBO? But it needs extra code to maintain it and increases the coupling.
Answer: If all the objects are (exactly or mostly) the same, you should look into "instanced" rendering or drawing (i.e. glDrawArraysInstanced, etc.)
If your objects are mostly different and mostly dynamic but have the same render state (textures, shaders, etc.,) and you can use OpenGL 4+, you should use "multi-draw indirect" facilities (i.e. glMultiDrawArraysIndirect, etc.) Note that the version requirement is a little tricky, when considering all the prior extensions, etc.
If your objects are not the same but are static, you should combine them into one (or a few) objects and draw those. This will need more code and will result in less flexibility, and you have to figure out whether it's worth the performance benefits or not.
If none of the above fits (i.e. your objects are all different, very dynamic, and you can't use modern OpenGL,) then you don't have any easy ways to improve your drawing efficiency. You'll probably need to employ ubershaders (actually, very few shaders that do everything), texture arrays (or bindless texturing) and other tricks.


Copying internal formats float64 uint64

Question: I'm using Numpy and Python. I need to copy data, WITHOUT numeric conversion between np.uint64 and np.float64,  e.g. 1.5 <-> 0x3ff8000000000000.
I'm aware of float.hex, but the output format a long way from uint64:
In [30]: a=1.5
In [31]: float.hex(a)
Out[31]: '0x1.8000000000000p+0'

Im also aware of various string input routines for the other way.
Can anybody suggest more direct methods? After all, its just simple copy and type change but python/numpy seem really rigid about converting the data on the way.
Answer: Use an intermediate array and the frombuffer method to "cast" one array type into the other:
>>> v = 1.5
>>> fa = np.array([v], dtype='float64')
>>> ua = np.frombuffer(fa, dtype='uint64')
>>> ua[0]
4609434218613702656      # 0x3ff8000000000000

Since frombuffer creates a view into the original buffer, this is efficient even for reinterpreting data in large arrays.
Comment: From Rob Potter Thanks - looks good for large data arrays (which we'll get to some time after detailed logic design. Random number testing si great fun (when it works).
Answer: So, what you need is to see the 8 bytes that represent the float64 in memory as an integer number. (representing this int64 number as an hexadecimal string is another thing - it
is just its representation).
The Struct and Union functionality that comes bundled with the stdlib's ctypes
may be nice for you - no need for numpy. It has a Union type that works
quite like C language unions, and allow you to do this:
>>> import ctypes
>>> class Conv(ctypes.Union):
...   _fields_ = [ ("float", ctypes.c_double), ("int", ctypes.c_uint64)]
...
>>> c = Conv()
>>> c.float = 1.5
>>> print hex(c.int)
0x3ff8000000000000L

The built-in "hex" function is a way to get the hexadecimal representation of the number.
You can use the struct module as well: pack the number to a string as a double, and unpack it as int. I think it is both less readable and less efficient than using ctypes Union:
>>> inport struct
>>> hex(struct.unpack("<Q",  struct.pack("<d", 1.5))[0])
'0x3ff8000000000000'

Since you are using numpy , however, you can simply change the array type, "on the fly", and manipulate all the array as integers with 0 copy:
>>> import numpy
>>> x = numpy.array((1.5,), dtype=numpy.double)
>>> x[0]
1.5
>>> x.dtype=numpy.dtype("uint64")
>>> x[0]
4609434218613702656
>>> hex(x[0])
'0x3ff8000000000000L'

This is by far the most efficient way of doing it, whatever is your purpose in getting the raw bytes of the float64 numbers.
Comment: Thanks, Looks good. Purpose is design verification for logic design of high performance div, log, exp functions etc. Who loves IEEE 754?

Copying internal formats float64 uint64


Views caching dont show changes

Question: I'm having a problem with views and caching. Within a custom module, i do changes on my database, which is working fine, but my view won't show that changes until I clear all caches.
I tried to deactivate views-caching here "admin/structure/views/settings/advanced"
Caching in the view is deactivated too
And the whole caching is deactivated here "admin/config/development/performance"
But I still have to clear all caches on every change I make to see what I did. Is there a chance to stop caching for that view by code in the module? Or any other possibility?
EDIT: I now tried a module called "CacheExclude" and
<code>$GLOBALS['conf']['cache'] = 0;
drupal_page_is_cacheable(FALSE);
$conf['cache'] = FALSE;
</code>
but no change :(
EDIT 2:
Here is the code where I change the field in the database:
<code>foreach($books as $book) {
    $query = db_update('field_data_field_zuordnung')
        ->fields(array(
            'field_zuordnung_value' => 'verkauft',
            ))
        ->condition('entity_id', $book->product_id, '=')
        ->execute();
}
</code>
The change is done in the DB, but it isn't shown in the view. After that, I use drupal_goto to move to a "you're done site".
Comment: You might want to give a bit more detail of what your module does so we can maybe thing of other reasons you are facing the problem.
Comment: I am changing a custom field. In the first place I have a variable in that field, after my action, this variable changes. But this change is only visible after I clear my cache. I'm putting some code into the question.
Answer: You should ideally be using the Field Attach API to avoid these problems.
Or for a quick solution have a look at field_attach_update where at the end of the function, it clears the field cache:
<code>$entity_info = entity_get_info($entity_type);
if ($entity_info['field cache']) {
  cache_clear_all("field:$entity_type:$id", 'cache_field');
}
</code>
Comment: +1 If you don't use the API then relevant hooks won't be invoked which might break functionality provided by other modules (now or in the future).

Views caching dont show changes


List only queue id in mailq

Question: mailq lists a bunch of information relating to the queue:
C999C20A80    8314 Sun Dec 24 21:19:18  MAILER-DAEMON
(host abc[x.x.x.x] said: 421 Timeout - closing connection (in reply to MAIL FROM command))
                                         a@a

How do you print only the QUEUE ID without processing it with various grep|awk|sed?
I'm certain I saw a command for it but I didn't "register" it and now I forgot it.
Maybe something with postsuper or postqueue, but reading the man pages I cannot see any options for this.
Comment: sudo find  /var/spool/postfix/deferred/ -type f ?
Comment: yes, I know about that, I'm trying to find out what's the "correct" way to do it, without such workarounds
Answer: I don't know about the 'right way to do it'
but for me works
mailq | awk '$7 ~/@/ { print $1 }'
this will display only the id's

List only queue id in mailq


"add content" suddenly not showing on navigation block anymore

Question: Good day,
I'm having a problem of a block not showing its content!
the block is stock and called navigation, which has "add content" in its links.
but just recently, it has not been working on other users except admin.
i checked it setting, and the access control says: "authenticated users" which is good.
but the moment i check it at other users (the non admin), i can only see the navigation block with "chaos Ajax demo" ONLY..
i checked around possible permissions, link settings, but with no luck..nothing seemed strange to me..
here's a screen shot of the navigation block at admin:

and here's 2nd shot at non admin (was working and showing few days back, but then suddenly became like this):

logically speaking, since the navigation block is existing at other users only means that its permissions is allowed for users to see the block.
but why suddenly it stopped showing the links?? im very much concerned about "add content" link, because i need it to add contents (otherwise, i'll have to go through a headache of creating 10s of manual links for each content to add).
let me note that I'm quit new to drupal, that's why I'm not pretty sure what did i mess with here.
any help is very appreciated, Thanks
Answer: First a clarification about terminology: make sure to correctly separate access to "blocks" from "navigation links": your non admin users seem to have access to that "block" also (that Ajax link in it proofs that to me). Your real issue/question should be something like "why are some of the menu links missing in that block?".
Seems like you need to resolve that "Access Denied" message first. Even though it's hard to tell (from the screenshots provided), My best guess would be that you need to review/tune some of the settings related to "node" within admin/people/permissions.
So check/confirm that for the users who receive this "Access Denied", they are granted the permission like "View Published Content". If that permission was not granted yet, then do so now and try again to see what happens.
A few more "comments" (moved from the comments below to around here):

The "menu items" that are shown in that block, will be shown (only) to the users who have access to the actual content (node) that the menu items are related to. And apart from that there is the "block visibility", which is typically something you "can" set so that it is only shown (or hidden) on specific pages, or so that it is only shown to users with specific roles.
About "I didn't want every user to other users' published content": looks like there is something you mis-interprete about the "View published content": that permission is ONLY a way to tell Drupal "which roles are allowed to see anything (nodes) that have the "published" checkbox turned on. It seems to me that you MIGHT need to add something like the (great!) "Content_Access" module to implement something similar to what you wrote in one of your last comments.
If it makes sense, you should set the "default" content access for each content type first, so that you only have to change it for those nodes where you want content access to be different from that default. So no need to "go through every content to manage their content access".
Comment: what on earth?  my salute for @Pierre !!
i very surprised, how come not giving access to view publish content was affecting the navigation menu, i mean shouldn't they be not related? because i didn't want every user to other users' published contents.
Comment: First things first: no need for "sir" around here, just "Pierre" is fine, ok?
Comment: no problemo..
yes, i guess thats the issue im wondering about..how do separate the access to blocks for the links themselves?
Comment: ooh, i see!! ..yes i do understand, i just knew about the content access recently actually (in my previous question about the admin restriction reasons)..
i just tested what u advised, and it worked!! it seems that i have to go through every content to manage their content access control and make them "view own content only" .. my issue is addressed to the bulls' eye! thank you very much. :D


Erro para configurar Wordpress multisite

Question: Eu instalei o wordpress em um servidor, e funcionou tudo certinho, entretanto quando tento adicionar a função:
define('MULTISITE', true);

Todas as páginas aparecem o seguinte erro:

"Erro ao estabelecer uma conexão com o Banco de Dados"

Aparentemente o wordpress não está criando algumas tabelas necessárias, mas é uma instalação nova e quando comento a linha do multisite ele funciona normalmente.
Answer: Já consegui solucionar, na verdade estava seguindo um tutorial que não estava certo, foi necessário adicionar apenas o seguinte código inicialmente:
define('WP_ALLOW_MULTISITE', true);

E executar a instalação pelo painel de admin Ferramentas -> Instalação de Rede, e ai sim colar o texto que ele gera, que tem a instrução de define('MULTISITE', true);


Issue with Laravel Symbolic Links

Question: I have specific folder for each user inside storage/app/public.
I'm dynamically changing the public_path as:
$storageConfig = Config::get('filesystems.disks.public');
$storageConfig['root'] = storage_path('app/public/').$userString ;
config()->set('filesystems.disks.public', $storageConfig);

When a user uploads his photo, it will get saved in the path
storage/app/public/$userString/profile_pictures

I used the php artisan command to create the link:
php artisan storage: link

But I have this issue while displaying images.
Using symbolic link, images are displayed as:

Images are not loading . What can be the issue? Can someone help?
Comment: What if you do this: ``
Comment: @Ahsan this is not working
Comment: Are you changing the path in a middleware?
Comment: @SérgioReis yes
Comment: In your .blade what does it output if you try this `{{Storage::disk("public")->getDriver()->getAdapter()->getPathPrefix()}}`
Comment: @SérgioReis it points to the user folder :storage/app/public/$userString/
Answer: To call images from storage you should use the built in helper:
e.g.

see here
This will work after having used php artisan storage:link
Comment: updated, is the link correct in the source generated?

Issue with Laravel Symbolic Links


O Node no mundo .NET seria o CLR ou o .NET?

Question: Tendo em vista que o Node é uma plataforma de desenvolvimento server-side em JS... e no .NET nós temos o CLR (Common Language Runtime) o Node seria o CLR que compila? Ou um framework como .NET, como dois importam módulos eu fiquei bem confuso quanto a essa questão.
Answer: A pergunta está formulada de uma forma que não reflete a realidade.
De certa forma podemos comparar a plataforma .NET com o Node.js. A plataforma envolve uma série de coisas.
O CLR é o runtime, algo que o Node tem também, então acho que CLR está para o V8 do Node.
Na verdade, a plataforma .NET é um padrão e existem várias implementações. Até onde sei o Node só tem uma, mesmo o Deno não é compatível.
De fato o compilador do .NET não faz parte do CLR. Nas implementações mais comuns do .NET o mais comum é usar o .NET Compiler Platform. O Node pega o fonte e JITta diretamente. O CLR tem um JITter também, mas parte de um código previamente compilado.
Outro componente importante da plataforma é a FCL.
Outros componentes podem ser opcionais, como ocorre no Node também.
A questão dos módulos não está clara, acho que cabe uma pergunta específica com mais detalhes da dúvida. Mas acho que há semelhanças, o .NET obtém com Nuget e o Node com NPM.
Comment: Essa foi a minha duvida... eu fiquei tão confuso que nem sabia como expressar ela...


A question about rings, true or false statements

Question: Let R be a ring such that $x^2=x$ for each x in R. Which of the following must be true?
I‐ x= ‐x for all x in R.
II‐ R is commutative
III‐ xy+yx=0 for all x in R
I know that for R to be a ring there are three conditions that must be met. They are:
1)[A,+] is an abelian group (i.e. its commutative)
2)multiplication is associative in A, and
3)multiplication is left and right- distributed over addition.
Therefore I know by definition that II is correct, but need help figuring out if I and III are correct.
Comment: Your belief about II is mistaken, as whoever asked you this probably means that the *multiplication* is commutative, which is not true for rings in general.
Answer: If $x\in R$, then
$$2x=(2x)^2 = (x+x)^2 = (x+x)(x+x) = x^2 + x^2 + x^2 + x^2 = 4x^2 = 4x$$
hence $4x=2x$, so $2x=0$.

Thus, $2x=0$, for all $x\in R$.

Equivalently, $x=-x$, for all $x\in R$.

If $x,y\in R$, then
$$x+y = (x+y)^2 = (x+y)(x+y) = x^2 + xy + yx + y^2 = (x + y) + (xy + yx)$$
hence $xy+yx=0$.

But also, since $yx=-yx$, we have
$$xy-yx=xy + (-yx) = xy+yx =0$$
so $R$ is commutative.
Comment: How did you go from $ 4x^2 $ to 4x in the initial steps?
Comment: Since $x^2=x$, we get
$$4x^2 = x^2+x^2+x^2+x^2 = x + x + x + x = 4x$$
Comment: Thank you! Did you also do this for the third statement?
Comment: Which statement?
Comment: For the line $x^2 $ + xy +yx + $y^2$ = (x+y) + (xy+yx)
Comment: For any expression $u$, we can always replace $u^2$ by $u$.


Runners at first and third. Why not steal?

Question: Let's say there are runners on first and third with no outs. If the runner on first attempts to steal I see two outcomes:

The catcher does not throw to second. The runner advances.
The catcher throws to second, the runner on third steals home. The runner from first might not make it in time and be out, but a run scored.

This seems to be a win-win, so why don't teams try to steal in this situation very often?
Comment: Giving up an out for a run is not necessarily a win.
Answer: Thrown baseballs move a lot faster than people. The ball will get to second and then back to home again before the runner from third can make it home, particularly as the runner on third has to delay starting until the catcher has thrown the ball to second at all.
Answer: This is not materially different than the accepted answer, just some more elaboration.  In a nutshell, the options you listed are not the only possible outcomes.
The runner at third has to wait for the throw to be released by the catcher, or he/she risks the catcher not throwing to second and instead getting the lead runner in a rundown or tagged-out situation at third.  So, if the runner leaves early, you get a runner on second, no runner on third, and another out.  That's, objectively, worse than 1st and 3rd without the added out.
So, let's say the runner waits for the throw, that gives them less of a jump for the run to home plate.  Sometimes the fielder covering 2nd base doesn't even try to tag the runner, and comes straight home with the throw, getting the runner out, with the same result as if the runner left early and got caught.
If the catcher's throw is perfect, the tag for the out at second can be applied and the fielder can be up and throwing home in almost the same instant, then you have both players caught stealing, two more outs, and no one on base.
Sometimes (less common) the catcher even throws the ball on a low trajectory and the pitcher will intercept it if he sees the player at third breaking on the throw, much like a cut-off man with a throw from the outfield.
All of these scenarios have happened during regular play.
Comment: It also depends on what level you play at. This was almost a mandatory play in Little League, where the chances of getting either a run or runners on 2nd and 3rd were extremely high.


average of pairs sitting next to each other - exoected value

Question: At the film screening "for the singles" spóźniło 15 singles: 8 men and 7 women. Since it is already dark, and latecomers do not want to disturb others, all randomly sit in the first row, which has 16 seats (so one too much). How much will the average male-female couples sitting next to each other?
My attempt:
$X$- - the number of pairs (girl+boy( sitting next to each other )
$X_i$ - the number of such settings that accurately and couples sitting next to each other
$EX = EX_0 + EX_1 + ... + EX_{14}$
All settings is $N = 8\cdot {16\choose 8  }$
Every setting is is equally likely, so:
I can't compute number of settings that we have $i$ pairs.
Could help me, please  ?
Answer: Each couple takes two seats chosen at random. There are $15$ pairs of contiguous seats and ${16\choose2}=8\times15$ pairs of seats hence each man-woman couple is seated next to each other with probability $\frac18$. There are $8\times 7$ man-woman couples hence the mean number of man-woman couples seated next to each other is $8\times7\times\frac18=7$.
For $w$ women and $m$ men seating on $s\geqslant w+m$ seats, the mean number of man-woman couples seated next to each other is $2\times w\times m\times\dfrac1s$.
Answer: There are 2 chances in 16 that the spare seat is at the end, with 14 places for boy/girl pairs.
There are 14 chances in 16 that the spare seat is not at the end, and 13 places for boy/girl pairs.
Given a pair of people there is (8*7+7*8)/(15*14)=8/15 chance they are boy/girl.
With 14 places, I expect 14*(8/15) boy/girl pairs.  With 13 places, I expect 13*(8/15) pairs.
Overall, I expect (2/16)(14*(8/15))+(14/16)(13*(8/15)) pairs.
Let A be the situation with a spare seat at the end, and B have the spare seat elsewhere.
$E(X_i)=8/15$
$E(\sum_iX_i|A)=14E(X_i)$
$E(\sum_iX_i|B)=13E(X_i)$
$E(\sum_iX_i)=E(A)E(\sum_iX_i|A)+E(B)E(\sum_iX_i|B)$
Comment: I don't understand. Could you solve it with using expected value ?
Answer: Every pair of contiguous chairs has a probability
of $\frac{8}{16}\times\frac{7}{15}+\frac{7}{16}\times\frac{8}{15}$
that it will give place to a boy/girl combination.
There are exactly $15$ pairs of contiguous chairs.
Numbering these pairs and saying that $X_{i}=1$ if it gives place
to a boy/girl combination and $X_{i}=0$ otherwise, we find $\mathbb{E}X_{i}=P\left(X_{i}=1\right)=\frac{8}{16}\times\frac{7}{15}+\frac{7}{16}\times\frac{8}{15}$.
Then $X:=X_{1}+\cdots+X_{15}$ is the number of boy/girl combinations, and:
$$\mathbb{E}X=\mathbb{E}X_{1}+\cdots+\mathbb{E}X_{15}=15\times\left(\frac{8}{16}\times\frac{7}{15}+\frac{7}{16}\times\frac{8}{15}\right)=7$$


Expressing the four roots of a particular quartic in terms of trigonometric functions

Question: I know one root of the equation (eq.1),
$x^4+ax^3+2x^2-ax+1 = 0$
is,
$x_1 = \tan\big(\tfrac{1}{4}\arcsin(\tfrac{4}{a})\big)$
How to find the other three roots of eq.1 expressed similarly in terms of trigonometric and/or inverse trigonometric functions?
Comment: There are three non-principal values of the arcsine that have different tangents when divided by 4 -- namely $\theta+2\pi$, $\pi-\theta$ and $3\pi-\theta$, where $\theta$ is the principal arcsine. If $\tan(\theta/4)$ is a root, chances are excellent that the others will be, too.
Comment: Thanks for the tip. I found that, given $x = \tan(\theta/4)$, then two roots are given by $\theta = \pi/2 +\arcsin\big(\pm\sqrt{1-(4/a)^2}\big)$, and the other two are $\theta = -3\pi/2 +\arcsin\big(\pm\sqrt{1-(4/a)^2}\big)$. (I forgot to mention that *a* is non-zero.)
Answer: I wanted to find a clever solution in terms of the tangent being the slope of some line crossing an algebraic curve... no luck. This is what I got instead:
$$\begin{split}x^4+2x^2+1&=a(x-x^3)\\
(x^2+1)^2&=a(x-x^3)\end{split}\tag1$$
Now substitution $x=\tan t$ is natural on the left, because $x^2+1=1/\cos^2 t$.
$$\begin{split}\frac{1}{\cos^4 t}&=a(\tan t-\tan^3 t)\\
1 &=a(\sin t\cos^3t-\sin^3 t\cos t) \end{split}\tag2$$
The rest flows easily: factor out $\sin t \cos t$ and turn it into $\frac12 \sin 2t$, then use $\cos^2 t-\sin^2 t=\cos 2t$, finally arriving at
$$1=\frac{a}{4}\sin 4t \tag3$$
Now it's time to pay attention to domains: the substitution $x=\tan t$ is a bijection between $\mathbb R$ and $(-\pi/2,\pi/2)$. In the interval $(-\pi/2,\pi/2)$, which is two periods of the function $\sin 4t$, equation (3) has

no roots if $|a|<4$
two (double) roots if $|a|=4$
four roots if $|a|>4$

It is awkward to write down the roots keeping them all in  $(-\pi/2,\pi/2)$. Since all we care about is $\tan t$, adding or subtracting a multiple of $\pi$ is acceptable. For example: $\theta$, $\theta+\pi/2$, $\pi/4-\theta$, and $3\pi/4-\theta$, where $\theta=\arcsin (4/a)$.
Comment: Is there any straightforward way to generalize this to where instead of 2 as the coefficient of $x^{2}$ it is some arbitrary real number?


Installing Ball-End Nylon Strings on a Classical Guitar

Question: I'm looking to install ball-end nylon strings on a classical guitar.
Which of these ways is the best in terms of tone and preserving the bridge?

The same way you install ball-end steel strings on a guitar: ball rests on the bridge hole, farthest from the nut.
Loop the string around the bridge and then pass the string through the hole in the ball-end so that the ball end is on the opposite side of the bridge, closest to the nut. See photo. Note the extra ivory to preserve the corners. It's just wood on the bridge furthest from the nut.

I'd prefer not to discuss looping and knotting a string. Let's stick to ball-end strings. Thanks!
Comment: Uuuh... that in your image is a _steel_ string though, isn't it? Never install (normal-tension) steel strings on a classical guitar, unless you want to destroy it!
Comment: Why not cut the ball end of you believe that's the way to better tone? Or buy traditional strings? IIRC the balls are nylon or plastic, so they shouldn't do any damage (I wouldn't think) to a wooden bridge, but if you're previously inclined against them, why even bother?
Comment: There exist ball-end classical strings. I think the ones I had in years ago had a plastic ball-end, not steel. Strings are cheap; buy new strings that are appropriate for your instrument. Tying to bridge is traditional for classical guitar, but you do you. You don't need to loop ball-end strings. And, as always, _never_ put steel strings classical guitars. https://music.stackexchange.com/questions/11809/putting-steel-strings-on-a-cheap-nylon-guitar
Comment: @DaveJacoby it seems the OP precisely wanted to _avoid opions of people previously inclined against ball-ends_. I.e., not get into discussions about ball vs no-ball, but take the balls as a given and only discuss what to do with them.
Comment: There is no reason I can think of to loop the string through the ball-end. It's there to provide a mass that won't go through the hole at the back of the bridge.
Comment: My vtc was because it seems like a pointless question (to me), and needs more clarity. Buy a different set of strings, and compare the two.
Comment: @DaveJacoby I don't believe that ball-less strings give better tone. I was trying to avoid this exact comment thread.
Comment: @leftaroundabout let's hope it was just laid on there loosely for demonstration purposes.
Comment: @leftaroundabout I was given this guitar and have just got the replacement strings. Sadly that string has been on for years in a closet.  Steel string is coming off forthwith!
Comment: Votes to close are because...?
Comment: @tim interesting that you chose to answer the question then.
Comment: With my bit of experience, just trying to be helpful..! No-one else seems to be helpful.
Comment: @tim it's not about different sets of strings it's about how to set a particular kind of string namely ball end strings.
Answer: Tone wise, there's very very little, or no difference. The string doesn't vibrate past the saddle, so what you do will make no difference.
Thread the string through the hole, over the saddle, then as normal.
As a pro muso, I'd try both ways - as explained, and wrapping, and record the two, but I wouldn't waste my time. There's probably more tonal difference to be found in different makes of strings rather than using ball-ends. I'm not sure what the point is.
Comment: I agree, bridge to nut is where the sound is and what counts. I wouldn't even bother doing an A/B. If anything having the ball end on the saddle side might make indentations on top of the bridge since the ball might ride up with the tension so I would just go traditional.


Could not instantiate custom library's DataSource after Spring Boot upgrade

Question: I have custom datasource defined in a library with autoconfiguration:
@Configuration
@ConditionalOnProperty(
        name = ["spring.datasource.type"],
        havingValue = "org.example.datasource.connector.RoutingDataSource",
        matchIfMissing = true
)
@EnableConfigurationProperties(RoutingDataSourceConfig::class)
@Import(value = [
        RoutingDataSourceBeanPostProcessor::class,
        WriteRouteInterceptor::class
])
@EnableAspectJAutoProxy
class RoutingDataSourceAutoConfiguration{
        @Bean
        @ConditionalOnMissingBean(DataSource::class)
        fun dataSource(routingDataSourceConfig: RoutingDataSourceConfig): RoutingDataSource {
                return RoutingDataSource().also {
                        it.initDataSources(routingDataSourceConfig)
                }
        }

        @Bean
        @ConditionalOnBean(RoutingDataSource::class)
        fun writeDataSource(routingDataSource: RoutingDataSource) =
                routingDataSource.getWriteDataSource()

}

With spring factories file:
# Auto Configure
org.springframework.boot.autoconfigure.AutoConfigureBefore=\
  org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  org.example.datasource.connector.RoutingDataSourceAutoConfiguration

Data source is configured as follows
spring:
    datasource:
        url: jdbc:postgresql://${POSTGRESQL_HOSTPORT}/chords?targetServerType=master&reWriteBatchedInserts=true
        routing:
            write:
                jdbcUrl: jdbc:postgresql://${POSTGRESQL_HOSTPORT}/chords?targetServerType=master&reWriteBatchedInserts=true
                username: ${POSTGRESQL_USERNAME}
                password: ${POSTGRESQL_PASSWORD}
                schema: chords
            read:
                jdbcUrl: jdbc:postgresql://${POSTGRESQL_HOSTPORT}/chords?loadBalanceHosts=true
                username: ${POSTGRESQL_USERNAME}
                password: ${POSTGRESQL_PASSWORD}
                schema: chords
                readOnly: true
        type: org.example.datasource.connector.RoutingDataSource

It worked fine on spring boot 2.4.2. However, when I upgraded it to 2.5.2, my application did not start because it could not create dataSource bean and throws the exception
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Generic.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.jdbc.UnsupportedDataSourcePropertyException: Unable to find suitable method for url
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
    ... 21 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Generic.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.jdbc.UnsupportedDataSourcePropertyException: Unable to find suitable method for url
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectProvider.getIfUnique(DefaultListableBeanFactory.java:2063)
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.flyway(FlywayAutoConfiguration.java:117)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 22 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.jdbc.UnsupportedDataSourcePropertyException: Unable to find suitable method for url
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
    ... 40 common frames omitted
Caused by: org.springframework.boot.jdbc.UnsupportedDataSourcePropertyException: Unable to find suitable method for url
    at org.springframework.boot.jdbc.UnsupportedDataSourcePropertyException.throwIf(UnsupportedDataSourcePropertyException.java:36)
    at org.springframework.boot.jdbc.DataSourceBuilder$ReflectionDataSourceProperties.getMethod(DataSourceBuilder.java:561)
    at org.springframework.boot.jdbc.DataSourceBuilder$ReflectionDataSourceProperties.set(DataSourceBuilder.java:543)
    at org.springframework.boot.jdbc.DataSourceBuilder.build(DataSourceBuilder.java:181)
    at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Generic.dataSource(DataSourceConfiguration.java:150)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 41 common frames omitted

How could I fix that?
Answer: In the default case, the evaluation order of auto-configuration classes is not specified, and trivial changes (the kind that could make a HashMap reordered) can cause this kind of failure. You need to instruct Boot to evaluate the conditions in your class in a specific order:
@AutoConfigureBefore(DataSourceAutoConfiguration::class)
(I think these are the semantics you mean, defining a DataSource bean yourself, but you might need @AutoConfigureAfter instead.)
Comment: Thank you for your answer. I tried adding `@AutoConfigureAfter(DataSourceAutoConfiguration::class)` on `RoutingDataSourceAutoConfiguration` and replacing `AutoConfigureBefore` to `AutoConfigureAfter` in spring factories, the problem hasn't gone


How these two quantities compare in $\mathbb{C}^n$

Question: Let $z=(z_1,…,z_n),w=(w_1,…,w_n) \in \mathbb{B}$ (the open unit ball in $\mathbb{C}^n$. I want to compare the quantities $A=|1-\left\langle z,w\right\rangle|$ and $|z-w|$ where $|z|^2=|z_1|^2+ \ldots +|z_n|^2$ and $\langle z,w\rangle =z_1\overline{w_1}+…+z_n\overline{w_n}.$
I am stuck as I want to find an inequality between these quantities. Is an inequality of the following type achievable in any way inside the unit ball?
$C_1|z-w|\leq |1-\langle z, w\rangle| \leq C_2|z-w|$? Than you for taking the time to look my question.
Answer: If the inequality were true, then taking $z=w$ would give $0\leq 1-|z|^2\leq 0$, i.e $1-|z|^2=0$ and hence $|z|=1$ which contradicts that $z$ is in the open unit ball.
Comment: Another way of saying is that by (reverse) triangle inequality and Cauchy-Schwarz,, $|1-\langle z,w\rangle|\geq 1-|\langle z,w\rangle|\geq 1-|z||w|>0$. So, your middle term is strictly positive when $z,w$ vary in the unit ball, while the function you're trying to control this with (namely $|z-w|$) vanishes in the unit ball. So, even if you were to remove the diagonal from the product of the unit balls, the inequality is still false.
Answer:
If $w$ or $z$ are not on the sphere the inequalities are false.

If $w$ and $z$ are on the sphere the right inequality will be true. Indeed,$$\left|1 - \left\langle z, \, w\right\rangle\right| = \left|\left\langle w, \, w\right\rangle - \left\langle z, \, w\right\rangle\right| = \left|\left\langle w - z, w \right\rangle\right| \le \left|z\right|\left|z-w\right| \le \left|z-w\right|$$ However the left one can not be true. Let $t = \left\langle z, w\right\rangle$ and $v = z - t w$ (the projection of $z$ onto $w^{\perp}$), $\left|v\right|^2 + t^2\left|w\right|^2 = \left|z\right|^2$ So $$\left|v\right|^2 = 1 - t^2 $$
Since $v\perp w$ then, $$\left|z - w\right|^2 = \left|v\right|^2 + \left(1 - t\right)^2 \left|w\right|^2 = 1 - t^2 + \left(1 - t\right)^2 = \left(1 - t\right)\left(2 + t\right)$$ so $$\left|\frac{1 - \left\langle z, w\right\rangle}{\left|z-w\right|}\right| = \frac{1-t}{\sqrt{(1-t)(2+t)}} = \sqrt{\frac{1-t}{2+t}} \underset{t\to 1}{\to} 0$$ This proves that $$\inf_{z\neq w,\, z\in \mathbb S,\, w\in\mathbb S} \left|\frac{1 - \left\langle z, w\right\rangle}{\left|z-w\right|}\right| = 0.$$
Comment: Thats a really nice answer thank you. The supremum of this quantity inside the ball is infinity right? Also, locally in pseudohyperbolic ball inside the ball, are these two quantities comparable?
Comment: The supremum is infinity inside the ball. For the pseudohyperbolic ball, I suggest that you ask a new question.


Structure of pure JavaScript API

Question: I am relatively new to JavaScript, which means i only used jquery, meteor.js and some WebGL (but in no larger project) Since i am very interested in Computer graphics, i want to write a simple WebGL library ( like three.js oder pixie.js but of course more simpler)
The Problem i am facing is for example when i have a namespace MyLibrary.renderer=... i only want to expose MyLibrary. What i am looking for is that a client can only write var renderer =new MyLibrary.renderer()
However inside the file renderer i will need a couple of other classes. The Problem so far is that i import them via

Structure of pure JavaScript API


Bash script passed to AWS EC2 Instance as User Data file fails to load on initial boot

Question: I have a simple bash script I'm trying to pass to an AWS EC2 ubuntu instance via a Powershell script using the AWS Library.
#!/bin/bash

apt-get update
apt-get upgrade

Heres the powershell script that encodes the file contents in base64 and calls the cmdlet that starts the EC2 instance:
$fileContent = Get-Content $UserDataTarget
$fileContentBytes = [System.Text.Encoding]::UTF8.GetBytes($fileContent)
$fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes)
$MasterInstance = New-EC2Instance -ImageId ami-4c7a3924 -MinCount 1 -MaxCount 1 -KeyName AWSKey -SecurityGroups $SecurityGroup -InstanceType "t1.micro" -UserData $fileContentEncoded

This is a snippet from the cloud init log:
Cloud-init v. 0.7.5 running 'modules:final' at Fri, 02 Oct 2015 21:05:24 +0000. Up 33.88 seconds.
/bin/bash: apt-get update apt-get upgrade: No such file or directory
2015-10-02 21:05:24,294 - util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [127]
2015-10-02 21:05:24,298 - cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
2015-10-02 21:05:24,298 - util.py[WARNING]: Running scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/dist-packages/cloudinit/config/cc_scripts_user.pyc'>) failed

Here's a snippet of the loaded user data script on the ubuntu instance at /var/lib/cloud/instance/scripts/part-001:
#!/bin/bash  apt-get update apt-get upgrade

I have tried converting the windows file to linux using 010 Editor and Cygwin. I've tried replacing the CRLF bytes with LF bytes. The result is the same: the entire bash script is condensed to 1 line, all line breaks are removed, and user data script fails to load on initial boot.
UPDATE: I've included both code snippets I've used to do the line break conversion. Both were vetted from peer sources (SO). For some reason, the script still shows up in the linux instance without the line break characters.
Snippet 1
function ConvertTo-LinuxLineEndings($path) {
        $oldBytes = [io.file]::ReadAllBytes($path)
        if (!$oldBytes.Length) {
            return;
        }
        [byte[]]$newBytes = @()
        [byte[]]::Resize([ref]$newBytes, $oldBytes.Length)
        $newLength = 0
        for ($i = 0; $i -lt $oldBytes.Length - 1; $i++) {
            if (($oldBytes[$i] -eq [byte][char]"`r") -and ($oldBytes[$i + 1] -eq [byte][char]"`n")) {
                continue;
            }
            $newBytes[$newLength++] = $oldBytes[$i]
        }
        $newBytes[$newLength++] = $oldBytes[$oldBytes.Length - 1]
        [byte[]]::Resize([ref]$newBytes, $newLength)
        [io.file]::WriteAllBytes($path, $newBytes)
    }

    ConvertTo-LinuxLineEndings($UserDataTarget)

Snippet 2
try{

    # get the contents and replace line breaks by U+000A
    $contents = [IO.File]::ReadAllText($UserDataSource) -replace "`r`n", "`n"
    # create UTF-8 encoding without signature
    $utf8 = New-Object System.Text.UTF8Encoding $false
    # write the text back
    [IO.File]::WriteAllText($UserDataTarget, $contents, $utf8)
}
catch [Exception]
{
    echo $_.Exception|format-list -force
}

Comment: Perhaps try using `\n` to indicate line breaks?
Comment: I tried that. Seems to be something funky with how user data file sourced from windows machine is copied through the AWS powershell library to a linux instance on EC2.
Comment: Look at your /var/lib/cloud/instance/user-data.txt or /var/lib/cloud/cloud-config.txt (ubuntu) file to see if it looks like a valid script was passed int.  You will see what the system saw as your script.
Answer: I can't give you an answer on what your Powershell code needs to look like, but in case it helps I can tell you what the output from your Powershell script needs to look like, so you need to confirm that this is what you're ending up with in the UserData when it goes in the template:
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
            "#!/bin/bash\n\n",
            "apt-get update\n",
            "apt-get upgrade\n"
        ]]}}


Using MSBuild to compile for ToolsVersion 3.5

Question: I need to compile for visual studio project using MSBuild for .Net version 3.5. I have downloaded Visual studio 2013 which comes with a tool chain 12.0 which uses .Net version 4.5. I can't install Visual Studio 2008(which comes with .NET version 3.5) because that is not supported on my Windows 7 PC.
I am using following powershell script to do that:-
<code># set environment variables for Visual Studio Command Prompt
pushd 'c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC'
cmd /c "vcvarsall.bat&set" |
foreach {
  if ($_ -match "=") {
    $v = $_.split("="); set-item -force -path "ENV:\$($v[0])"  -value "$($v[1])"
  }
}
popd
write-host "`nVisual Studio 2010 Command Prompt variables set." -ForegroundColor Yellow

$ErrorActionPreference = "Stop"
write-host "** building busdog.sys" -ForegroundColor Yellow
Exec { MSBuild ./filter/busdog.sln /t:clean /ToolsVersion:3.5}
Exec { MSBuild ./filter/busdog.sln /p:Configuration="$conf_driver" /property:Platform="$platform" /ToolsVersion:3.5}
</code>
If I remove the "/ToolsVersion" setting from my MSBuild command above or set it to 12.0, then my code gets compiled perfectly.
But, with /ToolsVersion option set to 3.5, I keep getting following error:-

MSBUILD : error MSB3411: Could not load the Visual C++ component
  "VCBuild.exe". If the component is not installed, either 1) install
  the Microsoft Windows SDK for Windows Server 2008 and .NET Framework
  3.5, or 2) install Microsoft Visual Studio 2008.[C:\workspace\busdog\filter\busdog.sln]

I already have .NET framework 3.5, 4.0 and 4.5 installed under: C:\Windows\Microsoft.NET\Framework\
Could someone please help with where I might be going wrong ?
Thanks
Manas
Answer: The error message already tells you waht to do: install the Microsoft Windows SDK for Windows Server 2008.
Comment: Thanks for your reply. I already tried doing that as well but I still get the same error. Also, I am not sure why is it asking me for VCBuild.exe, since VCBuild was replaced by MSBuild from Visual Studio 2010. Do you know why that might be happening ?
Comment: Do you have VS2010 installed by chance?
Comment: No, I have VS2013. VS2010 is not supported on Win7.
Comment: Ok, one more question: are you trying to use node.js in some way?
Comment: No, not using Node.js. Just trying to compile a c# program via command line using MSBuild


Javax, @DefaultValues, @PrePersistent, @PreUpdate

Question: Estou aprendendo a mexer com Javax, e persistencia do Java e quero saber se há algum modo de deixar um valor default pro banco de dados.
Exemplo no SQL:
variacao TIMESTAMP DEFAULT CURRENT_TIMESTAMP

Como faria isso no meu código Modelo ?
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private int id;

@NotNull
@Column(name="nota")
private int nota;

@NotNull
@Column(name="data")
private Timestamp data;

@Column(name="comentario")
private String comentario;

@Column(name="evento_id")
private Evento evento_id;

@Column(name="pessoa_id")
private Pessoa pessoa_id;

1) Qual diferença dos seguintes itens?
a) @DefaultValues
b) @PrePersistent
c) @PreUpdate
2) E qual eu usaria para este caso ?
a) @DefaultValues
b) @PrePersistent
c) @PreUpdate
Answer: Pelo que entendi você está usando JPA, nesse caso caso prefira deixar o valor default ser gerado pelo banco utilize assim:
@Column(name = "DATA_ATUALIZACAO", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
Isso só irá funcionar se você deixar o JPA criar as tabelas, ou exportar o script de criação das tabelas.

1) Qual diferença dos seguintes itens?
@PrePersist

Callback é executado antes da entidade ser persistida.

@PreUpdate

Callback é executado antes da entidade ser atualizada.

2) E qual eu usaria para este caso ?

Isso irá depender do objetivo da sua coluna, por exemplo:

Se sua coluna DATA você para armazenar a data de cadastro teria que  usar @PrePersist;
Se sua coluna DATA você para armazenar a data de atualização teria que  usar @PreUpdate;

Consulte em [hibernate] que é uma das implementações do JPA: https://docs.jboss.org/hibernate/orm/4.0/hem/en-US/html/listeners.html
Comment: Para que serve o DefaultValue ? E tambem, pelo que vi o PrePersist e PreUpdate são métodos, correto ?
Comment: @FelipeJunges Sim, voce coloca `@PrePersist` e `@PreUpdate` em um metodo e dentro dele alteras os valores da entity como quiser. A anotaçao `DefaultValue` nao existe


A version of BOOST_CHECK_CLOSE that deals with absolute differences

Question: Is there a version of BOOST_CHECK_CLOSE that works with absolute differences as opposed to percentage? In some cases absolute differences make more sense, e.g. when we are working with money (yeah, I know that double is not the best type for that), we might check that the answer is fine to the closest penny. There are many other examples.
It is rather trivial to write one of these myself using e.g. BOOST_CHECK_SMALL, but I the verbose output of right macro would make the error much easier to track down.
Answer: TBH, I don't understand the issue with BOOST_CHECK_SMALL:
<code>double val = func(); //should be between 95 and 105
BOOST_CHECK_SMALL(val - 100, 5);
</code>
However, if it has to look more like CHECK_CLOSE, you'll have to roll your own macro the way boost does - just dig into the corresponding headers. You'll probably have to add your own check type enum value, create a predicate and use it in your macro.
Or use BOOST_CHECK_PREDICATE which honestly looks a lot uglier than CHECK_SMALL with a difference.
Or simply use BOOST_CHECK with a custom function returning a predicate - but I think that's overkill.