What to look for in the musicians you play with

Question: This may be primarily opinion based, but I believe there's good scope to get some valuable information if the question's worded well.  please share comments if you think the wording could be improved :D
Background
I'm playing with friend right now who has a lot of enthusiasm, but isn't great.  It takes a lot of effort to teach riffs, chords and melodies to.  Being blunt it feels like the time would be better spent finding other musicians, or practicing on my own.
The upside is that it is great fun, and being able to teach someone what you know feels fantastic for strengthening knowledge.  The guy's a good friend and is really keen on playing live gigs(though we've only played a few so far)
Part of it of course is what your goal is, and mine is to grow and learn as best I can as a musician (and it tops the fun I might have not learning).
A common belief I've had is that you should always hang around musicians that are better than you, or as good so that you can learn from each other and grow.
I do feel like a bad person for asking this question, but hopefully I'm not the only one who's been in such a situation.
Summary
Given these circumstances, Is it better to to learn with less developed musicians you have fun with, or to take the time to seek out greater challenges?
Answer: It works both ways. Don't forget that to your mate, you're the better player, mentor, teacher. Often, it can make you play in less complex ways, maybe to not intimidate `lesser players.And complex isn't often best. As Mr The Bard says, teaching something will always make sure you learn it better.
To play with far better players can be scary, if you let it, but it keeps you on your toes: you probably don't listen to what's going on around as much, because you're concentrating on getting your part of the jigsaw right. So the earlier scenario is good from the respect that you can at least relax and enjoy your own playing. But, you're then nervous for your mate, so different pressures are brought out.
Try to play with superior players as much as possible - as much as they'll let you - this is a good way to get really good, trying to get up to their level. However, never forget that most players will have strengths and weaknesses, just like most things in life. I might play with a brilliant jazzer, who can solo over just about anything, but I know that if dots were put in front of him, he'd probably stop playing. And vice versa, play with someone who I could only wish to read as well as, but not expect great off-the-cuff solos from. Both great players, from different respects, and both putting me in different situations,trying to complement each.It's not a race or contest, but teamwork, and each situation makes you stronger with different challenges.
In the original situation, as long as you can support your mate, carry on, maybe bringing in others who can push or pull both of you. There are bound to be things he can do that move you up a rung, so there's mileage to be had from both situations.
Comment: Tim brings up a great point about **you** being the musician who's "1 rung up" so to speak.  Just because your friend might not be as advanced as you doesn't mean that your individual contribution can't surpass his.  Do what you want; encourage him to do whatever he can (understanding that he might not be able to play everything *you* do, and he *doesn't have to.*) Over time, he will improve.  I would much rather play with a great friend who's an okay musician than someone who's awesome and is a jerk (the latter has happened many a time...)
Answer: You asked what we look for in musical collaborators.
Playing with musicians who have something to prove is a drag. But it's nice playing with really brilliant people because they don't have to go out of their way to show their brilliance - they just play.
Playing with people who aren't brittle is nice too - you can point out an error without them taking it personally. And also it's nice if you can be confident that when one of the others in your group points out an error in your playing they're not making some personal point, and that it's the music that's being improved. It's good to feel relaxed enough to admit you can't do something. Then the others give you the benefit of their experience.
I also like if someone can't do something and they go away and work on it, rather than just admitting defeat.
And finally I always try to remember what it's like not to be able to do something - as I'm more use to other people struggling with the same issue.
So most of the qualities I value in fellow musicians aren't musical qualities particularly - they're more qualities I'd like in any collaboration I do.
Answer: I am inclined to agree with you that it is best to hang around with musicians that are of equal or greater skill than yourself, however there are benefits to be had from playing with lesser experienced musicians.
It is said, that the best way to learn is to teach. Teaching someone melodies and chords further reinforces your knowledge of them and works to cement them in your brain, so you're still practicing. Another great thing about practicing with lesser skilled musicians, is that you can learn from their playing style. This is especially good if your friend is not classically trained or self taught. Often times musicians with little or no formal education, form certain habits and techniques that are unique and pretty cool.
Ultimately the choice is up to you, whether or not you want to spend your time practicing elsewhere, but as long as you're playing your instrument, you're practicing, so practicing with a lesser skilled musician is still beneficial and will not be of detriment to you.
Comment: Perhaps there's also a balance to it.  If I decide to play with only pro jazz players, I'll likely find myself being booted out before I get a chance to learn anything!  Robert Fripp's advice was to always play with players one rung above the ladder from you, because 2 and you're no use to them.
Comment: It can be detrimental to 'practise with lesser skilled musicians'. Many a time I've attended rehearsals and had time wasted because a player hasn't prepared or can't get a particular thing. Especially when that time is being paid for in a rehearsal studio. Left several bands for that very reason.
Answer: Get two pots boiling at the same time: continue to play with your friend; and seek out a new band with more accomplished musicians. There's nothing saying you can't be in two bands at once.
I personally feel it's not an "either-or" thing, because there's equal importance to getting along with your bandmates as there is to challenging yourself and growing as a musician. You could have a really good player in your midst, but if that person is difficult to work with you may find yourself learning less than you would otherwise.


How i can get the number of followers from a Instagram profile using ASPX.NET (C#)

Question: Im using the C# language in a ASP.NET project but i dont know how to do this. It is possible?
I already have the access code.
Thanks
Answer: It does appear to be possible to get the number of followers for an Instagram profile.
If you query the Instagram api it returns the number of followers. You can serialize that data into an object to use the data in your application.
For example, https://api.instagram.com/v1/users/1574083/?access_token=ACCESS-TOKEN will return the following data about the user.
{
"data": {
    "id": "1574083",
    "username": "snoopdogg",
    "full_name": "Snoop Dogg",
    "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
    "bio": "This is my bio",
    "website": "http://snoopdogg.com",
    "counts": {
        "media": 1320,
        "follows": 420,
        "followed_by": 3410
    }
}

Answer: you can find their API at this address
In the API console, it will generate you the URL according to what you need. It is really easy to use. According to the console, you have to access
https://api.instagram.com/v1/users/{user-id}/followed-by
where {user-id} is the ID of your user.
It will probably return a list. Count them, and there you are!


I don't know the use colon in C

Question: I'm browsing freebsd code and i see this:
i don't understand the use of colon in C
this is an example: u_char    ip_hl:4, ip_v:4;
anyone have an idea?
Comment: Read about [bit fields](http://en.cppreference.com/w/c/language/bit_field).
Answer: These colons are used to set bit fields of structure members. u_char ip_hl:4 means u_char ip_hl can hold only up to 4 bits.
Answer: This is to do with Bit fields. You can learn more about it by reading here

I don't know the use colon in C


Mean of the sampling distribution of the OLS estimator

Question: Suppose b represents the OLS estimator, and B the true coefficient in the regression model without intercept
y = Bx + u.

Under certain assumptions b is unbiased so that
E[b | X] = B.

Suppose that I want to have an estimator of
E[b | X].

The estimator of B is b. Hence it should be the estimator of this conditional mean. Then
Est. E[b | X] = b

where Est. stands for estimator. What does this tell me? The OLS estimate I obtain with the sample data at hand gives me the estimate of the mean of the sampling distribution of b. So we assume that the sample data at hand is so typical that it produces a b that is an estimate of the mean of the sampling distribution of the estimator. Is this correct?
Comment: You might be overthinking this.  Since $E[b\mid X]=B$, estimating either quantity amounts to exactly the same thing, no matter how you perform the estimate.  And estimating $E[b\mid X]$ as $b$ is no different than, say, estimating the mean of a population ($B$) with the arithmetic mean $b$ of a sample.  In light of this, could you explain what you're looking for by "What does this tell me" and "What does this mean"?
Comment: Firstly, you are asking for the sampling distribution of the mean of the OLS estimator, correct? Which estimator (intercept $\hat{\beta_0}$ or slope $\hat{\beta_1}$? I assume you are inquiring about the latter. In your post, you are merely demonstrating that the OLS estimator(s) are unbiased. Your third line of R code is not correct.
Comment: The question is about the sampling distribution and about the mean of that. b is for a variable not for a constant which I should have mentioned. My question is not about whether b is unbiased. It is simply about how to estimate the conditional mean of b. I do not use any R code in my question. I just state expressions. Est. stands for estimate.
Comment: One assumption of an OLS regression is that your estimated expectation 'b' is at the center of a normal distribution defined by X belongs to a normal distribution.  Inherent randomness in the underlying process  (i.e. the random normal error term in the equation governing the underlying process), means that the samples may not always fall on the expectation, but that if the error in the process is normal, then so too must be the estimated expectation values.
Comment: My question is simply how to estimate the mean of the sampling distribution of b? I deduce in my question that the answer is b. What is the estimator of Var[b | x]? It is s^2 (x'X)^{-1}. So what is the estimator of E[b | X]? It is b. Right? I am just questioning what this tells. So I have sample data at hand. I calculate b, and this b gives me an estimate of the mean of the sampling distribution of b. Is this correct?
Answer: Your surprise might stem from a reasoning in a different direction, why is $\hat \beta$ not only estimate for $\beta$ but also for the mean of it's own sampling distribution $\mu_{\hat\beta}=E(\hat \beta)$.
But you always get (by default) for any random variable $X$ with finite mean, that a particular value $x$ sampled from the distribution of $X$ is an unbiased estimate for $E(X)$.

a single $b$, drawn from the distribution for $B$ is an unbiased estimator for $E(B)$
if $E(B)=\beta$, then $b$ is (also) an unbiased estimate for $\beta$

The property 1 is: not some additional rule to 2, not a consequence of 2, and neither a consequence of OLS estimation.
You always have 1, and sometimes 2.
Your line of thought goes like we have 2, but also 1, why is that? The answer is a bit trivial: since you always have 1.

Where:

$B$ is a variable and more specifically refers to the population (that is all instances of $B$)
$b$ is a specific draw from $B$, it  refers to a sample (in contrast to the population)
$\beta$ is a parameter. It is not directly measured. For instance, the slope in a particular relationship/function/model.
$\hat \beta$ is an estimate for $\beta$ based on a sample.
Comment: I am trying to understand the reply but there is a b, B, italic B, and beta in the answer. Should I continue to try to understand the reply, or is there room for updating the notation?
Comment: I will place my comment in the answer since these conventions are also troubling to me so maybe someone can help.
Comment: As you can see I like to use lowercase and uppercase differently. You used lowercase for an estimate of uppercase. Whereas I use lowercase as a particular draw from uppercase.
Comment: Isn't $\hat\beta$ an estimator for $\beta$, and estimate is $b$?
Comment: $\hat\beta = (X^TX)^{-1}X y$ is a statistic. It is based on a particular transformation of $y$ that is sampled from the distribution $Y$ (if you like you could call it 'an estimator for $\beta$'). Like for any sample that comes from a distribution with finite mean, you have that a single sample $\hat\beta$ is an unbiased estimator for the mean/expectation-value of it's own distribution $E(\hat\beta)$, this is not something particular for OLS.
Answer: Following your notation and your particular example ... "given certain assumption we have that"
E[b | X] = B

for the law of iterated exeptaction it follows that:
E[b] = B

$b$ is your ESTIMATOR for $B$ and it is a random variable because its value depends on the sample you draw. It's centered around the $B$ that is its expected value (the mean). Every time you draw a sample the value o $b$ is different but the mean of $b$, $E(b)$  is equal to $B$ .
The mean of the sampling distribution of $b$ is just $B$ as you can read in the equality above.
Comment: But my question is not about what b is or what its expected value is. My question is about "Est. E[b | X]". It is like "Est. Var[b | X]" which is s^2(X'X)^{-1}.


How to parse html in Powershell Core

Question: So, Invoke-WebRequest in Powershell Core is permanently baked with -UseBasicParsing. More details can be found here and here.
Net result - no ParsedHtml property on the result object.
While the rationale makes perfect sense, the question is - how to parse HTML in Powershell Core?
Now, I can probably use a .NET Core library, like HtmlAgilityPack, but it seems like vast code changes would be required to migrate existing PS code to use this library.
Is this our best option or are there any better ones for PS Core users?
EDIT 1
The answer seems to be found here - Unable to use IHTMLDocument2
Answer: Probably the easiest way is to use powerHTML module which basically provides a wrapper for HTML Agility Pack
PowerHTML

How to parse html in Powershell Core


Domain Join - The Network Path was not Found

Question: I am unable to join PC's or servers to my domain and am unable to determine the cause...
What have I tried? - Disabled Domain Windows Firewall; Changed Network Adapter from Public to Domain, Changed DNS directly to the Domain Controller (Same Issues), I have Malwarebytes Premium installed but this has not caused issues in the past, The Client is Windows Server 2016 (Unactivated).
Any advice would be greatly appreciated.
Here are the results from the NetSetup.log on the client...
03/31/2019 22:16:23:240 NetpDoDomainJoin
03/31/2019 22:16:23:240 NetpDoDomainJoin: using current computer names
03/31/2019 22:16:23:240 NetpDoDomainJoin: NetpGetComputerNameEx(NetBios) returned 0x0
03/31/2019 22:16:23:240 NetpDoDomainJoin: NetpGetComputerNameEx(DnsHostName) returned 0x0
03/31/2019 22:16:23:240 NetpMachineValidToJoin: 'GVSNORTSVR'
03/31/2019 22:16:23:240 NetpMachineValidToJoin: status: 0x0
03/31/2019 22:16:23:240 NetpJoinDomain
03/31/2019 22:16:23:240     HostName: GVSNORTSVR
03/31/2019 22:16:23:240     NetbiosName: GVSNORTSVR
03/31/2019 22:16:23:240     Domain: XXX.co.uk
03/31/2019 22:16:23:240     MachineAccountOU: (NULL)
03/31/2019 22:16:23:240     Account: XXX.co.uk\ADM-LC
03/31/2019 22:16:23:240     Options: 0x27
03/31/2019 22:16:23:240 NetpValidateName: checking to see if 'XXX.co.uk' is valid as type 3 name
03/31/2019 22:16:23:240 NetpValidateName: 'XXX.co.uk' is not a valid NetBIOS domain name: 0x7b
03/31/2019 22:16:23:318 NetpCheckDomainNameIsValid [ Exists ] for 'XXX.co.uk' returned 0x0
03/31/2019 22:16:23:318 NetpValidateName: name 'XXX.co.uk' is valid for type 3
03/31/2019 22:16:23:318 NetpDsGetDcName: trying to find DC in domain 'XXX.co.uk', flags: 0x40001010
03/31/2019 22:16:23:774 NetpDsGetDcName: failed to find a DC having account 'GVSNORTSVR$': 0x525, last error is 0x0
03/31/2019 22:16:23:774 NetpDsGetDcName: status of verifying DNS A record name resolution for 'XXX-DC.XXX.co.uk': 0x0
03/31/2019 22:16:23:774 NetpDsGetDcName: found DC '\\XXX-DC.XXX.co.uk' in the specified domain
03/31/2019 22:16:23:774 NetpJoinDomainOnDs: NetpDsGetDcName returned: 0x0
03/31/2019 22:16:23:774 NetpDisableIDNEncoding: using FQDN XXX.co.uk from dcinfo
03/31/2019 22:16:23:774 NetpDisableIDNEncoding: DnsDisableIdnEncoding(UNTILREBOOT) on 'XXX.co.uk' succeeded
03/31/2019 22:16:23:774 NetpJoinDomainOnDs: NetpDisableIDNEncoding returned: 0x0
03/31/2019 22:16:23:774 NetUseAdd to \\XXX-DC.XXX.co.uk\IPC$ returned 53
03/31/2019 22:16:23:774 NetpJoinDomainOnDs: status of connecting to dc '\\XXX-DC.XXX.co.uk': 0x35
03/31/2019 22:16:23:774 NetpJoinDomainOnDs: Function exits with status of: 0x35
03/31/2019 22:16:23:774 NetpResetIDNEncoding: DnsDisableIdnEncoding(RESETALL) on 'XXX.co.uk' returned 0x0
03/31/2019 22:16:23:774 NetpJoinDomainOnDs: NetpResetIDNEncoding on 'XXX.co.uk': 0x0
03/31/2019 22:16:23:774 NetpDoDomainJoin: status: 0x35

Here are the results from DCDiag...
Directory Server Diagnosis

Performing initial setup:
   Trying to find home server...
   Home Server = XXX-DC
   * Identified AD Forest.
   Done gathering initial info.

Doing initial required tests

   Testing server: Default-First-Site-Name\XXX-DC
      Starting test: Connectivity
         ......................... XXX-DC passed test Connectivity

Doing primary tests

   Testing server: Default-First-Site-Name\XXX-DC
      Starting test: Advertising
         ......................... XXX-DC passed test Advertising
      Starting test: FrsEvent
         ......................... XXX-DC passed test FrsEvent
      Starting test: DFSREvent
         There are warning or error events within the last 24 hours after the SYSVOL has been shared.  Failing SYSVOL
         replication problems may cause Group Policy problems.
         ......................... XXX-DC failed test DFSREvent
      Starting test: SysVolCheck
         ......................... XXX-DC passed test SysVolCheck
      Starting test: KccEvent
         ......................... XXX-DC passed test KccEvent
      Starting test: KnowsOfRoleHolders
         ......................... XXX-DC passed test KnowsOfRoleHolders
      Starting test: MachineAccount
         ......................... XXX-DC passed test MachineAccount
      Starting test: NCSecDesc
         ......................... XXX-DC passed test NCSecDesc
      Starting test: NetLogons
         ......................... XXX-DC passed test NetLogons
      Starting test: ObjectsReplicated
         ......................... XXX-DC passed test ObjectsReplicated
      Starting test: Replications
         ......................... XXX-DC passed test Replications
      Starting test: RidManager
         ......................... XXX-DC passed test RidManager
      Starting test: Services
         ......................... XXX-DC passed test Services
      Starting test: SystemLog
         ......................... XXX-DC passed test SystemLog
      Starting test: VerifyReferences
         ......................... XXX-DC passed test VerifyReferences

   Running partition tests on : ForestDnsZones
      Starting test: CheckSDRefDom
         ......................... ForestDnsZones passed test CheckSDRefDom
      Starting test: CrossRefValidation
         ......................... ForestDnsZones passed test CrossRefValidation

   Running partition tests on : DomainDnsZones
      Starting test: CheckSDRefDom
         ......................... DomainDnsZones passed test CheckSDRefDom
      Starting test: CrossRefValidation
         ......................... DomainDnsZones passed test CrossRefValidation

   Running partition tests on : Schema
      Starting test: CheckSDRefDom
         ......................... Schema passed test CheckSDRefDom
      Starting test: CrossRefValidation
         ......................... Schema passed test CrossRefValidation

   Running partition tests on : Configuration
      Starting test: CheckSDRefDom
         ......................... Configuration passed test CheckSDRefDom
      Starting test: CrossRefValidation
         ......................... Configuration passed test CrossRefValidation

   Running partition tests on : XXX
      Starting test: CheckSDRefDom
         ......................... XXX passed test CheckSDRefDom
      Starting test: CrossRefValidation
         ......................... XXX passed test CrossRefValidation

   Running enterprise tests on : XXX.co.uk
      Starting test: LocatorCheck
         ......................... XXX.co.uk passed test LocatorCheck
      Starting test: Intersite
         ......................... XXX.co.uk passed test Intersite

Answer: Issue was caused by the Hyper V Virtual Switch. I had reset all my network adapters and re-sent them back up again. It is now working :)


VirtualHost https and non-www

Question: I'm attempting to redirect all requests to my main site to https://example.com with VirtualHost. I want to remove the www from the domain and force https.
Currently all http:// requests are redirecting properly, but https://www.example.com is throwing an SSL privacy error.
I have a couple subdomains I'm hosting as well, so I assume virtualhost is the way to go?
Wondering if there's anything I can do, or if I'll need to purchase a second SSL cert just to support the https://www. redirect.
Current vhost.conf:
<code><VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    Redirect permanent / https://example.com/
</VirtualHost>

<VirtualHost *:443>
    ServerName example.com
    DocumentRoot /var/www/html
    SSLENGINE on
    SSL certs...
</VirtualHost>
</code>
Comment: Best practice is to use www.example.com
Comment: Ordinarily when you get a certificate for www.example.com it will include example.com as well, in the Subject Alternative Name field. The reverse may not be true. You should only need the one certificate, but you may have gotten the wrong one.
Answer: No there isn't a way around that,  SSL socket opens before redirects are processed.
Some ssl providers give you www.example.com SAN free,  contact them.

VirtualHost https and non-www


How to apply number or date format to columns after TEXTSPLIT in Excel

Question: I use TEXTSPLIT to cut text composed of multiple parts, like for example: the country, the date and the value:
"USA-01/01/2023-1000"
=TEXTSPLIT(A1,"-")

Unfortunately, the result is a spill formula (dynamic array) where the date and the value are "text" (which is normal after a text function). This poses a big problem if I want to SORT, because the sorting is applied as TEXT, not as date.
Is there a way to have the date and number columns recognized as number, without having to enumerate each column to apply the format?
My current solution:
For now I use let to name the textsplit part and I use choosecols for each column and multiply by 1 the number ones... before using SORT:
=LET(a,TEXTSPLIT(A1,"-"),HSTACK(CHOOSECOLS(a,1),CHOOSECOLS(a,2)*1,CHOOSECOLS(a,3)*1))

But this seems overcomplicated... especially when the equivalent SPLIT array formula in GoogleSheet applies immediately the correct dates and number format to each part.
Comment: You could use: `=LET(d,TEXTSPLIT(A1,"-"),IFERROR(d+0,d))` but you'll have manually apply any number/date formatting to the relevant cells.
Comment: @MayukhBhattacharya thank you for the editing of the post. I will try to follow these guidelines in the future.
Comment: Yes, but I would like to avoid enumerating the columns with choosecols
Comment: And using TEXT, the result is still "text" not a date, which means that sorting on this column will be incorrect for dates.
Comment: Please @Rory can you post it as an anwser so that I can accept it? Thanks
Comment: Or you could check this method: https://stackoverflow.com/a/76573858/4961700
Answer: You could use:
=LET(d,TEXTSPLIT(A1,"-"),IFERROR(d+0,d))

but you'll have to manually apply any number/date formatting to the relevant cells.
Comment: Thanks a lot for your solution, I credited you in my tutorial https://www.youtube.com/watch?v=yeQnMxxZL0U (delete this comment when seen).


When should I subtract or add integrals?

Question: I try to figure out the area between the function $f(x)=x^2$ and function $g(x)=x+6$ bounded by lines $x=0$ to $x=6$. I know, how will the area look like, but I've got problem with subtraction or addition of integrals.
This is what I figured out so far:
In bound from 0 to 6 function $f$ and function $g$ have one point in common and that is the point $P=[3,9]$.
In bound from 0 to 3 the function $g$ is above the function $f$, so I got integral:
$\int_{0}^{3}(g-f) dx=\int_{0}^{3}(x+6-x^2)dx=[\frac{x^2}{2}+6x-\frac{x^3}{3}]_0^3 = \frac{27}{2}$
In bound from 3 to 6 the function $f$ is above the function $g$, so I got integral:
$\int_{3}^{6}(f-g) dx=\int_{3}^{6}(x^2-x-6)dx=[\frac{x^3}{3}-\frac{x^2}{2}-6x]_3^6 = \frac{63}{2}$
The result has to be 18, but with my results can I get 18 just by subtracting the second area from the first area.

Why should I subtract and not to sum up the areas?
Answer: When they want the "area between the two curves", then you have to add the two numbers you got. This area is the $L^1$-distance of the two functions $y_1(x):=x^2$ and $y_2(x):=x+6$ over the interval $[0,6]$.
When they wanted $18$ they might as well have asked for the integral $\int_0^6\bigl(y_1(x)-y_2(x)\bigr)\>dx$. This integral represents the overall difference in the "effectivity" of the two functions $y_1$ and $y_2$  over the interval $[0,6]$ (say, sales of two firms in the months January–June).
Comment: Thank you very much :)


C++ and Enumerable

Question: I have a producer/consumers design in my application which implement Produce/Consume functions on user types. But it doesn't work very naturally with the standard library and especially with algorithms.
In C# there is the Enumerable and Observable concepts that can be used to easily implement stuff like this and get alot of nice free functionality.
In C++ there is the ios, istream, ostream, input_iterator, output_iterator concepts which I thought might be useful. But it seems to me that all of these are for primitive character types, e.g. char, int etc... and not for user types.
Sure I could use real functions such as Produce/Consumer and std::mem_fn for algorithms. But I was hoping there was a better way.
Im looking on some best-practice advice on how to go about designing i/o similar solutions on user types in C++.
E.g. from C#
class FrameProducer : IEnumerable<Frame> // pull frames
{...}

// Some engine between

class FrameConsumer : IObserver<Frame> // push frames
{...}

I was hoping for something similar in C++ e.g. which i dont believe is possible.
class FrameProducer : istream<Frame> // pull frames
{...}

// Some engine between

class FrameConsumer : ostream<Frame> // push frames
{...}

Maybe I'm thinking to hard about it and should just go by KISS.
Thoughts?
Comment: Are you familiar with duck typing? That's generally how C++ deals with IEnumerable and the like.  If you want to write to streams, then overload <<. If you want to iterate over a collection, make something that looks like an iterator. Your FrameProducer would likely provide a `begin()` and `end()` method that produces those iterators, which would allow it to be used places that expect traditional containers.
Comment: Why are you talking about C#? This is C++, forget you know C# and start programming in C++. Saying "I'd do it this way in language X, how can I translate it into language Y" will always fail, you must learn language Y from the ground up so you know how things are done in language Y. [A good book helps](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). Oh, and I don't get the question. Whenever you bring language X into a problem about language Y, many people that know language Y need you to explain that X language feature.
Comment: Can you explain better what you mean for "Produce/Consume functions on user types"?
Comment: It doesn't matter what language I'm talking about, it's not to the point. I just picked C# because it was convenient since it had the LINQ concept which is similar to C++ and its iterators and algorithms.

My question is why the C++ ios concept doesn't allow for user types and what alternatives there are.
Comment: I could for example implement a producer by having it provide an input_iterator instead of having a "Producer" function and in the same way a consumer by having it provide an output_iterator. Im just looking for a best practice.
Comment: produce/consume on user types.

struct MyProducer
{
     MyNiceClass Produce();
};

struct MyConsumer
{
     void Consume(const MyNiceClass& item);
};
Comment: How then would i implement iostream::getline on a user type?

My goal is to use the infrastructure provide by stl if possible instead of making up my own.
Comment: @Dacav I guess OP meant that Producer produces class instances rather then primitive types (such as `int`, `char`, etc).
Comment: C++ *does* allow user types to be streamed, by overloading insertion and extraction operators. (I think the problem is your question asks about a step, rather than a problem. Your comment above actually describes a problem, which can be answered.)
Comment: I am simply astonished people are not familiar with and therefore reject the ENTIRE body of work called COMPARATIVE ANALYSIS and the entire body of LOGIC in relation to Comparative Analysis. It's a great way to force yourself into a barren intellectual ghetto. Enjoy the soulless rap.
Answer: Th terms are "insertion operator" and "extraction operator", which insert and extract data from a stream.
Here's an example:
#include <iostream>
#include <sstream>

struct foo
{
    int x;
};

// insertion operator
std::ostream& operator<<(std::ostream& s, const foo& f)
{
    s << f.x; // insert a foo by inserting x
    return s;
}

// extraction operator
std::istream& operator>>(std::istream& s, foo& f)
{
    s >> f.x; // extract a foo by extracting x
    return s;
}

int main(void)
{
    std::stringstream ss;

    foo f1 = {5};
    ss << f1;

    foo f2;
    ss >> f2;
}

Based on your desire to do:
MyFrameProducer producer;
MyFrameConsumer consumer;
Frame frame; // frame should probably be in the while loop, since its
while(!producer.eof()) // lifetime doesn't need to exist outside the loop
{
    producer >> frame;
    consumer << frame;
}

You might make:
struct MyFrameProducer {}; // add an eof function
struct MyFrameConsumer {};
struct Frame {};

// producer produces a frame
MyFrameProducer& operator>>(MyFrameProducer& p, Frame& f)
{
    /* whatever it takes to make a frame */

    return p;
}

// consumer consumes a frame
MyFrameConsumer& operator<<(MyFrameConsumer& c, const Frame& f)
{
    /* whatever it takes to use a frame */

    return c;
}

Or something akin to it. (Sorry my understanding of the problem is small.) It is a bit weird to desire this interface, since it has nothing to do with streams, and you might be better off with a different interface (explicit methods).
Comment: @ronag: I did *not* show how to convert a user type into a string, I showed how to insert it into a stream. (Only coincidentally does `stringstream` provide a way of producing a string.) Let me edit the answer to your comment snippet.
Comment: Not quite, what you show is how to convert a user type to a string.

I was looking for something like this (which doesn't work since the stl istream/ostream seems to be character based)

class MyFrameProducer : istream
{
}

class MyFrameConsumer : ostream
{
}

int main()
{
     MyFrameProducer producer;
     MyFrameConsumer consumer;

     Frame frame;
     while(!producer.eof())
     {
          producer >> frame;
          consumer << frame;
     }
}
Comment: @Philipp: No, don't worry. I made it CW because I'm basically guessing, it wasn't your edit. And thanks. :)
Answer: Take a look at this producer/consumer solution. Although it is in pure C it is so elegant so I just can't resist from posting it.
Comment: Interesting, this seems also interesting: http://www.crystalclearsoftware.com/soc/coroutine/

C++ and Enumerable


Is bootstrapping standard errors and confidence intervals appropriate in regressions where homoscedasticity assumption is violated?

Question: If in standard OLS regressions two assumptions are violated (normal distribution of errors, homoscedasticity), is bootstrapping standard errors and confidence intervals an appropriate alternative to arrive at meaningful results with respect to the significance of regressor coefficients?
Do significance tests with bootstrapped standard errors and confidence intervals still "work" with heteroscedasticity?
If yes, what would be applicable confidence intervals that can be used in this scenario (percentile, BC, BCA)?
Finally, if bootstrapping is appropriate in this scenario, what would be the relevant literature that needs to be read and cited to arrive at this conclusion? Any hint would be greatly appreciated!
Comment: If there is such violation, I dont think bootstrapping cures it. Instead why not try to transform (log) the data to get closer to normality and use a robust standard error such as from the sandwich package in R?
Comment: The bootstrap works fine if you adapt the resampling scheme to the situation you're in.
Comment: Also  https://stats.stackexchange.com/questions/64813/two-ways-of-using-bootstrap-to-estimate-the-confidence-interval-of-coefficients,  https://stats.stackexchange.com/questions/41547/resampling-and-huber-white,
Answer: There are at least three (may be more) approaches to perform the bootstrap for linear regression with independent, but not identically distributed data. (If you have other violations of the "standard" assumptions, e.g., due to autocorrelations with time series data, or clustering due to sampling design, things get even more complicated).

You can resample observation as a whole, i.e., take a sample with replacement of $(y_j^*, {\bf x}_j^*)$ from the original data $\{ (y_i, {\bf x}_i) \}$. This will be asymptotically equivalent to performing the Huber-White heteroskedasticity correction.
You can fit your model, obtain the residuals $e_i = y_i - {\bf x}_i ' \hat\beta$, and resample independently ${\bf x}_j^*$ and $e_j^*$ with replacement from their respective empirical distributions, but this breaks down the heteroskedasticity patterns, if there are any, so I doubt this bootstrap is consistent.
You can perform wild bootstrap in which you resample the sign of the residual, which controls for the conditional second moment (and, with some extra tweaks, for the conditional third moment, too). This would be the procedure I would recommend (provided that you can understand it and defend it to others when asked, "What did you do to control for heteroskedasticity? How do you know that it works?").

The ultimate reference is Wu (1986), but Annals are not exactly the picture book reading.
UPDATES based on the OP's follow-up questions asked in the comments:
The number of replicates seemed large to me; the only good discussion of this bootstrap parameter that I am aware of is in Efron & Tibshirani's Intro to Bootstrap book.
I believe that generally similar corrections for the lack of distributional assumptions can be obtained with Huber/White standard errors. Cameron & Triverdi's textbook discuss equivalence of the pairs bootstrap and White's heteroskedasticity correction. The equivalence follows from the general robustness theory for $M$-estimates: both corrections are aimed at correcting the distributional assumptions, whatever they may be, with the minimal assumption of finite second moments of residuals, and independence between observations. See also Hausman and Palmer (2012) on more specific comparisons in finite samples (a version of this paper is available on one of the authors' websites) on comparison between the bootstrap and heteroskedasticity corrections.
Comment: Thanks a lot for your help! Please allow me one followup question:

The only assumptions that I violate are the normal distribution of errors and the homoscedasticity assumptions.

Also, I am only interested in seeing whether my regression coefficients are sig. in the expected direction or no. The magnitude of the effect is not important.

I think what I have done so far is your option 1. I bootstrapped standard errors and generated in addition bootstrapped confidence intervals. I did that using Stata: vce(bootstrap, reps(2500) bca), estat bootstrap.

Does that cure my assumption violations?
Comment: I don't do diagnostics of the data based only on your syntax, and nobody will. What is the size of your data set? `reps(2500)` is probably an overkill, at least for the standard errors; I think `reps(500)` is OK for most practical purposes. Efron & Tibshirani's [intro bootstrap book](http://www.amazon.com/Introduction-Bootstrap-Monographs-Statistics-Probability/dp/0412042312) has a section on the number of replicates. They have a whole chapter on regression, too, so that may be another good reference for you to look at.
Comment: Thank you for your quick answer. The dataset is ~250. The questions on the number of replications aside (thank you for the link!), would you agree that bootstrapped standard errors (by way of resampling observations as a whole) and / or bootstrapped confidence intervals (e.g., percentile or bias corrected) would be an appropriate way to determine the significance (or lack thereof) of a regression coefficient given the violation of homoscedasticity and normal distribution of errors assumption?

Thanks a lot for your input!
Comment: Yes, I would say that's better. If you use Stata though you could get a very similar answer using `robust` option of your regression. `est store` both results and `est tab, se` them to compare side by side.
Comment: Thank you StasK.

I have also seen the following comment that you made somewhere else on this site: "Simple bootstrap with resampling ⇔ White's heteroskedasticity robust estimator".

In the context of my questions as outlined above: Are there published journal articles that make this point?
Comment: More specifically:

Question 1: I have only come across papers that suggest the use of "White's heteroskedasticity robust estimator" in case of heteroscedasticity, but no paper that suggests that this robust estimator also "cures" a distribution of errors that is not normal. Does White's robust estimator cure for both these assumption violations? Could you direct me to a paper that makes this point?
Comment: Question 2: Similarly in the case of bootstrapping: none of the papers I have seen explicitly mention that it also "cures" heteroscedasticity. Is there a paper you could direct me to that explicitly explains that boostrapping standard errors based on a simple bootstrap "cures" heteroscedasticity? Thanks a lot for your help! It is very much appreciated!
Comment: [Cameron & Triverdi's textbook](http://www.amazon.com/Microeconometrics-Methods-Applications-Colin-Cameron/dp/0521848059) makes this point. See also [Hausman and Palmer (2012)](http://ideas.repec.org/a/eee/ecolet/v116y2012i2p232-235.html) (a version of this is available on the authors' websites) on comparison between the bootstrap and heteroskedasticity corrections.


Hierarchical query from two tables

Question: Help me create a hierarchical query.
I have two table:
Table 1(dic_kgs)
KGS_ID    KGS_PARENT_ID    KGS_CODE
1                           A
2              1            A0
3              1            A1
4                           B

and so on
Table 2(dic_kgs_strings)
KGS_ID    LANG_ID    KGS_NAME    KGS_ADD_INFO
1            1        Name1
2            1        Name2
3            1        Name3
4            1        Name4

and so on.
I want to get result in the follow view:
A Name1
A0 Name2
A1 Name3
B Name4

I have writen only part of query:
select kgs_code
  from dic_kgs
  start with dic_kgs.kgs_parent_id is null
      connect by prior dic_kgs.kgs_id = dic_kgs.kgs_parent_id;

Thanks.
Comment: Obviously DIC_KGS has a hierarchical structure but you're not using it in your query.  So what is the point you're trying to reach
Answer: it not seems to be a hierarchical query what you need.
You can get the report using:
select
   kgs_code, kgs_name
from
   dic_kgs a join dic_kgs_strings b on (a.kgs_id = b.kgs_id)

Hierarchical query from two tables


Pandas GroupBy, to compare the new column of list of numbers, to another column of list of numbers

Question: A data frame is as the left of screenshot below.
I want to GroupBy the names, and find out which numbers (compared to [1,2,3,4,5]) are missing.
The ideal output is as the right of screenshot.
I've tried below codes. But the column 'Number of stars' after the GroupBy, is being taken as a list of strings. So it doesn't perform the comparison.
How can I fix it?

import pandas as pd
from io import StringIO

csvfile = StringIO("""
Name    Number of stars
Benjamin    1,3,2,1,2
Benjamin    2,5,1,3
Emma    2,1,1,4,4,2
Ethan   2,5,4
Emma    2,2,2
Ethan   5,4,4,1,1,1
Olivia  4,1,3,5""")

df = pd.read_csv(csvfile, sep = '\t', engine='python')

df_1 = df.groupby('Name')['Number of stars'].apply(list)

df_1 = df_1.to_frame().reset_index()

df_1['all stars'] = pd.Series([list(range(1,6)) for x in range(len(df_1.index))])
df_1['diff'] = df_1['all stars'].map(set) - df_1['Number of stars'].map(set)

print (df_1)

Output:
   Name       Number of stars        all stars             diff
0  Benjamin  [1,3,2,1,2, 2,5,1,3]  [1, 2, 3, 4, 5]  {1, 2, 3, 4, 5}
1      Emma  [2,1,1,4,4,2, 2,2,2]  [1, 2, 3, 4, 5]  {1, 2, 3, 4, 5}
2     Ethan  [2,5,4, 5,4,4,1,1,1]  [1, 2, 3, 4, 5]  {1, 2, 3, 4, 5}
3    Olivia             [4,1,3,5]  [1, 2, 3, 4, 5]  {1, 2, 3, 4, 5}

Answer: Try:
out = (
    df.groupby("Name")["Number of stars"]
    .apply(
        lambda x: ",".join(set("12345").difference(x.str.split(",").explode()))
    )
    .reset_index(name="diff")
)
print(out)

Prints:
       Name diff
0  Benjamin    4
1      Emma  3,5
2     Ethan    3
3    Olivia    2

Comment: thank you! May I have your understanding that I chose another one as the answer, which is a little flexible?
Answer: Let us group the dataframe by Name and aggregate Number of stars with custom lambda function that returns the required set difference:
s = set(range(1, 6))
df.groupby('Name')['Number of stars']\
  .agg(lambda x: s - set(int(z) for y in x for z in y.split(',')))

Name
Benjamin       {4}
Emma        {3, 5}
Ethan          {3}
Olivia         {2}
Name: Number of stars, dtype: object

Answer: You can convert comma separated string to list of string   then explode and groupby to get set
df['Number of stars'] = df['Number of stars'].str.split(',')
df = df.explode('Number of stars')
df['Number of stars'] = df['Number of stars'].astype(int)

df_1 = (df.groupby('Name')['Number of stars'].apply(set)
        .to_frame().reset_index())
df_1['diff'] = df_1['Number of stars'].apply(lambda x: set(range(1,6))-x)

print(df_1)

       Name Number of stars    diff
0  Benjamin    {1, 2, 3, 5}     {4}
1      Emma       {1, 2, 4}  {3, 5}
2     Ethan    {1, 2, 4, 5}     {3}
3    Olivia    {1, 3, 4, 5}     {2}

Comment: thank you! your answer is very helpful in understand the working logic. however, hope you don't mind I chose another one for answer.


Able to touch the background of activity indicator

Question: In my iphone application an activity indicator is shown at the time of webservice call. My problem is that i am able to touch the view on which the activity indicator is shown.My view has textfields and buttons and i am able to enter values in the text fields and also change the button states while the activity indicator is still on it. Have anybody faced a similar situation? Does anybody know a solution to this problem? All helpful suggestions are welcomed.
Here is my activity indicator class.
ActivityProgressViewController.h
#import <UIKit/UIKit.h>

@interface ActivityProgressViewController : UIViewController {
    IBOutlet UIActivityIndicatorView *_activityIndicator;
    IBOutlet UILabel *_labelMessage;
    NSString *_messageToShow;
}

@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activityIndicator;
@property (nonatomic, retain) IBOutlet UILabel *labelMessage;

+ (ActivityProgressViewController*) createInstance;

- (void)show;
- (void)showWithMessage:(NSString*)message;
- (void)close;

+ (void)show;
+ (void)close;

@end

ActivityProgressViewController.m
#import "ActivityProgressViewController.h"

#define kACTIVITY_INDICATOR_NIB @"ActivityProgressViewController"

@implementation ActivityProgressViewController

@synthesize activityIndicator = _activityIndicator;
@synthesize labelMessage = _labelMessage;

static ActivityProgressViewController *_viewController;

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
}

- (void)viewDidLoad {
    if (_messageToShow) _labelMessage.text = _messageToShow;
}

- (void)dealloc {
    [_labelMessage release];
    [_messageToShow release];
    [_activityIndicator release];
    [super dealloc];
}

+ (ActivityProgressViewController*) createInstance {
    _viewController = [[ActivityProgressViewController alloc] initWithNibName:kACTIVITY_INDICATOR_NIB bundle:nil];
    return _viewController;
}

- (void)show
{
    [_activityIndicator startAnimating];

    UIWindow *window = [[[UIApplication sharedApplication] windows]objectAtIndex:0];
    NSLog(@"[[UIApplication sharedApplication] windows]===%@",[[UIApplication sharedApplication] windows]);

    self.view.frame = CGRectMake(window.bounds.origin.x, window.bounds.origin.y, window.bounds.size.width, window.bounds.size.height);

    [window addSubview:self.view];

}

- (void)showWithMessage:(NSString*)message {
    _messageToShow = message;
    [self show];
}

- (void)close
{
    [self.view removeFromSuperview];

}

+ (void)show {
    if (!_viewController) {
        _viewController = [ActivityProgressViewController createInstance];
    }
    [_viewController show];
}

+ (void)close {
    if (_viewController) {
        [_viewController close];
    }
}

@end

Here is how i call from my required class.
 [ActivityProgressViewController show];

 [ActivityProgressViewController close];

I also call the activity indicator while exporting audio.
This is the code I use for exporting
    -(void)exportAudioFile:(AVComposition*)combinedComposition
{

[ActivityProgressViewController show];

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:combinedComposition
                                                                           presetName:AVAssetExportPresetPassthrough];

    NSArray *presets =[AVAssetExportSession exportPresetsCompatibleWithAsset:combinedComposition];

    NSLog(@"presets======%@",presets);
    NSLog (@"can export: %@", exportSession.supportedFileTypes);
    NSArray *dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectoryPath = [dirs objectAtIndex:0];
    exportPath = [documentsDirectoryPath stringByAppendingPathComponent:@"CombinedNew.m4a"];
    [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
    exportURL = [NSURL fileURLWithPath:exportPath];
    exportSession.outputURL = exportURL;
    exportSession.outputFileType = @"com.apple.m4a-audio";
    exportSession.shouldOptimizeForNetworkUse = YES;
    [exportSession exportAsynchronouslyWithCompletionHandler:^{
        NSLog (@"i is in your block, exportin. status is %d",
               exportSession.status);
        switch (exportSession.status)
        {
            case AVAssetExportSessionStatusFailed:
            {

                break;
            }
            case AVAssetExportSessionStatusCompleted:
            {

                exportSuccess = YES;
                if (recorderFilePath)
                {
                    NSError *finalurlError;
                    [[NSFileManager defaultManager]removeItemAtPath:recorderFilePath  error:&finalurlError];
                    finalurlError = nil;
                    [[NSFileManager defaultManager]copyItemAtPath:[exportURL path] toPath:recorderFilePath error:&finalurlError];
                    NSLog(@"finalurlError 2-----%@",finalurlError);
                }
                [ActivityProgressViewController close];
                fileUrl = [NSURL fileURLWithPath:recorderFilePath];
                [self updatePlayerForUrl:fileUrl];
                break;
            }
            case AVAssetExportSessionStatusUnknown:
            {

                break;
            }
            case AVAssetExportSessionStatusExporting:
            {

                break;
            }
            case AVAssetExportSessionStatusCancelled:
            {

                break;
            }
            case AVAssetExportSessionStatusWaiting:
            {

                break;
            }
            default:
            {
                NSLog (@"didn't get export status");
                break;
            }

        };
    }];

    [exportSession release];
}

Answer: You're adding your activity indicator to the middle of another view, yes?
If so, you can do this in your show method:
self.superview.userInteractionEnabled = NO;

And in your close method:
self.superview.userInteractionEnabled = YES;

Here is where you'll find information on the UIView's userInteractionEnabled property:  http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instp/UIView/userInteractionEnabled
Hope this helps!
Comment: It worked.Thank you.But there is still an issue.In my application I also use that activity indicator while exporting audio files. Here the same problem occurs.
Comment: The same solution should work there also. Whatever view you added your activity indicator to, setting `userInteractionEnabled` to NO should disable touches until the activity is done.
Comment: In the exporting case I noticed that the  [ActivityProgressViewController close] gets called. But the activity indicator still exists after that and i am able to touch the UI elements of background view. I think this have something to do with the asynchronous exporting. I have added the exporting code above for referrence.
Comment: Any idea regarding this issue?
Comment: Found solution to the issue. The exportAsynchronouslyWithCompletionHandler block is performed on background thread. So i called the [ActivityProgressViewController close] method in updatePlayerForUrl function which in turn is performed in the background using :            [self performSelectorInBackground:@selector(updatePlayerForUrl:) withObject:fileUrl];
Now it works fine.
Comment: very glad to hear that!  don't forget to "accept" the answer if it worked for you (it'll help motivate other people to answer any future questions you ask here :-)


In parallelogram ABCD, points E and F are chosen on sides AB and CD, respectively.

Question: In parallelogram ABCD, points E and F are chosen on sides AB and CD, respectively, so that AE = DE
and CF/DF=2/3. Find the ratio of the area of triangle BFC to the area of quadrilateral BEDF.
I'd appreciate it if someone could show a step-by-step solution to the problem. :)
Comment: What have you tried? Where are you stuck?
Comment: Did you make a typo somewhere, please check!
Answer:
In parallelogram $ABCD$, given $AE=DE$ and $\frac{CF}{DF}=\frac{2}{3}$, then joining $DB$, and taking $AD$ and $\angle DAB$ as fixed, and sliding $AD$ to the right until $E$ coincides with $B$, then$$\frac{\triangle BFC}{BEDF}=\frac{2}{3}$$since triangles under the same height have areas proportional to their bases.
On the other hand, if we slide $AD$ increasingly to the left, quadrilateral $BEDF$ becomes an ever greater fraction of the lengthening trapezoid $ABFD$. Disregarding $\triangle ADE$ as negligible, then, and since a parallelogram is double a triangle of equal base and height, the ratio of $\triangle BFC$ to quadrilateral $BEDF$, as $AD$ moves to the left, approaches the ratio $\frac{\triangle BFC}{ABCD}$, i.e. diminishes indefinitely toward$$\frac{2}{3}\cdot\frac{1}{2}=\frac{1}{3}$$
I am not confident this answer meets the real intent of OP's problem, but based on the information given, the most I can conclude is that$$\frac{1}{3}<\frac{\triangle BFC}{BEDF}<\frac{2}{3}$$
Answer: Choosing these points is in general not possible:
If $AE=DE$, then $E$ has to be on the perpendicular bisector of $A$ and $D$. But $E$ is also on $AB$. Hence $E$ is on the intersection of this line and this segment. But if the segment $AD$ is too short, then there is no intersection.

In fact, if $\alpha$ is the angle at $A$, then we need $AB\ge \frac{AD} {2 \cos(\alpha)}$.


MySQL append , prefix a range of numbers with 0

Question: I have around a few thousand rows with which contain 3 digit numbers starting with 100 and ranging to 199 which i need to prefix with 0. There are also thousands of other numbers 4 digit numbers as well which i don't want to change.
I need find all the 3 digit numbers in the range and prefix only those ranging from 100 -199 with a 0 so as they are 4 digits eg 100 > 0100 , 104 > 0104 and so on.
Also these numbers may step eg 110 next is 124.
Is there a way I can do this using SQL? as i don't fancy changing these manually!
Many Thanks
Comment: Is there a scripting language you are using?
Comment: Im using PHP5 and using MySQL Front.
Comment: Check that the field is a CHAR, as adding a zero to the left of a number and saving it to the db will only remove it again  (numbers don't start with a zero)
Answer: This is best done with a programming language. That said, here's a SQL query that will update all the existing numbers:
UPDATE tableName SET fieldName = right(concat('0000',fieldName), 4) WHERE length(fieldName) < 4

Comment: Thanks cpharmston, you would think looking at that it would just replace everything < 4 with 0000. But it doesn't it retains the original number and works great-  thanks, you saved me a lot of time. Cheers.
Answer: The LPAD function is what you are looking for. You can use this in your query to pad the numbers on the fly.
SELECT LPAD(CONVERT(num AS CHAR), 4, '0') FROM tbl WHERE num > 99 AND num < 200

If you prefer to do this on the script side, str_pad will do the same in php.
Comment: Thanks Dane the Sane. Ill try that as well but the above seems to work ok.


Load objects for the map based on current view bounds

Question: I have a Rails web app with a Google map, which shows markers from a Mongoid database.
The amount of markers is really high and loading them all at once is very time and resource-consuming. Because of that, I'm loading the objects based on the map's current view bounds, but there is one problem:
New objects need to be loaded when the bounds change (bounds_changed event), but I don't want to add duplicate markers. I haven't found any way of doing this except creating an index of all the loaded objects and then comparing every loaded object with that. But I think there can be a more efficient way.
https://github.com/shvelo/pathfinder
https://github.com/shvelo/pathfinder/blob/master/app/assets/javascripts/client.js
Answer: I couldn't find the bounds_changed event in your git repo, but you're pretty much doing it right from what I can gather. Example:
var loaded = {"markerID1":true, "markerID2":true, ...};

if(!(marker in loaded)){
//Do stuff
}

No better way as of now. Although, ECMAScript 6 will soon the new standard, and it implements a real Set object.
Comment: `loaded[marker]` is slightly faster than `marker in loaded` , so I'm using that


MERN stack app deployed on Heroku not showing donut svg charts (it works on localhost)

Question: I have created a statistics page that presents svg donut chart components (the package is react-donut-component) but on heroku the statistics do not appear. Below are the screenshots of heroku and localhost.

STATISTICS COMPONENTS
GameChart.js
import { DonutMultiple, DonutElement } from 'react-donut-component';

function DonutChartGame(props) {
  const { values } = props;
  const colorsArr = ['#c2f158', '#82aac5', '#e93c42'];

  return (

Games

      <DonutMultiple linecap="butt" size={150} strokeWidth={20} animate={true}>
        <DonutElement color={colorsArr[0]} name={values[0].status}>
          {values[0].value}
        </DonutElement>
        <DonutElement color={colorsArr[1]} name={values[1].status}>
          {values[1].value}
        </DonutElement>
        <DonutElement color={colorsArr[2]} name={values[2].status}>
          {values[2].value}
        </DonutElement>
      </DonutMultiple>

  );
}

export default DonutChartGame;

TournamentChart.js
import { DonutMultiple, DonutElement } from 'react-donut-component';

function DonutChartTournament(props) {
  const { values } = props;
  const colorsArr = ['#b834c6', '#1077c3'];

  return (

Tournaments

      <DonutMultiple linecap="butt" size={150} strokeWidth={20} animate={true}>
        <DonutElement color={colorsArr[0]} name={values[0].status}>
          {values[0].value}
        </DonutElement>
        <DonutElement color={colorsArr[1]} name={values[1].status}>
          {values[1].value}
        </DonutElement>
      </DonutMultiple>

  );
}

export default DonutChartTournament;

Answer: Seems that nothing can make it work. The only solution was to replace the react-donut-component package with react-chartjs-2.


$\mathbb Q$-basis of $\mathbb Q(\sqrt[3] 7, \sqrt[5] 3)$.

Question: Can someone explain how I can find such a basis ? I computed that the degree of $[\mathbb Q(\sqrt[3] 7, \sqrt[5] 3):\mathbb Q] = 15$. Does this help ?
Comment: This has nothing to do with [tag: finite-fields] (read its Wiki!), but is, of course, an otherwise perfectly good question.
Answer: Try first to find the degree of the extension over $\mathbb Q$. You know that $\mathbb Q(\sqrt[3]{7})$ and $\mathbb Q(\sqrt[5]{3})$ are subfields with minimal polynomials $x^3 - 7$ and $x^5-3$ which are both Eisenstein.
Therefore those subfields have degree $3$ and $5$ respectively and thus $3$ and $5$ divide $[\mathbb Q(\sqrt[3]7,\sqrt[5]3) : \mathbb Q]$, which means $15$ divides it. But you know that the set $\{ \sqrt[3]7^i \sqrt[5]3^j \, | \, 0 \le i \le 2, 0 \le j \le 4 \}$ spans $\mathbb Q(\sqrt[3]7, \sqrt[5]3)$ as a $\mathbb Q$ vector space. I am letting you fill in the blanks.
Hope that helps,


Updating elements atomically retrieving from Map using Java 8 parallel streams

Question: I have a parallel stream in which I'm using a Map to mutate the elements.
Map<Long, List<MyItem>> hashmap = foo.getMap();

itemStream.parallel()
  .filter(Objects::nonNull)
  .forEach(item -> setProperties(hashmap, item));

The method 'setProperties()' takes the map and item, and performs a get using item and then sets some attributes of the item.
What I want is for the getting/property setting to be done atomically. So that two threads can't perform a get on the same key and have property updates be interleaved.
private void setProperties(Map<Long, List<Item>> map, Item item) {
    long id = item.getID();
    List<Object1> items = map.get(id);
    for (Object1 ob : items) {
            ob.setId(item.getFloorId());
            ob.setPath(item.getPath());
            ob.setTypeName(item.getTypeName());
    }
}

Also a bit concerned about the latency hit and whether this sort of parallelization will really have a benefit vs the existing single threaded approach.
Comment: Do these items with the same ID contain contradicting data? If so, how do you want to solve these contradictions? If not, what's stopping you from filtering out these duplicate IDs before performing the operation?
Comment: If your `itemStream` doesn't have duplicates (or duplicated `ID`s) then there will be no interleaving `get()` calls for the same key
Comment: Don't have that guarantee, may have duplicate IDs @Ivan
Comment: @JacobG. at leas tin Java 8 in CHM `get()` is a non-blocking operation
Answer: Synchnorising the Map or the get from it has no benefit, because the map is not being altered so there's no race condition.
You need to synchronise the updates so they happen all-at-once:
for (Object1 ob : items) {
    synchronized (ob) {
        ob.setId(item.getFloorId());
        ob.setPath(item.getPath());
        ob.setTypeName(item.getTypeName());
    }
}

This will have very little impact on performance, because these days synchronising introduces very little overhead and you will only block if the same Item is being operated on.
Comment: Can you put some light on your point "these days synchronising introduces very little overhead"? I wanna know more.


Smacking the ball down without hitting the opponent's hand when they hold the ball with two hands

Question: When my opponent holds the ball with two hands can I smack the ball down without hitting the hand?
Comment: I asked this question a awhile ago: https://sports.stackexchange.com/questions/12877/what-are-reaching-fouls-in-the-nba
Comment: You can hit both hands and no ball whatsoever, and it's not a foul. When a hand is in contact with the ball, it counts as the ball.
Answer: That is perfectly legal, so long as you don't hit their arms or hands as well, which would constitute a 'reach in' foul. You aren't allowed to touch an offensive player with the ball except in a few restricted ways - slapping them isn't one of them.
The question linked by Kevin Tinnemans in the comments to your question has the official rules regarding permissible contact with the offensive player with the ball.


Why does the value of a conversion rate change the number of observations required when calculating statistical power?

Question: This is probably basic, but I haven't come across it before:
With a minimum detectable effect of 10% and a baseline conversion rate of 0.44% it takes 265,857 observations per cohort to reach 80% power (1-sided test with 5% alpha).
Keeping the same parameters, but changing the baseline rate to, say, 44%, we see only 1,573 observations are needed per cohort.
Why does the value of the conversion rate change the number of observations required?
Code (Using R power.prop.test)
# Choose baseline (control) conversion rate
      #BaselineConversion <- 0.0044 # <- This is the real conversion rate
      BaselineConversion <-  0.44   # <- This is the adjusted rate for comparision

  # We want to be able to detect a minumium of 10% drop in conversion rates (i.e. if the reduction in conversion rates is <10% we don't care)
    minDetectedDrop_10pct <- 0.1

  # Power calculation: -10%
    minDetectedConversion_10pct <- BaselineConversion*(1-minDetectedDrop_10pct)
    testResult_10pct <- power.prop.test(
      p1= BaselineConversion,
      p2 = minDetectedConversion_10pct,
      sig.level = 0.05,
      power = 0.8,
      alternative = 'one.sided')
    paste0('Number observations needed with baseline conversion of: ',BaselineConversion,' is: ', round(testResult_10pct$n))

Comment: The bigger the effect size, the less observation you will need to show a statistical significance (got I hate that phrase).
Comment: Thanks for your reply... so I guess when you say 'big' you mean relative to the denominator right? So even though the numerator could be hundreds of thousands, if the denominator is much bigger, that's still a small effect size.
Comment: If you measure A LOT of giraffes in Africa and you notice a 1 mm statistically significant difference in height between the Masai and Angolian population... would you make this biologically significant? Hint, giraffes can grow up to 5-6 meters.
Answer: The average number of success with success rate p is p for binomial distribution. So the difference between p and 0.9 * p is proportional to p. In your examples, 10% of 0.44 is much greater than 10% of 0.0044 .
The figure below shows the probability density of the success number from 1000 draws. The success rates are 0.05, 0.5, 0.95 for the solid lines from left to right. The success rates of the dashed lines are 10% smaller than the solid lines.

Observe that the variance is wider in the middle and thinner on both sides, but its effect on power is not as strong as the distance between peaks. (Note that the variance of average success is p(1-p)/n)
The R code for the plot.
N = 1000
x_ = 0:N
plot(x_/N, dbinom(x_, size=N, prob=0.05) * N, type='l', xlab='Mean success number', ylab='Density')
lines(x_/N, dbinom(x_, size=N, prob=0.05*0.9) * N, lty=2)

lines(x_/N, dbinom(x_, size=N, prob=0.5) * N, col='red')
lines(x_/N, dbinom(x_, size=N, prob=0.5*0.9) * N, lty=2, col='red')

lines(x_/N, dbinom(x_, size=N, prob=0.95) * N, col='blue')
lines(x_/N, dbinom(x_, size=N, prob=0.95*0.9) * N, lty=2, col='blue')

Comment: Thanks for the clear answer (and sorry for the delay in accepting). I think this was a side remark, but I'm curious why is the 'variance in the middle'?
Comment: Do you mean why is the variance in the middle wider?
The variance of binomial distribution is `np(1-p)`. So the variance of binomial distribution divided by `n` (i.e. success rate) is `p(1-p)/n`.

if p=0.1, 0.1*0.9 = 0.09;

if p=0.5, 0.5*0.5 = 0.25;

if p=0.9, 0.9*0.1 = 0.09;
Comment: Ok cool, so it's just a mechanical effect from the definition of variance in a binomial distribution. Thanks for all the clarity!
Comment: Thank you for the interesting question! After thinking twice, both extreme cases do give a feeling of less "surprises" than the middle 50/50 case does.


Are integrals taught in Precalculus?

Question: I am high school student with an interest in mathematics. My school allowed me to self-study Pre-calculus over the summer so that I can move into AP Calculus AB next school year. I'm using a course on edX called Discovery Precalculus and things are ok for the most part, but I've recently hit a rough patch. I've come across a question that's asking me to find the algebraic measure of the space between a curve and the x-axis. From what I know, this would imply using integrals, but how does this make sense if this is meant to be a precalculus course? I've never worked with integrals or derivatives before.
The Question
I am given the function $f(t) = \frac{1}{t}$. It says our activities are restricted to the interval $t\in[1,3]$, which I'm guessing, in the language of calculus, would be the limits. The next things it tells me to do is plot the function on a coordinate plane with a scale of 0.1. The $f(t)$ axis goes from $0$ to $1.1$ and the $t$ axis ranges from $0$ to $3.1$. Now, from what I know so far about functions, $f(t)$ should be representing the y-axis and $t$ should be representing the x-axis. Finally, I'm told to plot the function along the domain interval $[1,3]$. So after I've done all of this, it states: The function that represents the accumulated area under $f(t)$ on the interval $[1,x]$ where $x\in[1,3]$  will be called $L(x) $. What is the value of $L(1)$?
The issue
I'm pretty sure it's asking me to find the area between the point $[1,1]$ and $[1,3]$, but how do I do this? It can't possibly be asking me to use integrals when the concept has never been brought up within in the scope of the course. I tried to sort it out and the farthest I got was $\int_1^3$, which I'm not even sure is right. Is there some sort of intuitive thing that I'm missing?
edit - Here is the entire problem as presented in the course (This just includes the first part, where it asks for $L(1)$):
Comment: It's asking for $L(1)$, not $L(3)$? That would make things much easier, but to the point of silly.
Comment: My advice is to forget about integrals. There is no mention of integrals in the question. Assume you know nothing of integrals and literally answer the questions as they come. For example, L(1) = 0 because the area under f(x) from x = 1 to x = 1 is 0. Since you are being asked to carefully graph with a lot of detail, the later questions are probably asking about approximate areas. You are not going to get the exact value of L(2) (which, by the way, is the natural log of 2).
Comment: I think @aschepler is onto it, and I don't think it's silly either.  You need calculus to *compute* $L(x)$ for $x>1$, but you can discover lots of information about it from the graph of $f$.  That's a pretty good skill to have, especially in a precalculus course.
Comment: Perhaps the instructions mean for you to plot points with $x$-values incrementing by $0.1$. This would let you make fairly narrow rectangles under or over the curve, to get a lower and upper bound for the area. In other words, use rectangles of width $\Delta x=0.1$.
Comment: http://www.mathwords.com/t/trapezoid_rule.htm
Comment: That's what it seems to be asking. edit - I just looked at the rest of the questions and it also asks to solve for $L(2)$ and $L(3)$.
Comment: So, I should be able to answer the questions just from the graph alone?
Comment: @CaptainAmerica16.  Well, now that you've added information about the question (that you need to find $L(2)$, and $L(3)$), I would say no.  Could you just transcribe the problem statement completely into your question?
Comment: This was so helpful. Thank you, I was probably over thinking it.
Comment: @Leonard Blackburn I see now that this was an exercise in learning the value of $e$. L(3) ended up being 1.1 which makes sense with the interval of the graph being $[1, 3]$.
Comment: +1  At least you took the trouble to think about the question and give the complete statement :)
Answer: Answer -

 $ L(1) = 0 $

Explanation -
What does the question mean ?
This is an excellent question, which gives you hints about several important results in mathematics, including a very important property of definite integrals. In a nutshell, it is asking you this -
We are defining a function $ f(t) = {1 \over t } $ on the interval; $ [1,3] \subset \mathbb{R} $. If we define $L(x) = \int_{1}^{x} f(t) \ dt $, find $ L(1) $.
This basically means -
We agree that $ f(t) $ represents the reciprocal, $ {1 \over t} $ of the real number $ t $. $ t $ can be between 1 and 3, both inclusive. Now we also agree that $ L(x) $ represents the area of the graph of $ { 1 \over t } $ from $ t = 1 $ to $ t= x $. Then find $ L(1) $ ?
This simplifies to -
Find the area under the graph of $ { 1 \over t } $, from $ t = 1 $ to $ t = 1 $.
So, how do we get the answer from this ?

 Now, this should be pretty obvious after the rewording. Basically, you are asked to find the area under the graph for the point $ t= 1 $.Now, the area under the point is just the area of the line segment under the point $ (1 , 1) $ till the $x$-axis, i.e. the area of the line segment joining $(1, 1)$ and $(1 , 0)$. And guess what ? that area is $0$. LOL :).

--Space left to prevent viewing in one look :P--

Great, but you said something about important results in math ...
Well, to start of with, saying that the area under the point is $0$, is equivalent to saying (well, not absolutely equivalent, but thats another story)-
$ \int_{a}^{a}f(x)\ dx = 0 $
Now, that is quite obvious and simple, but is quite important just the same.
Also, it talks about drawing the graph in (pretty narrow), intervals of $ 0.1 units $ ($=1mm$, i guess), which can mean two things -

Suggesting the geometrical interpretation of definite integration (See, the animation in the link). This is typically the first intutive notion of definite integration in calculus courses.
Suggesting an intuitive notion of approximation ( numerical integration, see this and this ) techniques, such as the trapezoidal rule.

To me the first seems more likely than the second possibility (or maybe its a bit of both ).
Comment: The definition of $L$ should be $L(x) = \int_1^x f(t)dt$. You mixed the integrating variable and the variable of $L$.
Comment: I see, i will edit for clarity's sake. (It doesn't of course matter what the variable of integration is) ;-)
Comment: @red_trumpet See edited answer.
Comment: @DevashishKaushik  Thank for taking the time to add such a detailed explanation! Since asking this, I was able to get my hands on an actual calculus textbook and have come many more problems like this. I understand now that it teaching about finding an approximation for the area under the curve in an attempt to provide an intuition for using integrals as well as provide an application for the use of $e $.
Answer: This comment under the question hit the nail mostly on the head, I think:

My advice is to forget about integrals. There is no mention of integrals in the question. Assume you know nothing of integrals and literally answer the questions as they come. For example, L(1) = 0 because the area under f(x) from x = 1 to x = 1 is 0. Since you are being asked to carefully graph with a lot of detail, the later questions are probably asking about approximate areas. You are not going to get the exact value of L(2) (which, by the way, is the natural log of 2)
  -  Leonard Blackburn Jul 3 at 14:40

Of course it has something to do with integrals. In particular it looks like the course authors are trying to introduce students to the kind of question that will later receive an answer in form of integrals. Perhaps the idea is that by having seen such an approximation done before they see limits and derivatives, they will later have an easier time keeping the big picture in mind instead of being bogged down in meaningless symbolic manipulations when they actually learn integrals.

Are integrals taught in Precalculus?


Using JS to determine range slider background widths

Question: I'm trying to control range slider track background widths using jQuery. I'm left scratching my head as to why the background doesn't seem to match the position of the slider however.
You can see the working page here: https://qh.brightchoicemarketing.com/hosting/cloud-vps-hosting/
(View on Chrome or any other Webkit browser)
Here is my code:
// .chrome styling
    $( 'input' ).on( 'input', function( ) {
        var x = document.getElementById("cpu").max;
        var x = document.getElementById("ram").max;
        var x = document.getElementById("ssd").max;
        console.log(x);
        y = this.value - 1;
        console.log(y);
        var percentWidth = ((y / x) * 100);
        console.log(percentWidth);
        $( this ).css( 'background', 'linear-gradient(to right, #da0266 0%, #00aeff '+percentWidth +'%, #eef1f8 ' + percentWidth + '%, #eef1f8 100%)' );
    } );

I am logging the values to console and the percentages appear to be correct. I next thought perhaps I had set a manually offset to move the slider thumb but I haven't and the background seems to go from too small to too large as you move the slider thumb from left to right (this makes me think it's a multiplier issue...).
Is my maths correct? I subtract 1 from the slider value to deal with the "0" position and then generate the percentage width that the slide thumb should be at.
EDIT:
I am adding custom values to all of the sliders apart from the first one (this is to ensure they show what the user is actually selecting before pushing to the store):
// Output value for CPU range slider
var sliderCPU = document.getElementById("cpu");
var outputCPU = document.getElementById("valueCPU");
outputCPU.innerHTML = sliderCPU.value;

sliderCPU.oninput = function() {
  outputCPU.innerHTML = this.value;
}

// Set and output custom values for Memory range slider
var valuesRAM = [0,"256 MB","512 MB","1 GB","2 GB","3 GB","4 GB","5 GB","6 GB","7 GB","8 GB","9 GB","10 GB","11 GB","12 GB"];

var sliderRAM = document.getElementById('ram'),
   outputRAM = document.getElementById('valueRAM');
sliderRAM.oninput = function(){
    outputRAM.innerHTML = valuesRAM[this.value];
};
sliderRAM.oninput();

// Set and output custom values for SSD range slider
var valuesSSD = [0,"10 GB","20 GB","30 GB","40 GB","50 GB","60 GB","70 GB","80 GB","90 GB","100 GB","200 GB","300 GB","400 GB","500 GB"];

var sliderSSD = document.getElementById('ssd'),
   outputSSD = document.getElementById('valueSSD');
sliderSSD.oninput = function(){
    outputSSD.innerHTML = valuesSSD[this.value];
};
sliderSSD.oninput();

Comment: what do you mean by the background doesn't match the slider? the gradient background is following the slider fine for me in Firefox. I updated your question for Chrome - seems to be an issue in Chrome
Comment: Thank you, yes it is a Webkit browser issue. Affects Safari as well.
Comment: Do you have `background-size` set correctly? Do not use `auto`
Comment: I have it set to `cover`, doesn't seem to make a difference though.
Answer: Add background-size: 105% 100% !important to this selector:
input[type="range"] {
        outline: none;
        transition: background 450ms ease-in;
        -webkit-appearance: none;
        cursor: pointer;
        border-radius: 16px;
        height: 15px;
        -webkit-box-shadow: 0px 2px 2px rgba(255, 255, 255, 0.25), inset 0px 1px 3px rgba(0, 0, 0, 0.3);
        background-size: 105% 100% !important
    }

Seems to work for me in Chrome and Firefox
Comment: Finally fixed it! I didn't realise, but I was selecting 'input' and applying the styles. I changed this to select individual inputs by their IDs and it's all working now! In general, your answer was the actual fix to the problem and so I've marked it! Thank you very much!
Comment: The "Processor" slider is still exhibiting the issue though. Think it's the calculation?
Comment: You're right, it's strange why only 1 is affected. Is there anything unique about that slider? It is known that webkit requires both values of `background-size` to be set to a fixed value when dealing with widths/heights.
Comment: It's the only slider I am not adding custom values to, I'll add this to the main question.
Comment: After playing around with the settings a little bit more, I set the max number of values for the "Processor" slider to 14 and the background began to fit perfectly. I then realised that no matter which slider I was changing, the x value would always equal 14. I think maybe because I am setting x 3 times in the same script without any conditional statements...


Escala de cor do Treemap com Plotly

Question: Fiz um treemap utilizando o pacote treemap, em que a área de cada caixa está relacionada a variável Valor e a cor de cada caixa está relacionada a variável escala, que foi criada a partir da variável Nota. Em escala de vermelho a cinza, conforme figura abaixo:
library(data.table)
library(tidyverse)
library(treemap)
url <- "https://raw.githack.com/fsbmat-ufv/stackExchange/main/df2.csv"
df <- fread(url)
df$escala <- scale(df$Nota)
treemap(df, index = "MUNICIPIO", vSize = "Valor", vColor = "escala",
        type = "value", palette = "-RdGy", lowerbound.cex.labels = 0.1,
        title  =  "Treemap Rio de Janeiro",
        overlap.labels=0.05)

Gostaria de criar o mesmo treemap com o plotly, ou um bem parecido, de tal forma que a área das caixas estejam relacionados a variável Valor e a cor esteja em intensidade relacionada a variável Nota ou a variável escala. Criei o código abaixo mas não obtive sucesso. Alguém possui sugestão?
    color <- colorRamp(c("Red", "gray"))
colorlist <- rgb(color((df$Nota)/max(df$Nota)), max = 255)
df  %>%
  plotly::plot_ly(labels = ~ MUNICIPIO,
                  values = ~Valor,
                  parents = ~NA,
                  type = 'treemap',
                  ids = ~Nota,
                  hovertemplate = paste0("Cidade: %{label}<extra></extra>
",
                                         "Nota Média: %{id}")) %>%
  plotly::layout(title = "Patent scape",
                 colorway = colorlist)

Comment: Tente mudar a colorlist para: `rgb(color((df$Nota)/max(df$Nota)), max = max(df$Nota))`. Caso a `max(df$nota)` seja por exemplo 10. Todos os valores de cor estarão longe de 255.
Comment: @PauloMarques agradeço, mas não funcionou!
Answer: Consegui, agora vou trabalhar um pouco mais na palette para ficar parecido com o primeiro:
unique_values_count <- length(unique(df$Nota))
palette <- colorRampPalette(c("gray", "Darkred"), alpha = F)(unique_values_count)
assigned_colors <- c(palette[cut(df$Nota, unique_values_count)])
plotly::plot_ly(
  data = df,
  type = "treemap",
  labels =  ~ MUNICIPIO,
  parents = ~ NA,
  values =  ~ Valor,
  ids = ~Nota,
  marker = list(colors = assigned_colors),
  hovertemplate = paste0("Cidade: %{label}<extra></extra>
",
                         "Nota Média: %{id}"))

Answer: Atualizado em 13/12/2022
Nota: Não percebi que os valores não estavam em ordem. Para resolver, basta ordená-los com sort(df$Nota, decreasing=TRUE)
Resposta Original modificada com o sort
Parece que o colorRamp está pegando uma cor diferente para cada resultado de df$Nota/max(df$Nota), o que faz sentido, pois todos os resultados são diferentes.
Usando colorNumeric pode resolver esta questão.
library(data.table)
library(tidyverse)

url <- "https://raw.githack.com/fsbmat-ufv/stackExchange/main/df2.csv"
df <- fread(url)

pal <- colorNumeric(
  palette = "Reds",
  domain = sort(df$Nota, decreasing=TRUE))

df  %>%
  plotly::plot_ly(labels = ~ MUNICIPIO,
                  values = ~Valor,
                  parents = ~NA,
                  type = 'treemap',
                  hovertemplate = "Cidade: %{label}<extra></extra>") %>%
  plotly::layout(title = "Patent scape",
                 colorway = ~pal(sort(df$Nota, decreasing=TRUE)))

O resultado é

Caso queira usar outra palette...
pal <- colorNumeric(
  palette = "RdGy",
  domain = sort(df$Nota, decreasing=TRUE),
  reverse = TRUE)

Resultado

Outra possibilidade é usar o colorBin com a escala que vc definiu
df$escala <- scale(df$Nota)

pal <- colorBin(
  palette = "RdGy",
  domain = sort(df$escala, decreasing=TRUE),
  reverse = TRUE,
  bins=seq(-2.5, 2.5, 0.5))

df  %>%
  plotly::plot_ly(labels = ~MUNICIPIO,
                  values = ~Valor,
                  parents = ~NA,
                  type = 'treemap',
                  hovertemplate = "Cidade: %{label}<extra></extra>") %>%
  plotly::layout(title = "Patent scape",
                 colorway = ~pal(df$escala))

Resultado

Nota: Usei o domínio de -2.5 até 2.5, pois haviam valores fora da escala.
Comment: @fsbmat, o intuito é ajudar você da melhor maneira possível e os demais que venha a cair nesta página. No entanto, tem pessoas que procuram por ajuda, não encontram e dão `dislike`, outras acham que a resposta não está correta e dão `dislike` ao invés de ajudar e corrigir a resposta, outras fazem isso sem razão, e sabe-se lá qual outra razão. Enfim, atualizei o post com o `colorBin` utilizando `df$escala` que parece que é o que você procura. Caso não seja, me desculpe por não ter entendido a demanda.
Comment: @fsbmat. Atualizei o post. Não havia percebido que as notas não estavam drenadas.
Comment: Oi @Paulo Marques, na verdade, não quero colorir o treemap de acordo com os valores e sim de acordo com a nota. Veja o primeiro treemap que coloquei na pergunta! Não entendi porque a resposta está, juntamente com a pergunta, com deslike?
Comment: pois é, complicado o pessoal não entender o papel do like e do dislike! Agradeço muito sua ajuda, mas o resultado não é o que desejo. Se você conferir as cores e as notas, verá que o plot_ly não obedece a escala de cor. Adicionei mais um argumento no meu código que ajuda a visualizar a nota e verificar que a cor não está bem relacionada com a mesma!

Escala de cor do Treemap com Plotly


Find rectangular box which has biggest volume

Question: Exercise: Find rectangular box with surface area 10 that has minimum volume
My solution: We know that surface area is $$S= 2(wl +hl+hw)$$and volume $$V=whl$$ ,where w-width,h-heigh, l=length.
We will use lagrange function$$L = whl - \lambda(2(wl +hl+hw)-10)$$.
Now we will find partial derivatives w.r.t $w,h,l,\lambda$ respectively
$$1)hl-2h\lambda-2l\lambda \\ 2)wl-2l\lambda - 2wl\lambda \\ 3)wh-2w\lambda-2h\lambda \\ 4) 2(wl +hl+hw) - 10$$
By setting this equations to 0 we will get that $l=h=w$. Then inset into Surface equation and we will get that the volume will be the biggest when $w=h=l= \sqrt{\frac{5}{3}}$.
Did i solve it correctly?
Answer: As an alternative and to check let use AM-GM inequality
$$\frac {S} 6= \frac{wl +hl+hw}{3}\ge\sqrt[3]{w^2l^2h^2}\implies V^{\frac23}\le\frac {5}3\implies V\le\sqrt{\left(\frac{5}3\right)^3}$$
with equality for $$wl=hl=hw \implies w=l=h=\sqrt{\frac{5}3}$$


How to show that a solution is not derivable?

Question: This morning I was reading from How To Solve It - George Polya. One of his questions gave a set up about a bear leaving some point $P$, gave some info about the path the bear took, then asked "what color was the bear?"
The answer to the problem was white, and one comes to this answer because using the information given you can show geometrically, assuming the earth is perfectly spherical, the information about the bears path could only happen if the point $P$ was the north pole, so one infers the bear is a polar bear, thus is white.
I don't really care about the geometry of the problem but it sent me into a tailwind thinking about "If I wanted to be an ankle biter, how would I actually justify that the color of the bear cannot be deduced from the sentences given?". I am aware of independence results, complicated things like AC and CH (aware that they were proven to be independent, I do not understand how the techniques used to do so actually work), but for simpler things can anyone explain, or direct me, or tell me what I could look up to get a sense of how to show something is not derivable from some set of hypotheses? I have a feeling such information would be in the language of first order logic, mathematical logic or proof theory, which I know little to nothing about.
Even when studying for the GRE there are multiple choice questions where sometimes the correct answer is "not enough info". If it was something with order relations I might have an idea of how to prove that it cannot be deduced. For example,
If $a<b$ is $a^2 < b^2$ or is $b^2 < a^2$? One could quickly give examples where both outcomes are possible unless the hypothesis is strengthened to nonnegatives. But I feel like it is possible to do so in this case because we have only two possible options to exhaust and showing they are both possible means such a conclusion cannot be proven from the hypothesis.
Please edit away if there is anything wrong with my question.
Answer: This particular problem is more a brainteaser than mathematics.
A little mathematical insight will tell you the bear's walk must
have started at the North Pole. But that's all the math there is in the
problem.
There is no mathematical reason why the bear must be white;
someone could have airlifted a grizzly bear to the North Pole and
let it loose to walk this path.
But since the color of a bear whose walk starts at the North Pole
is the "brain teaser" part of the problem,
you are intended to think through the "most plausible"
events that could have occurred, and the idea that the bear was one that
was likely to be found naturally near the North Pole seems to
be a better fit to the story than the possibility of any other
kind of bear appearing there.
These reasons why the color of the bear is determined (or not)
involve kinds of real-world reasoning that are sometimes called
"using common sense" or "exercising judgment"
and are notoriously difficult to express in mathematical logic.
The difficulty of this sort of thing has fueled a lot of the research
that was done in artificial intelligence over the last sixty years or so.
As far as I'm aware there is still no general solution to the problem.

Now let's consider questions in which
the options to be chosen among are susceptible to mathematical logic
(unlike the color of a bear found at the North Pole).
First, consider your example:

If $a<b$, is $a^2 < b^2$ or is $b^2 < a^2$?

A somewhat more general format of this question, allowing for any finite
number of unknown quantities and any finite number of choices (two or more), is,
"Given $P(x_1, \ldots, x_n)$, which is true: $Q_1(x_1, \ldots, x_n)$, $Q_2(x_1, \ldots, x_n),\ldots$,
$Q_{k-1}(x_1, \ldots, x_n)$, or $Q_k(x_1, \ldots, x_n)$?"
It seems to me you also mean to require the following two conditions:

The formulas $Q_1,\ldots,Q_k$ are mutually exclusive, that is,
no two formulas $Q_i(x_1, \ldots, x_n)$ and $Q_j(x_1, \ldots, x_n)$,
where $i\neq j$, can be true simultaneously for any choice of values of
$x_1, \ldots, x_n$ such that $P(x_1, \ldots, x_n)$ is true.
$Q_1,\ldots,Q_k$ are exhaustive, that is,
for every choice of values of $x_1, \ldots, x_n$,
if $P(x_1, \ldots, x_n)$ then
at least one of the formulas
$Q_1(x_1, \ldots, x_n),\ldots$, $Q_k(x_1, \ldots, x_n)$ is true.

This format assumes an implicit quantification over the variables
$x_1, \ldots, x_n$, namely, $Q(x_1, \ldots, x_n)$, and
an answer to the question (if there is one)
depends on which one of the $k$ following statements is true:
\begin{align}
(\forall (x_1, \ldots, x_n))
  & (P(x_1, \ldots, x_n)\implies Q_1(x_1, \ldots, x_n)), \tag{$\phi_1$}\\
& \vdots \\
(\forall (x_1, \ldots, x_n))
  & (P(x_1, \ldots, x_n)\implies Q_k(x_1, \ldots, x_n)). \tag{$\phi_k$}
\end{align}
For $i=1\ldots,k$, if $\phi_i$ is true then the answer is $Q_i$.
If no $\phi_i$ is true then the problem is indeterminate.
The example above also assumes (somewhat ambiguously) a domain
for the variables; in context, the domain would usually be whatever
things we had most recently defined that could be compared using $<$,
whose squares existed, and whose squares could be compared using $<$.
Out of context, we have to choose a suitable domain arbitrarily,
so I'll choose the integers.
(Like the color of the bear, that particular choice is an exercise
in judgment.)
This leads to consideration of the following two statements:
\begin{align}
\newcommand{Z}{\in \mathbb Z}
(\forall (a,b)) & ((a \Z \land b \Z \land a < b) \implies a^2 < b^2)
\tag{$\phi_1$}\\
(\forall (a,b)) & ((a \Z \land b \Z \land a < b) \implies b^2 < a^2)
\tag{$\phi_2$}\\
\end{align}
In this particular example, it's easy enough to show
that the statements $a^2 < b^2$ and $b^2 < a^2$ are mutually exclusive
(because $<$ is antisymmetric),
and not much harder to show that these statements are exhaustive
(because if $x$ and $y$ are integers, one of $x<y$, $x=y$, or $x>y$
must be true, and the condition $a<b$ rules out the case $a^2=b^2$),
so this is indeed a problem in the desired format.
To show that the answer to the problem is indeterminate,
we have to disprove both $\phi_1$ and $\phi_2$.
Disproofs of statements of this form are typically done by
counterexample; for example, a disproof of
$$
(\forall (a,b)) ((a \Z \land b \Z \land a < b) \implies a^2 < b^2) \tag{$\phi_1$}
$$
is just a proof of
$$
\lnot(\forall (a,b)) ((a \Z \land b \Z \land a < b) \implies a^2 < b^2),
\tag{$\lnot\phi_1$}
$$
which is equivalent to
$$
(\exists(a,b)) ((a \Z \land b \Z \land a < b) \land \lnot(a^2 < b^2)).
$$
By far the easiest way to prove this last formula
(and therefore disprove $\phi_1$) is by presenting a "witness"
such as $a=-2$, $b=-1$, which proves the last formula
because $-2\Z$, $-1\Z$, $-2<-1$, and $(-2)^2 \not< (-1)^2$.
Similarly, to disprove $\phi_2$ we can simply present the witness
$a=1$, $b=2$.
For a more general problem of this format, with $k$ alternatives,
you just need $k$ witnesses, not necessarily all different.
The "exercise in judgment" above was that I did not choose $\mathbb N$
as the domain because the idea of this example in the first place
was to show how something could be indeterminate (which would
not be the case here if the domain were $\mathbb N$);
I did not choose $\mathbb Q$ or $\mathbb R$ because any proof of
indeterminacy for $\mathbb Z$ can be extended to those domains as well;
and I did not choose any other domain because that would have been weird.
Comment: Out of curiosity did you finish reading my question?
Comment: Yes, but as the "ankle biting" concerns with the bear problem aren't really mathematical, we're kind of lacking a concrete idea of what other kind of problem we might want to deal with. Or maybe I just got too distracted by the bear.
Comment: The reason I included the prelude with Polya's problem was, I guess, just to give an idea what sparked the interest. When I said "If I wanted to be an ankle biter" was because, if I proved that the color of the bear was not actually \textit{deducible} from the information given (as in actually deducible, not just a sequence of clues that allow reader to make an inductive inference) then I would be an ankle biter since I would have proven that Polya's answer was wrong. I guess the whole point of my question is how would one formulate an argument to prove something is not derivable.
Comment: I believe in mathematical logic, what I am asking is, how does one show $P \neg \vdash Q$ Where $P$ is the information given and $Q$ is bears color. Or could this not be done since the color is outside of the domain of discourse?
Comment: And to answer your question, mathematical logic is what I believe I'm concerned with, hence the tags.
Comment: I've tried to address a reasonably general mathematical problem of this kind. The color of the bear indeed is outside of that realm. I've chosen predicate logic without the turnstile notation.
Answer: Here's a very general kind of answer to this very general question:

how to show something is not derivable from some set of hypotheses?

There are several ways, that usually rely on proof by contradiction in some form. Most don't depend on serious study of mathematical logic.

Pythagoras knew how to prove that there is no rational number whose
square is $2$ .
Showing that $\pi$ isn't the root of a polynomial with rational
coefficients is harder. See
How hard is the proof of $\pi$ or $e$ being transcendental?
.
For GRE questions where the choice is among several possible answers,
you can try them all and show none works.
You can prove that Euclid's parallel postulate can't be derived from
the others by building a model inside Euclidean geometry where the
parallel postulate fails. I'm particularly fond of the Poincare model.
Finally, there's Godel's theorem, proving that there are
unprovable propositions ...


getElement não declara o objeto (VBA) .IE

Question: preciso de uma ajudinha em um codigo, VBA interação em IE, uso uma pagina para extrair relatorios diarios, e atualmente esse pagina sofreu uma atualização de versão, meus codigos estão quase todos funcionado porem o codigo que teria que acionar um botão para gerar um relatório de informações, não esta funcionado, tentei varias formas mas sem sucesso, meu conhecimento é ainda, acho que e coisa simples, mas eu não consegui finalizar.
codigo da pagina IE.

<button title="Iniciar" class="sapMBarChild sapMBtn sapMBtnBase sapMBtnInverted" id="__bar2-btnGo" aria-describedby="__text13" data-sap-ui="__bar2-btnGo">Iniciar</button>

Cod VBA IE.
'IDENTIFICA A DATA DA REQUISIÇÃO (FINAL) ' ok funcionado

Set objCollection = IE.Document.getElementsByTagName("input")
For Each objElement In objCollection
    If objElement.ID = "__xmlview0--filterDtEndRequest-inner" Then objElement.innerText = Data2
Next objElement                                  '

'IDENTIFICA O BOTÃO PARA EXECUTAR ' Com erro abaixo
'*************************************************************

Set objCollection = IE.Document.getElementsByTagName("button")
For Each objElement In objCollection
    If (objElement.getAttribute("title") = "Iniciar") Then objElement.Click
Next objElement

Comment: Codigo html

Iniciar )
Comment: Favor [edit] a questão com o código html
Comment: danieltakeshi ajuda este formato?
Answer: HTML
Adicionando um JS no código HTML para verificar se o mesmo foi clicado:

function toggleText() {
  var text = document.getElementById("demo");
  if (text.style.display === "none") {
    text.style.display = "block";
  } else {
    text.style.display = "none";
  }
}
<!DOCTYPE html>

  <title>Test HTML</title>

Hello Teste

  <button title="Iniciar" class="sapMBarChild sapMBtn sapMBtnBase sapMBtnInverted" id="__bar2-btnGo" aria-describedby="__text13" data-sap-ui="__bar2-btnGo" onclick="toggleText()">Iniciar
  </button>

Solução
É possível clicar no botão encontrando a tag do mesmo, que precisa ser "button" e se o texto for iniciar, porém utilizando a função Trim(). Pois o texto está com um espaço e é "Iniciar ".
'Declara função Sleep
#If VBA7 Then
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
#Else
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
#End If

Public Sub ClicarBotao()
    Dim IE As Object
    Dim url As String
    Dim myPoints As String

    url = "http://run.plnkr.co/plunks/TmODUSMPPAxswW7pqyfV/"
    Set IE = CreateObject("InternetExplorer.Application")

    With IE
        .Visible = True
        .navigate url
    End With

    EsperaIE IE, 2000

    Dim Doc As HTMLDocument
    Set Doc = IE.document

    For Each elemento In Doc.body.getElementsByTagName("button")
        Debug.Print elemento.Type
        Debug.Print elemento.innerText
        If Trim(elemento.innerText) = "Iniciar" And elemento.Type = "submit" Then
            elemento.Click
        End If
    Next elemento
    Set IE = Nothing

End Sub

Public Sub EsperaIE(IE As Object, Optional time As Long = 250)
    'Código de: https://stackoverflow.com/questions/33808000/run-time-error-91-object-variable-or-with-block-variable-not-set
    Dim i As Long
    Do
        Sleep time
        Debug.Print CStr(i) & vbTab & "Ready: " & CStr(IE.readyState = 4) & _
                    vbCrLf & vbTab & "Busy: " & CStr(IE.Busy)
        i = i + 1
    Loop Until IE.readyState = 4 Or Not IE.Busy
End Sub