How should I analyze this passage? As vii°7, V7, or both?

Question: So, I'm doing another Beethoven analysis, this time using the Liszt transcription of Beethoven's Fifth so that I can more easily see the harmonies and form. I am analyzing it passage by passage, first for the harmonies, and then for the form. I know, Beethoven's Fifth has been analyzed many times before. But most analyses I see of this symphony focus on how every movement is based on the Fate Motif rhythmically and/or melodically, how the Fate Motif is the one thing uniting all the movements, Beethoven's orchestration choices, and how from the first movement to the third movement, the C major finale is foreshadowed.
I rarely see a harmonic analysis of it and even more rarely do I see a formal analysis of this piece that goes into the phrasing and cadences. I'm focusing on the harmony and form of the piece. I thought the harmonies would be relatively simple to analyze. But early on, before I even reach the second theme, I am unsure how to analyze this passage circled in red:

I see two harmonies coexisting here, vii°7 and V7, with brief glimpses of the C minor tonic separating the 2 phrases from each other and from the next phrase. This and the way it is written makes me unsure how to analyze this passage.
Analyzing as vii°7
This works very well for the first 3 measures of the passage, where Beethoven is arpeggiating vii°7 using the Fate Motif. However, this means analyzing the G as a pedal point in the next measure, which I'm pretty sure isn't correct.
Analyzing as V7
This works better for the fourth measure of the passage, because the G isn't a pedal point here, unlike the C several measures later which is a pedal point. But then, what is the Ab in the first measure of the passage doing? It can't be a suspension, because it doesn't resolve anywhere, it simply leaps down a third to F. If I were to treat it as a suspension, it would have to be a 9-8 suspension without the resolution note G, which just does not sound right. Would it be an unprepared appogiatura? Would it be part of the F minor harmony right before this passage? The Ab in the third measure of the passage though is clearly a re-articulated 9-8 suspension if you analyze the harmony as V7.
You see what I mean? V7 makes total sense for the second, third, and fourth measures of the passage. vii°7 makes total sense for the first, second, and third measures of the passage. They each have 1 measure where a certain note that would have to be a non-chord tone doesn't make sense with the harmony and melody combined. For vii°7, that is G as a pedal point. For V7, that is the first Ab being a 9-8 suspension without the resolution note.
So, if each of the coexisting harmonies have 1 measure where a non-chord tone doesn't make sense with the harmony and melody combined and have 2 measures of overlap where both harmonies make sense, how should I analyze the harmony in this passage? As vii°7 to match with the arpeggiation? As V7 to match with the fourth measure of the passage? As vii°7 in the first 3 measures followed by V7 in the fourth measure?
Comment: Is there a reason (a) why it can't be viewed as transitioning from one dominant function chord to another (something that frequently happens) or (b) just be viewed as a Vb9 chord overall?  Why do we need to choose?
Comment: Doublecheck the measure before the fermata. That's an A-flat in the bass!
Comment: But then, if it is viewed as a transition from vii°7 to V7, where would it be transitioning from vii°7 to V7? The second measure of the passage? The third measure of the passage?
Comment: @AlbrechtHügli The third measure of the excerpt is an Italian augmented-sixth chord on account of the A-flat in the bass. OP's analysis, viio7/V, suggests that they read an A-natural there.
Comment: @Richard:  What do yo mean with this hint exactly? The most interesting point in this passage is the unisono fortissimo. I doubt that iv is correct. I'd rather say this is already anticipating the following phrase in the dominant function and I agree with others this can be assembled and reduced to V79.
Comment: @Richard Thank you. I've looked at the measure before the second fermata. Yes, this is a it. aug. 6th chord.
Answer: In bars 5 - 7 of your excerpt, an excursion to F minor is implied.  But in bar 8 et seq. the Ab and F are re-assigned as the top two notes of G7b9, the dominant of C minor (and Beethoven's favourite diminished 7th chord with a root note added to pin down WHICH of the four possible dominants it's being this time!) which is reached in bar 12 and strongly reinforced in the following bars. No, we're not off on a journey to distant keys, Beethoven hasn't yet finished pounding C minor into our hearts!
The basic problem seems to be that a dom7(b9) chord wasn't in your musical vocabulary.  It should be.  (And it is, now :-) )  It isn't a modern, 'jazz harmony' thing.  It's very classical, very Beethovenian, and integral to his liking for dim7 chords.
Comment: Thanks for pointing out the motif on `F` minor is an _implied_ move to a new key that isn't fulfilled. That is the interesting part to me. The part I thought could be easily misunderstood.
Comment: I fully agree with AbF as part of  V7b9. That's what I meant to say too, but I was not so clear in my answer. ;)
Answer: I don't know if there is a typical way the passage is analyzed, but I agree with @Athanasius: just label it Vb9.
There is a theoretical view that diminished seventh chords are incomplete dominant ninth chords where the root is omitted. From that point of view viio7 V7 just divides the ninth chord and literally writes out the two halves.
It's perfectly clear that it resolves to the C minor chord and so whether you label a single ninth chord, or two chords - diminished seventh followed by a dominant seventh - the function is dominant. That's what is important.
I think I prefer the ninth chord, because the passage moves with a constant descent like an arpeggiation. And I like analysis that simplifies without loosing the essentials. The simple dominant to tonic labeling is Vb9 i.
The only other thing that seems worth mentioning is the Ab doesn't literally resolve to G in the first iteration.
Comment: Um, what do you mean the Ab doesn't literally resolve to G in the first iteration? The Ab in the left hand of the third measure of the passage that I circled is one scale step up from the G in the right hand in the fourth measure of that same passage.
Comment: @Caters, I was speaking about the `Ab4` - the very first one of the descent - it doesn't step down to `G`. But really it's about all the `Ab`s, when the lower `Ab` moves to `G` it isn't moving to another chord, so where is the resolution? I suppose you could call it passing motion. All of this is just icing on the cake. It's a dominant chord rooted on `G` resolving to a `C` minor chord. It's a harmonic thing that doesn't require more analysis than that. There isn't really a counterpoint thing going on to necessitate discussion of voice movements, suspensions, etc.
Comment: @Michael: I'm only reading your answer right know. I can see that I haven't brought any new aspects +1
Answer: I'll just throw my two cents in, for what it's worth.  And I will apologize for the tone of the following, because to me, a distinction like this is not generally very helpful in bringing out new musical understanding.  It's seeking a type of rigor in classification that is often not possible in analyzing art.
To me, analysis should be about telling us something about how the music works.  Perhaps it tells us something about how the music is composed.  If that's the goal here, it's pretty unlikely Beethoven was thinking in Roman numerals, so arguing about this distinction isn't going to help us understand the compositional process.
Another goal might be to understand how a listener perceives the music.  If I were listening to this piece for the first time, I think it makes most sense to hear the A♭-F after the fermata as a repetition of the previous motive before the fermata, which does perhaps create some implication of F minor.  Maybe.  Or maybe not.  It's odd, because it comes right after that strong dominant, so it all sounds a bit "off."  (Strong half cadences are not frequently followed by naked subdominant chords.)  Maybe the A♭ and F are meant to be felt with some tension with the preceding dominant?  Hmm...
Still, maybe it's F minor, but there's some tension there.  Maybe it's D-flat major, since after all, the opening motive to this piece was scale degree 5 descending to 3 with a major third.  Maybe Beethoven wants to move toward the Neapolitan?  Wouldn't that be interesting!  Or, well, maybe it's boring old F minor after all.  We'll have to wait and see.  Music is a temporal art, so that's part of what happens as your interpretation has to unfold in time as your experience with the piece increases...
So when the A♭-F motive adds the D, maybe it is a predominant function again after all... a iv turning into a iio, maybe?  It's certainly not that possible Neapolitan move.  Too bad...
But, oh!  The next bar brings the B♮ -- the leading tone that creates a tritone interval and turns this into a dominant function harmony!  Yet the A♭ returns in the "tenor" voice, this time resolving as a ♭9 should down to G, the strong dominant root that is confirmed with the entrance of G in the bass.  That V7 then resolves appropriately to tonic.
Now, when I hear this passage repeated, there are more interpretations open.  Maybe I am suckered into the possibility of a predominant iv-iio possibility again, turning into viio and then V, but "fool me once, fool me twice..."??  So maybe the second time instead I might hear this whole thing as one continuous descending V♭9... or at least an overall dominant function chord.
The preceding type of experiential analysis (in the past five paragraphs) is to me ten times more useful than putting a single label on a chord, as it tries to get at how it feels to actually listen to the piece and try to figure out what's going on, what's going to happen, how things relate to what came before, etc.
A third possible type of analysis is what I think of as the "god's eye view" analysis, where one stares at the score and tries to group notes together for some generally unstated purpose, like an analysis assignment for an intro theory class.  There's no real concern with how the music is put together or how it functions or what a listener might perceive -- just an obsession with classification for classification's sake, and labeling for labeling's sake.  I don't find such exercises particularly useful or musical, so if that sort of label is desired here just to settle the "name" of the chord, just choose some arbitrary system of rules to break the tie and slap the label on.
(And, for the record, what I imagine most Roman numeral-y textbooks would say is that the place the harmony becomes clear is the last measure of the first line of the excerpt, where you have the notes of some sort of viio7, which then turns into a V7 in the next bar when the A♭ moves down to G.)
Answer: Really, it doesn't matter in the context of the rest of your analysis.
Out of the 9 chord markings I would only consider 4 of them correct. The rest demonstrate that you don't understand the concepts of inessential notes, suspensions, and anticipations.
And there is one gross error, where you apparently didn't notice the difference between A natural and A flat.
FWIW I would call it V7. The A flats aren't a chord tone at all. But it would take at least a chapter of a textbook (if not the whole textbook) to try and correct your wrong thinking over all of this.
Comment: @Caters - "Guest" is talking about the augmented sixth chord you mislabeled as viio/V by mistaking an A-flat for an A-natural.
Comment: Oh, I see it now. It's an Italian augmented sixth with the root of Ab.
Comment: There are no A naturals until towards the end of the first theme, or at least, not in the section of the first theme that is in my post. You must be confusing the B naturals with A naturals. First chord I marked? Clearly V7. Chords in the half cadence? Clearly i, vii°7/V, V. Last 3 chords I marked? Clearly i, ii halfdim 7, vii°7 with a pedal C. If anything, you are the one whose thinking is wrong.
Answer: This is what happens all the time in chord progressions like this iv-ii-vii°-V (V7b9):  falling 3rds, a common third in 2 chords. We know it from Bachs Piano Concertos and many other pieces, same situation in C-Am-F-Dm (e.g. Invention 13).
As others already wonder: We don't have to decide whether something is a vii dim or V7 or V7b9. The relationship is clear: functional they are dominant or dominant substitutions. First you might see a subdominant iv-ii°- vii°-V7 but I hear a broken chord G7b9.
The first fermata is G ... and it continues unisono Ab -> F. You say F minor(=iv)
Nobody can forbid me to hear this already as the 9th and 7th of G7(b9) ...
Quite different would be the Smphony's opening motif: mimimi do. Is it major or minor. We can only guess that in the context it must be minor (and the key signature of course, if we can see it...)
Comment: Me too, of course, but only as we know the context and we know it's cm. Otherwise it could be as well Eb and Bb
Comment: I don't think many people would immediately hear the dramatically stated Ab-F version of the main motif as the top of a b9 chord.  The twist is in it BECOMING that.
Comment: I hear a very clear i-V7 motion in the opening statement of the motif. It doesn't just imply Cm-G7, it is Cm-G7.
Comment: @AlbrechtHügli: I agree completely with your comment.  If we didn't know the symphony at all, the opening few notes could easily be heard as in Eb major.  In fact, one could imagine the second theme of the movement beginning with the same G-Eb gesture (instead of the Bb-Eb leap Beethoven uses).  For all we know after the first few bars, we could be in Eb major.  It's only later that subsequent context *retrospectively* allows us to surmise that the opening bars imply Cm-G7.
Comment: @ Lawrence: but it would be quite exceptional a subdominant after the fermata on the V. anyway, we can develop the intention after the resolving broken V79. Play it the AbF bar accompanied with ii7-5, this would also fit with our expections. But iv? A little bit strange.
Comment: @Albrecht Hügli I just wrote iv because the fortissimo Ab-F motion seems to me to imply F minor, which is the iv of C minor. It is only when I start hearing the arpeggiation that I hear the Ab-F motion as being part of a seventh chord. And this doesn't make me retrospectively think of the fortissimo right before it as being part of that seventh chord.


Defaut image value not showing up

Question: In my article content type, I've added a header image (field_header_image) field which I placed a default image into it so that all articles would have a default image used if one wasn't needed. However, when creating an article and leaving that field as the default value, it doesn't actually use that default value. The page is created as if that value is empty.
Is there any way to make sure that this default value is used?
Is there a way to do this through the .theme file? Is this the best way to do it?
Comment: The solution to my problem was solved with the following solution: [Loading default image from a node field in page.html.twig](https://drupal.stackexchange.com/a/261484/55607)
Answer: If the default image was set correctly then the newly saved article nodes should pick it up. Check if the website's log show any related error messages.
If you want to go with another method then just:

Copy node.tpl.php in your website's themes folder to node--article.tpl.php;
Open node--article.tpl.php in editor and place the following code just before print render($content);:

Save.
Clear your website's cache and revisit any article node.
Comment: I'm on a Drupal 8 website. I've done the above the D8 way and still the default image does not show up.
Comment: For Drupal 8 read https://www.drupal.org/docs/8/theming/twig/twig-template-naming-conventions. So the copy should be called `node--type.html.twig`.
Comment: The default image was set correctly and there are no error messages. I've created a node--article.html.twig template already and have the content printing...the default image doesn't show up; hence my original question. Is there a way to set the default image through the .theme file?
Comment: Just creating the file is not enough to get to desired effect, you need to also add code in step #2: ``
Comment: I've done all of that already, still doesn't work. If I print `{{ content.field_header_image }}`, I get nothing. Even running `{{ kint(content.field_header_image) }}` comes back as null, even though I have a default image set in the content type.
Comment: @ACanadianCoder, because it's clear there is something wrong with your field image I advised you to use DIRECT link to the image instead. Can you just get your template output simple `test` word first as I have an impression now you might be working with a wrong template file.
Comment: I can't use a direct link because I don't actually want it to be displayed within that template file. I just need the field to hold a value so that I can use it within my page.html.twig file as I have it grabbing that field from various content types and using it as the background image for my page headers.
Comment: You have to separate two different issues: 1) get anything (take a `test` word, for example) displayed in your template file first - just to make sure you have created the correct template file; 2) and when you success step 1 start troubleshooting why the filed is not showing its content. What dpm() is giving for step 2?
Comment: 1.) the template file works for everything else. I already have it themed the way I want with no issues as all the other fields work as intended. 2.) I've already done the troubleshooting to the furthest extent as I could figure out. Nothing seems to be giving errors or issues. The default image just doesn't hold a value, just null. That's why I'm seeing if there's a way to inject a default value through a preprocess function.
Comment: The default image won't be saved in each entries image field. It's just a replacement if there is no image loaded. So if you have a single default image for the content type, it is ok to use a direct link in if condition: `if (empty($image_field)) { print ''; }`

Defaut image value not showing up


when more foreign keys and need to insert is it good to use native @Query instead of JPA managed way

Question: There is a table with 3 foreign keys to three tables.
To do an insert using JPA, is it suggested/performant to

query individual tables(having foreign key relations) and create
  respecitve objects and do a .save()

?
or

use native @Query(), with @Transactional and @Modifying?

for making an insert, i am making 3 calls to DB to get respective objects/details and use them for insertion. so total 4 calls.
If i use native Query, i have the id's required(getting from client) i can do it in one query.
so, is it good to do in JPA way or use native query? which is good in view of performance?
Answer: If you have the primary keys of the dependencies you can call EntityManager.getReference().
This will return a placeholder that you can use to set as the dependencies in your entity. That way no SQL statement is executed for the dependencies.
From the API Doc:
<code><T> T getReference(Class<T> entityClass,
                   Object primaryKey)

Get an instance, whose state may be lazily fetched.
If the requested instance does not exist in the database, the EntityNotFoundException
is thrown when the instance state is first accessed.
(The persistence provider runtime is permitted to throw the EntityNotFoundException when getReference is called.)
The application should not expect that the instance state will be available upon detachment,
unless it was accessed by the application while the entity manager was open.

Parameters:
entityClass - entity class
primaryKey - primary key
Returns:
the found entity instance

Throws:
IllegalArgumentException - if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key or is null
EntityNotFoundException - if the entity state cannot be accessed
</code>
https://docs.oracle.com/javaee/7/api/javax/persistence/EntityManager.html#getReference-java.lang.Class-java.lang.Object-


Subgroups of the additive group of the remainders mod 8 $(\mathbb{Z}_8, \underline{+}$

Question:
Identify the subgroups of the additive group of the remainders mod 8 $(\mathbb{Z}_8, \underline{+})$ where $\mathbb{Z} = \{0,1,2,...,7\}$ and the operation $\underline{+}$ is defined as:
$$
a \underline{+} b = \begin{cases}a+b, &a+b < 8 \\
a+b-8,  &a+b \geq 8
\end{cases}
$$
What are the subgroups of $(\mathbb{Z}_8, \underline{+})$ and which of them are normal subgroups?

From definition, I know that since $(\mathbb{Z}_8, \underline{+})$ contains $8$ elements then the subgroups can contain either $1, 2, 4 \text{ or } 8$ elements. But I do determine the groups and it's elements?
Comment: all subgroups are normal because is abelian
Comment: @janmarqz But how can I identify which are the subgroups?
Comment: among all the $2^8$ subsets you need to decide which are subgroups
Comment: @janmarqz So the only way is the Brute Force approach?
Comment: at the stage you are it isn't a too cruel task
Answer: $\Bbb Z_8$ is a cyclic group. Subgroups of a cyclic group are cyclic and to each positive divisor of the order of the group (here, 8) there corresponds a unique subgroup of that order.
Look at the elements of $\Bbb Z_8$ and the cyclic subgroups generated by them. This will indeed give you all the subgroups, but some of them will be the same subgroup.
Two elements will generate the same subgroup iff their order is the same. This will help you recognize which of them are the same subgroups.
(As mentioned in the comments, all the subgroups will be normal because the group $\Bbb Z_8$ is Abelian)
Answer: So a group with $1$ element will be $\{0\}$.  That was, literally, trivial.
A group with $2$ elements will be $\{0,a\}$ so that $a + a = 0; a\ne 0$ so of all $2*a \equiv 0 \mod 8\implies 2a = 8k \implies a =4k \implies a\equiv 0 \mod 4$ so $a = 0, 4$ but $a\ne 0$ so the group with $2$ elements is $\{0,4\}$.
Now after doing the above it "should be obvious to even a dope" that $\{0,2,4,6\}$ is a group with four elements.  But perhaps less insultingly we know that up to homeomorphism $\mathbb Z_4$ and $\mathbb Z_2 + \mathbb Z_2 $ are the only groups with four elements.  So if we look at the individual elements...
$|0| = 0; |1| =8; |2| = 4; |3| = 8; |4| =2; |5| = 8; |6|= 4; |7| = 8$.
So  ... scratch everything and start again.
The only group with $1$ element is $<e> = \{e\} = \{0\}$.
The only group with $2$  elements is $<a>$~$\mathbb Z_2$ where $|a| = 2$.  The only $a; |a| =2$ is $a =4$. So the only subgroup with $2$ elements is $<4> = \{4\}$.
The only groups with $4$ elements are $<a>$~$\mathbb Z_4$ where $|a| = 4$ or $<a,b>$~$\mathbb Z_2 \times \mathbb Z_2$. where $|a|=2; |b|= 2; a\ne b$.
We have $|2|,|6| = 4$ and so $<2> = <6> = \{0,2,4,6\}$ is one subgroup.
We only have $|4| =2$ so we don't have any $|b| = 2; b\ne a$ so we have no other subgroups.
And the only subgroup with $8$ elements is the group itself.


Static no Django

Question: Galera,
Queria um conselho ou ajuda sobre os 'static' no 'Django', meus arquivos que estao na pasta 'Static" eles nao vem ser carregados apresentando os seguintes erros abaixo:
    System check identified no issues (0 silenced).
December 30, 2020 - 15:49:40
Django version 3.1.4, using settings 'core.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[30/Dec/2020 15:49:47] "GET / HTTP/1.1" 200 6889
[30/Dec/2020 15:49:47] "GET /static/js/plugins/plugins.js HTTP/1.1" 404 1689
[30/Dec/2020 15:49:47] "GET /static/js/bootstrap/popper.min.js HTTP/1.1" 404 1704
[30/Dec/2020 15:49:47] "GET /static/site.css HTTP/1.1" 404 1650
[30/Dec/2020 15:49:47] "GET /static/js/active.js HTTP/1.1" 404 1662
[30/Dec/2020 15:49:47] "GET /static/js/jquery/jquery-2.2.4.min.js HTTP/1.1" 404 1713
[30/Dec/2020 15:49:47] "GET /static/js/bootstrap/bootstrap.min.js HTTP/1.1" 404 1713
[30/Dec/2020 15:49:47] "GET /static/img/core-img/pizza.png HTTP/1.1" 404 1692
[30/Dec/2020 15:49:47] "GET /static/static/img/bg-img/foto_receita.png HTTP/1.1" 404 1728
[30/Dec/2020 15:49:47] "GET /static/img/core-img/logo.png HTTP/1.1" 404 1689
[30/Dec/2020 15:49:47] "GET /static/js/bootstrap/popper.min.js HTTP/1.1" 404 1704
[30/Dec/2020 15:49:47] "GET /static/js/bootstrap/bootstrap.min.js HTTP/1.1" 404 1713
[30/Dec/2020 15:49:47] "GET /static/js/plugins/plugins.js HTTP/1.1" 404 1689
[30/Dec/2020 15:49:47] "GET /static/js/active.js HTTP/1.1" 404 1662

Na minha pasta settings.py esta da seguinte maneira
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, '/static')
]

e minha urls.py esta assim:
urlpatterns = [
    path('',include('receitas.urls')),
    path('admin/', admin.site.urls),
] #+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Alguem que ja passou por isso que possa dar uma luz ?
Answer: Após fazer o deploy da aplicação, você precisa executar o comando:
python manage.py collectstatic

Assim os dados da pasta static serão copiados nos lugares devidos (configurados em seu settings.py) .
Segue a referência do collectstatic do django.
Comment: Obrigado, me ajudou muito

Static no Django


If $f$ an isometry on $M$ s.t. $f(p)=p$ and $(df)_p=\mathrm{id}_{T_p M}$, then $f=\mathrm{id}_M$

Question: A sketch of the proof of this is provided here, though many of the details are incomplete, and I'm having a certain amount of difficulty filling in the gaps. Note that we require $M$ to be connected (obviously). For clarity, I repeat the question in full below.
Proposition (which I wish to prove): Let $(M,g)$ be an $n$-dimensional topologically-connected Riemannian manifold, let $f:M\to M$ be an isometry (i.e. $f^*g = g$), and suppose there exists some point $p\in M$ such that $f(p) = p$, and $(\mathrm{d}f)_p = \mathrm{id}_{\mathrm{T}_p M}$. I claim that $f = \mathrm{id}_M$.
The proof goes as follows: we define $$X = \{ q\in M\ \vert\ f(q) = q,\ (\mathrm{d}f)_q = \mathrm{id}_{\mathrm{T}_q M}\}$$ so that $X$ is easily seen to be closed, and is nonempty by assumption, so that we must prove that it is open. To do so, let $q\in X$ be arbitrary, and let $$\mathrm{exp}_q:\mathrm{B}_{\mathrm{T}_q M}(0,\varepsilon)\to\mathrm{B}_M(q,\varepsilon)\subseteq M$$ be a diffeomorphism defining a normal neighborhood $\mathrm{B}_M(q,\varepsilon)$, then we will prove that $\mathrm{B}_M(q,\varepsilon)\subseteq X$ for $\varepsilon$ sufficiently small. Note that since isometries preserve geodesics, then $$f(\mathrm{exp}_q(tv)) = \mathrm{exp}_{f(q)}(t\,f_*v)$$ and therefore for any $r = \mathrm{exp}_q(v)\in\mathrm{B}_M(q,\varepsilon)$ we have that $$f(r) = f(\mathrm{exp}_q(v)) = \mathrm{exp}_{f(q)}(f_* v) = \mathrm{exp}_q v = r$$ so it suffices to prove now that there exists some $\varepsilon$ such that for all $r\in\mathrm{B}_M(q,\varepsilon)$, $(\mathrm{d}f)_r = \mathrm{id}_{\mathrm{T}_r M}$, however, I don't see how this is obvious, and Jason DeVito's explanation (drawing a triangle between $r$, $q$, and $\mathrm{exp}_q(v)$ for some $v$ such that $(\mathrm{d}f)_r v\ne v$) doesn't seem at all clear to me. So how is this last part proved?
Comment: Rephrasing: you're asking why the diffential of the identity map is the identity.
Comment: Please make the body of your question self-contained: it has to make sense and be complete without the title. On the other hand, you say that you are having problems filling in the gaps: which gaps? As it stands, it is not at all clear what exactly you want from answers!
Comment: I edited it for clarity.
Comment: If I delete the title, can I still understand what you are asking?
Comment: Yes, that is my question.
Answer: If $q\in M$, then there is a minimizing geodesic $c(t)= \exp_p\ tv$
between $p$ and $q$ s.t. $|v|=1$. Since $f$ is an isometry so
$(f\circ c)(t)$ is a minimizing geodesic between $p$ and $q$.
Here $\frac{d}{dt}\bigg|_{t=0}\ ( f\circ c)(t) =(df)_p\ v=v$ so that
$(f\circ c)(t)$ is a geodesic starting at $p$ and has a direction
$v$. Hence it coincides $c$. That is $(f\circ c)(t)=c(t)$ for all
$t\in [0,{\rm dist}\ (p,q)]$. That is $f(q)=q$.


What is the power of this test?

Question: A bag contains $N$ balls numbered $1,2,3,…,N$ to test the hypothesis $H_0 : N=10 $ vs $H_1:N=20.$ Draw $2$ balls from the bag without replacement, let $X$ denote the larger of the $2$ numbers in the drawn balls and reject $H_0$ if $X>9$. What is the power of this test?
My attempt.
When $H_1$ is true, $N=20$. And now we need to calculate the probability that $H_0$ is rejected which is $\frac{\binom{20}{2}-\binom{9}{2}}{\binom{20}{2}}$. Am I correct?
Answer: By definition, the power of a test for a particular alternative hypothesis $H_1$ is the chance of rejecting the null when $H_1$ governs the data: that is, when $N=20$.  Rejection occurs when the larger of the two balls drawn exceeds $9$.
The chance of rejection is most simply computed by finding the complementary chance that both balls have values of $9$ or less, and subtracting this chance from $1$.  That's because there are $\binom{9}{2}$ two-ball subsets of the numbers $\{1,2,\ldots, 9\}$ that are selected from the $\binom{N}{2}=\binom{20}{2}$ equiprobable two-ball subsets when $N=20$.  Consequently, the power is
$$1 - \binom{9}{2}/\binom{20}{2} = \frac{\binom{20}{2} - \binom{9}{2}}{\binom{20}{2}},$$
as stated in the question.
Answer: Let $A$ and $B$ be the numbers on the balls.
\begin{align*}
P(X > 9) &= 1-P(X \le 9) \\
&= 1-P(A \le 9 \text{ and } B \le 9)
\end{align*}
Can you take it from here?

What is the power of this test?


How do I rerun the editor after the git commit-msg hook?

Question: I have a git commit-msg hook that looks like this:
#!/bin/bash

COMMIT_MESSAGE_FILE="$1"
COMMIT_MESSAGE=$(cat "$COMMIT_MESSAGE_FILE")

if echo $COMMIT_MESSAGE | grep -q "PROJ-XXXX"
then
    echo "ERROR: Please either delete the PROJ-XXXX, or enter a proper JIRA ticket number"
    exit 1
fi

This works, but if I write a commit message during a commit, and forget to update the ticket number, it will close the editor, show the error, and discard my message completely.
Is there a way to have the hook either rerun the editor so I can edit my message, or at least remember what my commit message was next time I run git commit -v so I don't need to retype the commit message?
Comment: If nothing else better comes up, you can always do `echo $COMMIT_MESSAGE >some_file` in the `then` block.  Then `git commit -m "$(cat some_file)"`.
Comment: Why are you reading the entire file into memory instead of just using `grep -q "PROJ-XXX" "$1"`?
Comment: @chepner that works too. It would probably matter more if modern computers didn't have gigabytes of memory (my laptop has 32GB), and git commit messages weren't inherently tiny, but I know what you mean. It's mostly because `COMMIT_MESSAGE_FILE` and `COMMIT_MESSAGE` are more clear then `$1` . That and muscle memory. I'm used to piping things to grep instead of having grep read it, which is probably bad in some situations. Thanks for the suggestion
Answer: I thought there might be a simple, built-in way to do it, but I guess not.
I just wrote this - it seems to work pretty good:
#!/bin/bash

# JIRA tag format
JIRA_TAG="PROJ-XXXX"

# Allows us to read user input below, assigns stdin to keyboard
exec < /dev/tty

# Colors
SWITCH="\033["
NORMAL="${SWITCH}0m"
RED="${SWITCH}1;31m"
YELLOW="${SWITCH}1;33m"

# Commit file
COMMIT_MESSAGE_FILE="$1"

while true
do
    COMMIT_MESSAGE=$(cat "$COMMIT_MESSAGE_FILE")

    if echo $COMMIT_MESSAGE | grep -q "${JIRA_TAG}"
    then
        # Print the problem
        echo -e "${RED}ERROR${NORMAL}: Please either delete the ${YELLOW}${JIRA_TAG}${NORMAL}, or enter a proper JIRA ticket number"
        read -p "Press Enter to Try Again"

        # Rerun in editor
        # Exit if editor exits with an error
        # This lets someone break out of loop with :cq in vim
        # Nano doesn't appear to have a similar way to exit with an error
        # code
        $EDITOR "$COMMIT_MESSAGE_FILE" || exit 1
    else
        exit 0
    fi
done

This git hook, saved in .git/hooks/commit-msg, along with a ~/.gitmessage of something like this:

Jira Tickets: PROJ-XXXX

Ensures that you never forget to include a JIRA tag in your commit.
Note: ~/.gitmessage needs to be enabled with something like:
git config --global commit.template ~/.gitmessage
and the commit-msg hook needs to be executable (chmod +x .git/hooks/commit-msg)


Export objects from 3Ds max 2010 with V-Ray masked to Virtools

Question: I'm doing a project on virtual reality. I'm doing a virtual walk-through of an museum.
I have done the 3D from 3Ds Max 2010 and I have used V-Ray to map the background and stuff.
I'm using Virtools to do the walkthrough. I can export files from 3Ds Max 2010 to Virtools. But it doesn't export V-Ray maps to the object.
I want to know how to export V-Ray maped objects from 3Ds Max 2010 to Virtools?
Answer: You have to bake the textures to the objects if you want to use unsupported textures \ shaders.
Use the texture baking tools found by pressing '0'.


Por que é possível acessar índices de arrays com "{}" chaves?

Question: Em alguns testes que fiz com PHP, vi que é possível utilizar chaves ({}) para acessar índices de arrays.
Exemplo:
$array = ['a' => 1, 'b' => 2, 'c' => ['d' => 4]]

echo $array{'c'}{'d'}; // 4
echo $array{'c'}['d']; // 4

Até então, pensava que apenas os colchetes ([]) faziam isso.
Sendo assim, quero perguntar:

Acessar um índice de um array com chaves ao invés de colchetes tem algum significado especial?
Por que é possível usar as duas formas?
Usar chaves seria considerado fora do padrão? Pergunto isso porque, apesar de funcionar, nunca vi ninguém usando.
Comment: http://php.net/manual/en/language.types.array.php#example-61 Veja a nota um pouco abaixo do exemplo.
Comment: http://pt.stackoverflow.com/questions/77693/qual-%C3%A9-a-utilidade-de-declarar-vari%C3%A1veis-atrav%C3%A9s-de-chavetas (não estou dizendo que é duplicada)
Comment: @DanielOmine pode não ser duplicada, mas é bem parecida mesmo.
Answer:
Acessar um índice de um array com chaves ao invés de colchetes tem algum significado especial?

Não.

Por que é possível usar as duas formas?

O manual diz que pode, sem explicações porque ter essa alternativa. Não consigo imaginar uma plausível a não ser gosto. O bfavaretto falou de um teoria sobre ajudar a transição de quem vinha do Perl, um concorrente direto na época. É uma boa teoria, ainda que eu acho um erro fazer esta opção. Não há ganho ter essa alternativa. Tem tanta coisa muito mais radical nas diferenças entre essas linguagens. Mas de fato muita coisa em PHP foi realizado sem muita lógica.

Usar chaves seria considerado fora do padrão?

Estritamente não.
Já que nunca viu alguém usar, não seja quem vai começar :) gera confusão, já que as chaves costumam ser usadas para outra coisa, o que alias já tem mais de uma finalidade, não adicione mais uma. Deixe as chaves para usar com o que todo mundo está acostumado. A não ser que encontre um motivo bom, o que eu duvido.
Comment: Isso, seria só inventar moda.
Comment: @bfavaretto é possível, o que vai atrair gente errada :) Quem gosta de Perl não vai trocar de linguagem, quem acha PHP mais interessante para alguma coisa vai se adaptar.
Comment: Eu li em algum lugar que aceitar `{}` seria uma maneira de atrair gente que mexe com perl.
Comment: Eu pensei em usar as chaves quando  eu fosse acessar os índices de uma `string`, já que em PHP, ao usar os colchetes, também é possível acessar o índice da string (seria pra diferenciar, mas também acho que seria inventar moda demais).


Is FarmWarDeployer compatible with Tomcat 7?

Question: Can I use FarmWarDeployer with TomCat 7? Or will I have to use Tomcat 5.5? Are there any other alternatives?
Answer: The TomCat 7.0 documentation exposes the FarmWarDeployer classes:
http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/ha/deploy/FarmWarDeployer.html
So it would be safe to assume that yes, it should work.
Comment: Thanks. I know that what the farmwardeployer but dont know how to use the functionality provided by that. Means I know the configuration within  element but How to test by deploying application in one place(which place).


Diagonalising a $2 \times 2$ and $3 \times 3$ matrix

Question:
For each of the following matrices $A$, find an invertible matrix $P$ over $C$ such that
  $P^{-1}AP$ is upper triangular:
$$A = \begin{bmatrix}4 & 1\\-1 & 2\end{bmatrix} \quad \text{ and } \quad A = \begin{bmatrix}1 & 1 & 1\\1 & 1 & 1\\0 & 0 & 0\end{bmatrix}.$$

For the first matrix, I calculate the eigenvalue to be $3$, with algebraic multiplicity $2$.
However, I can only find one eigenvector for it, namely $\begin{bmatrix}1\\-1\end{bmatrix}$.
The second has two eigenvalues, $0$ (multiplicity $2$) and $2$ (multiplicity $1$)
But again, for the eigenvalue $0$, I can't find two linearly independent eigenvectors.
So, how do I proceed to find $P$ in these cases?
Comment: relevant: [Jordan canonical form](https://en.wikipedia.org/wiki/Jordan_normal_form), which for the first matrix is $\left(\begin{smallmatrix}3&1\\0&3\end{smallmatrix}\right)$.
Comment: @GitGud I'm new to Latex, so don't know how to write it. But I calculated the char poly to ge the eigenvalue. I then did:A-(eigenvalue*I)*v = 0, where v= eigenvector
Comment: @vadim123 Thanks, I didn't know about the JCF. From what I see, it can't be applied to the second matrix as the (1,3)th entry of A isn't 0. Am I correct?
Comment: every matrix has a JCF, there will just be multiple blocks.  Wolframalpha can calculate this for you like [this](http://www.wolframalpha.com/input/?i=jordan+canonical+form+for+%5B%5B1%2C1%2C1%5D%2C%5B1%2C1%2C1%5D%2C%5B0%2C0%2C0%5D%5D).
Answer: For the first matrix, your work is all correct.
We need to find a generalized eigenvector.
One approach to this (did you learn why in class), is to setup:
$$[A - \lambda I]v_2 = v_1$$
I am going to write the eigenvector with the signs swapped for the first one.
We have $v_1 = (-1, 1)$, so we would get:
$$[A -\lambda I]v_2 = v_1 \rightarrow \begin{bmatrix}1 & 1\\-1 & -1\end{bmatrix}v_2 = \begin{bmatrix}-1\\1\end{bmatrix}$$
Solving this (use RREF), we get a second linearly independent eigenvector of:
$$v_2 = (-1, 0)$$
The matrix $P$ is formed as linear combination of the eigenvectors as $[v_1 | v_2]$, so we get:
$$P = [v_1 | v_2] = \begin{bmatrix}-1 & -1\\1 & 0\end{bmatrix}$$
This will lead to the Jordan Normal Form for the upper triangular matrix as:
$$J = P^{-1}AP = \begin{bmatrix}3& 1\\0 & 3\end{bmatrix}$$
Also note, there are other methods available and sometimes required over the method outlined above.
Can you use the method above for your second problem and see if it bears fruit?
For example, we find two eigenvalues of $\lambda_1 = 2 and \lambda_{2,3} = 0$. For the $\lambda_{2,3} eigenvalue, we will have a row-reduced-echelon-form of:
$$a+b+c = 0$$
We need two linearly independent choices and have a lot of free variables to choose from. For example, we can choose:
$$v_2 = (-1, 0, 1), v_3 = (-1, 1, 0)$$
For the $\lambda_1=2$ eigenvalue, we form:
$$[A-\lambda_1 I]v1 = 0$$.
After RREF that matrix, we arrive at: $v_1 = (1,1,0)$
Recall, you have to do this process over for EACH eigenvalue!
So, to summarize, we should arrive at (no generalized eigenvectors needed because of geometric and algebraic multiplicity):
$$\lambda_1 = 2, v_1 = (1, 1, 0)$$
$$\lambda_2 = 0, v_2 = (-1, 0, 1)$$
$$\lambda_3 = 0, v_3 = (-1, 1, 0)$$
Comment: Did you mean eigenvectors?
Comment: $$\begin{bmatrix}1 & 1 & 1\\1 & 1 & 1\\0 & 0 & 0\end{bmatrix} \begin{bmatrix}a\\b\\c\end{bmatrix} $$ gives us eigenvector $$\begin{bmatrix}1\\1\\1\end{bmatrix}$$
Comment: And so I solve $$\begin{bmatrix}1 & 1 & 1\\1 & 1 & 1\\0 & 0 & 0\end{bmatrix} \begin{bmatrix}a\\b\\c\end{bmatrix} = \begin{bmatrix}1\\1\\1\end{bmatrix} $$

Which gives a = 1-b-c , thus we get eigenvalues:

$$\begin{bmatrix}1\\0\\0\end{bmatrix} , \begin{bmatrix}-1\\1\\0\end{bmatrix} ,
\begin{bmatrix}-1\\0\\1\end{bmatrix}$$

Is that correct?
Comment: Sorry, This is my attempt at the 3x3!
Comment: See my update for the eigenvalues, eigenvectors. They need not be unique.
Comment: @Sapph: Did it all make sense? Regards
Comment: Great work!! and super effort to follow up +1
Comment: Sometimes they forget to return...and sometimes an OP doesn't realize when/how to see they've been pinged, or a comment/reply exists!!
Comment: @Amzoti Sorry! I understand the eigenvector for eigenvalue 2, but I don't understand how you calculated v2 and v3, without finding a generalised eigenvector. Was my method in the comments above incorrect?
Comment: @Sapph: unless you put my name with an $\@$ symbol, I don't get the comment. Recall that you have to do this process foe EACH eigenvalue, so your comment was only valid for the eigenvalue $0$, you have to repeat it for the other eigenvalue - see my updates. Regards
Answer: Here is an alternative approach. Note that you are not required to find the Jordan form of $A$. So, when $A$ is $n\times n$, you only need to find one eigenvector of length $n$.
More specifically, suppose $(\lambda_1,v_1)$ is an eigenpair for $A$. Extend $v_1$ to a basis $\{v_1,\ldots,v_n\}$ of $\mathbb{C}^n$ and put the basis vectors together to form an invertible matrix $P_n$. Then
$$
AP_n=(\lambda_1v_1,\,Av_2,\,\ldots,\,Av_n)
=P_n(\lambda_1e_1,\,P^{-1}Av_2,\,\ldots,\,P^{-1}Av_n)
$$
where $e_1=(1,0,\ldots,0)^T$. In other words,
$$
P_n^{-1}AP_n=\pmatrix{
\lambda_1&\ast&\ast&\cdots&\ast\\
0&\ast&\ast&\cdots&\ast\\
0&\ast&\ast&\cdots&\ast\\
\vdots&\vdots&\vdots&&\vdots\\
0&\ast&\ast&\cdots&\ast\\
}
=\pmatrix{\lambda_1&u^T\\ 0&B}
$$
for some $(n-1)$-vector $u$ and some matrix $B$ of order $n-1$. So, if $(\lambda_2,w)$ is an eigenpair of $B$ and $P_{n-1}$ is an invertible matrix whose first column is $w$, then
$$
\pmatrix{1\\ &P_{n-1}^{-1}}(P_n^{-1}AP_n)\pmatrix{1\\ &P_{n-1}}
=\pmatrix{
\lambda_1&\ast&\ast&\cdots&\ast\\
0&\lambda_2&\ast&\cdots&\ast\\
0&0&\ast&\cdots&\ast\\
\vdots&\vdots&\vdots&&\vdots\\
0&0&\ast&\cdots&\ast\\
}.
$$
Proceed recursively, you get an upper triangular matrix.
For your two $A$s, it happens (for different reasons) that you only need one shot each to get a triangular matrix. Take your second $A$ (which is $3\times3$) as an example. $(1,1,0)^T$ is an eigenvector of $A$ corresponding to the eigenvalue $2$. So, if we put
$$
P_3=\pmatrix{1&\ast&\ast\\ 1&\ast&\ast\\ 0&\ast&\ast}
$$
where the second and third columns are arbitrary (as long as $P_3$ is invertible), we have
$$
P_3^{-1}AP_3 = \pmatrix{2&\ast&\ast\\ 0&0&0\\ 0&0&0}.
$$
(Exercise: For each of the two $A$s in question, why only one shot is enough?)


ProFTPd and SELinux: mkdir Permission denied

Question: I have a ProFTPd server on Centos 6.3 with SELinux Enforcing.  My users are virtual users in a flat file.  The users are chrooted to directories mounted via NFS.  I've already set the following policy:
/usr/sbin/semanage boolean -m --on allow_ftpd_use_nfs
/usr/sbin/semanage boolean -m --on allow_ftpd_anon_write

The users can read and write files without problem.  However, they cannot create directories.  I get this in audit.log:
type=AVC msg=audit(1364763704.972:25268): avc:  denied  { create } for  pid=2971 comm="proftpd" name="test4" scontext=system_u:system_r:ftpd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:nfs_t:s0 tclass=dir

Is there away to keep SELinux on but allow directory creation?
Answer: That looks like a policy error. Try adding this policy by doing the following..

Create a new directory called "localftpd"
Place the content below into a file called "localftpd.te" inside of this new directory.
Run make -f /usr/share/selinux/devel/Makefile load

This is the policy amendment you need.
policy_module(localftpd, 1.0.0)

require {
    type ftpd_t;
    type nfs_t;
}

tunable_policy(`allow_ftpd_use_nfs && allow_ftpd_anon_write', `
    create_dirs_pattern(ftpd_t, nfs_t, nfs_t)
    delete_dirs_pattern(ftpd_t, nfs_t, nfs_t)
    rename_dirs_pattern(ftpd_t, nfs_t, nfs_t)
');

Comment: awesome, that totally worked.  Thanks!  It also got me to start learning this custom module business.
Comment: In case anyone else runs into this, I needed to make some changes to make this work, but the above answer led me on the right path:
tunable_policy(`allow_ftpd_use_nfs && allow_ftpd_anon_write', `
    fs_manage_nfs_files(ftpd_t)
    fs_manage_nfs_dirs(ftpd_t)
');


Storing temporary data in a form AJAX callback

Question: I have a form submit button that when clicked fires an AJAX callback.
$form['actions']['submit'] = [
  '#type' => 'submit',
  '#value' => $this->t('Title...'),
  '#ajax' => [
    'callback' => '::getResponse',
    'wrapper' => 'wrapper',
  ],
];

In the AJAX callback, I would like to save what the user entered, plus what the API responded with. I have tried using form state storage and $form_state->set, but in both cases the values are lost.
Form AJAX callback:
  public function getResponse(array &$form, FormStateInterface $form_state) {
    // API call here...

    $form['response']['#value'] = trim($result["answer"]) ?? $this->t('No answer was provided.');
    return $form['response'];
  }

Is there a way to update the UI and the form state?
Comment: How/where do you want to use this data? Do you want to pass it back to the front end to use in the ajax response or by some other JS? Or do you want to store some data to use when processing the form submission or whatever?
Comment: Don't want to save it to the database, just use it in the next form submission. So the next time the form submits, I have the previous user input and API response.
Answer: Data can be stored in the form submission using $form_state->set('[ARBITRARY KEY]', $value), then retrieved when the form is rebuilt with $value = $form_state->get('[ARBITRARY KEY]'). On the first form build, $value will be null, as the form has not gone through the ajax yet. On further #ajax rebuilds, $value will contain the value you set in the submit handler. Note that you will have to store the value on the form state in the submit handler, NOT the #ajax callback.
Comment: How can you have an ajax callback on a submit handler, then?
Comment: Submit handlers are called before the ajax handler(s).
Comment: Ah, gotcha. That works now.


Passar objeto por parâmetro causa erro - Android Studio

Question: Estou tentando passar um objeto por parâmetro, mas ocorre um erro na linha "it.putExtra("tag", obj);":

Cannot resolve method (java.lang.String, meu pacote.minhaClasse)

Segue o codigo
Obj obj = new Obj();
Intent it;
it = new Intent(this, MinhaClasse.class);
it.putExtra("tag", obj);
startActivity(it);

Outra pergunta, como recuperar esse objeto na outra Activity?
Comment: Essa pergunta pode ser bem útil para você, Vitor: http://pt.stackoverflow.com/questions/38492
Comment: Olá, essa resposta poderá te ajudar http://pt.stackoverflow.com/questions/70421/como-passar-informacoes-da-listview-para-uma-nova-activity/70456#70456
Answer: Para que você passe um objeto como parametro é necessário que o mesmo seja Serializado, ou seja, implemente Serializable.
Segue um simples exemplo:
Classe:
public class Params implements Serializable{
    public String param1="";
    public String param2="";
    public String param3="";
}

Setando o parametro:
 Params obj = new Params();
        obj.param1 = "Parametro UM ";
        obj.param2 = "Parametro DOIS ";
        obj.param3 = "Parametro TRES ";
        Intent it;
        it = new Intent(context, MainActivity.class);
        it.putExtra("Param", obj);

Saudações
Comment: Uma outra maneira seria utilizando `Parcelable`


Mogodb split values into 5 minute intervals and return most recent within interval group

Question: My Mongo database has documents as so:
{
   "timestamp": ISODate("2015-09-27T15:28:06.0Z"),
    "value": '123'
},
{
   "timestamp": ISODate("2015-09-27T15:31:06.0Z"),
    "value": '737'
},
{
   "timestamp": ISODate("2015-09-27T15:35:00.0Z"),
    "value": '456'
},
{
   "timestamp": ISODate("2015-09-27T15:40:20.0Z"),
    "value": '789'
}

...etc...
What I want to do is aggregate these in 5 minute intervals and than get the most recent (with the latest timestamp) value per 'group of 5 minutes'.
So basically the steps are:
1) split into groups of 5 minutes
2) return the 5-minute timestamp and the value of the document that has the newest timestamp within this 5 minute group
Based on that and my documents above the documents returned should be:
{
    "timestamp": ISODate("2015-09-27T15:25:00.0Z"),
    "value": '123'
},
{
    "timestamp": ISODate("2015-09-27T15:35:00.0Z"),
    "value": '456' // 456 has a newer timestamp than 737, which are in the same 5 minute range
},
{
    "timestamp": ISODate("2015-09-27T15:40:00.0Z"),
    "value": '789'
}

I have tried grouping into 5 minute intervals as described here: https://stackoverflow.com/a/26814496/1007236
Starting from there I can't find out how to return the value of the most recent within each 5 minute group.
How can I do that?
Answer:
You solve this by a very simple application of Date math:
db.collection.aggregate([
    { "$sort": { "timestamp": 1 } },
    { "$group": {
        "_id": {
            "$add": [
                { "$subtract": [
                    { "$subtract": [ "$timestamp", new Date(0) ] },
                    { "$mod": [
                        { "$subtract": [ "$timestamp", new Date(0) ] },
                        1000 * 60 * 5
                    ]}
                ]},
                new Date(0)
            ]
        },
        "value": { "$first": "$value" }
    }}
])

Where the basic principle is finding the modulo ( $mod ) or "remainder" from the time by a five minute interval and subtracting that from the base time. This rounds to "five minutes".
Of course the other part is you $sort in order to make sure the smallest original "timestamp" sorted "value" is on "top".
The other parts are when you $subtract "epoch" date as a BSON Date from another date then you receive an "integer" in result. The similar part is adding ( $add ) an "integer" to a BSON Date type to receive another BSON Date.
The result is BSON Date objects rounded out to the interval you use with the math.

1000 millisecons X 60 seconds X 5 minutes.
Comment: @JelmerKeij If you have more questions them please [ask them](http://stackoverflow.com/questions/ask) as it is the clearest way to express a new question anyway.
Comment: Excellent. Thanks again. Is it also possible to return some extra columns in these type of aggregations? For example, say you'd want to return a column 'myColumn' for every document with some custom value?


Tags: How to get the list of my created tags till now

Question: I just wanted to know that is there any way to get and view the list of my created tags during asking and editing questions.
There is tag option in site which list all the tags but I am looking for some thing like "My created tags".
Any help, experience and knowledge sharing would be highly appreciated
Comment: Did you find solution on this?
Comment: Sadly no, I am still looking for proper and complete solution
Answer: Please check SE Data Explorer ... maybe this one: https://data.stackexchange.com/magento/query/205459/all-tag-creators
Comment: I am little confused about is it showed my created tags during asking and editing question count or tags in which I created the usage guidance for that particular tag? if it shows the tags in which I created the usage guidance then I want to specifically view the tags in isolation which I created during asking and editing question I hope you got my point. Still `+1` for your effort


How to convert "top 10" list from SQL to NoSQL

Question: I have an online game currently using MySQL. I have a Player table looking like this:
create table player (
    id integer primary key,
    name varchar(50),
    score integer
);

I have an index on "score" column and display the rankings like this:
select id, name, score from player order by score desc limit 100

I'd like to migrate my system to Redis (or, if some other NoSQL is more applicable to this kind of problem, please tell). So I wonder what is the way to display this kind of rankings table efficiently?
AFAICT, this could be a Map/Reduce job? I know next to nothing about Map/Reduce although I read some docs I still don't quite understand as I haven't been able to find any real-life examples.
Can someone please give me a rought example how to do the above query in Redis?
Comment: you could consider orientDB (a noSQL derivat, quite nicely designed) http://code.google.com/p/orient/wiki/SQLQuery . They offer a LIMIT command
Answer: In redis you can use Sorted sets ( http://redis.io/commands#sorted_set )
When you have scored items in sorted set you can get top N by invoke ZRANGE players 0 N
Comment: Looks good. One question: If I need to have multiple rankings (say: score and monthly_score), would I need to create two sets?
Comment: yes, for each score. Or if monthly_score depends from score, I think you can use *list* for each player to star his score history
Answer: Good question - In MongoDB you would have to use the group() function to return this type of query:
select id, name, score from player order by score desc limit 100

Might look something like this:
db.player.group(
           {key: { id:true, name:true },
            reduce: function(obj,prev) { if(prev.cmax<obj.score) prev.cmax = obj.score; },
            initial: { cmax: 0 } // some initial value
            });

Using a MapReduce based approach is probably best, see:

http://www.mongodb.org/display/DOCS/Aggregation#Aggregation-Group
http://cookbook.mongodb.org/patterns/finding_max_and_min_values_for_a_key/
Comment: Thanks. How efficient would such function be? I have about 10 million records in that Player table. Will it have to traverse all records in Map process?
Comment: Well, yes in this case it does have to traverse the entire dataset. I think that the best solution might be to filter your dataset first before MapReduce  - for example, start with all players with a score over "50" or something. Otherwise, the 'efficiency' will always be the same, but the speed depends on the system you are using - if you have your NoSQL distributed across multiple machines, the Map and Reduce can take place across the various servers on the network.


Distributing executable terminal commands on macOS

Question: I make bash/ruby commands for basically everything in my development workflow (todo, pullrequest, asciiart, remind and so on). People I work with always ask me to share my commands with them, but to do this, I transfer the files to their computer, then xargs through each file with chmod +x and mv /usr/local/bin.
Wondering what work I can do upfront to make the import process easier. Fine with some Mac installer tool, or a git & makefile solution, but I'd really like to get the process down to a single click or command if possible.
Answer: Use Nix expressions with Nix package manager: https://en.m.wikipedia.org/wiki/Nix_package_manager ! It is supported on Macs.
Answer: It is possible to make a Terminal command executable by just selecting it in Finder and pressing the keyboard shortcut.
Below is the method for solving your problem.
1. Create a macOS service using Automator
1.1 Open Automator and create a new service
1.2 At the top, choose Service receives selected no input in Finder
1.3 Drag Get Selected Finder Items action to the workflow
1.4 Drag Run Shell Script action to the workflow
1.5 In Run Shell Script action, select Pass input: as arguments and in the text field, type:
chmod u+x "$@" && mv "$@" /usr/local/bin
1.6 Save service

2. Distribute service to colleagues' computers
2.1 The created service is located in ~/Library/Services
2.2 Move it to other computers and install it by opening the file, or manually copying the service to ~/Library/Services

3. Bind service to a keyboard shortcut
3.1 Open System Preferences → Keyboard → Shortcuts → Services → General
3.2 Choose an appropriate keyboard shortcut for your service
You can also run the service by right-clicking on file and selecting the action in Services submenu at the bottom of contextual menu.
Comment: Screenshots and effort appreciated
Answer: Share a Dropbox directory with them that contains your scripts, and ensure that it is in their PATH.
No updates are necessary when you improve your scripts as they will automatically see the latest version.
Manage the directory with git for version control.
Answer: Thought I'd post the standard makefile solution for completion sake. Works for macOS/ and GNU(Linux)
Put a makefile in the project directory.
So the directory looks like [ my-executable makefile readme.md ] or whatever
# makefile

install:

    # side note: `@` prevents make from printing the command itself

    @echo "installing..."
    @chmod +x my-executable
    @cp my-executable /usr/local/bin
    @echo "done!"

then inform recipients to download/clone and run sudo make install from the project directory
Or for a one-line solution (presuming the recipients trust you a little too much)
git clone https://githost.com/myaccount/myrepo.git &&
sudo make install -C myrepo &&
rm -rf myrepo

(download, install, remove cloned directory) – user 16 mins ago
Comment: One line `git clone https://githost.com/myaccount/myrepo.git && sudo make install -C myrepo && rm -rf myrepo`" (download, install, remove cloned directory)


Maximal compact subgroup of $GL_n(\mathbb C_p)$

Question: It is known that the general linear group $GL_n(\mathbb Q_p)$ over the $p$-adic numbers has $GL_n(\mathbb Z_p)$ as a maximal compact subgroup and every other maximal compact subgroup of $GL_n(\mathbb Q_p)$ is conjugated to this one. (Unfortunately, I don't have any reference for this fact and so I don't know any proof.)
Q: Is this also true for $GL_n(\mathbb C_p)$ and $GL_n(\mathcal O)$, where $\mathcal O \subset \mathbb C_p$ is the integer ring?
Comment: A reference to the statement for $GL_n(\mathbb{Q}_p)$ is Appendix 1 of Chap IV, Lie Algebras and Lie groups by J-P. Serre.
Comment: The unit group $\mathcal O^{\times}$ is not compact, so the group $\text{GL}_n(\mathcal O)$ can't be compact, as the determinant is a continuous surjective map from that matrix group onto the unit group.
Comment: Thank You. It could be that my question is really stupid, since I don't even know that $GL_n(\mathcal O)$ is compact. But, if this is true, I can modify Serre's proof to generalize the statement to my situation.
Answer: As noted in a comment, $GL_n(\mathcal O)$ is not compact in this situation. Further:
There are no maximal compact subgroups in $GL_n(\mathbb C_p)$.
Proposition: Let $F$ be any field which is complete with respect to a nonarchimedean value $\lvert \cdot \rvert$  but not locally compact, and let $K$ be a compact subgroup of $GL_n(F)$. Then there is a larger compact subgroup $\tilde K \supset K$.
Proof: $F$ being not locally compact means that either its residue field $\mathcal{O}/m_{\mathcal O}$ is infinite, or its value group $\lvert F \rvert$ is dense in $[0, \infty)$ (or both). In either case one can see (compare constructions here) that the closed set $$ U:= \{x \in F: \lvert x-1 \rvert < 1\}$$ (the "principal units") contains sequences without convergent subsequences; hence, so does the closed set of scalar matrices $U_n := U \cdot Id_n \subset GL_n(F)$; meaning that there must be $x \in U_n \setminus K$. The closure of the subgroup generated by such $x$ is the subgroup $ X:= x^{\mathbb Z_p} \subset GL_n(F)$, which is compact and in the centre of $GL_n(F)$. In particular, $\tilde K := KX =$ the subgroup generated by $K$ and $X$ is compact.

Note: We used completeness of $F$ for the description and compactness of $X$ in the above proof. K. Conrad's Compact Subgroups of $GL_n(\overline{\mathbb Q_p})$, which gave me the idea for that step, implies that the result is also true for $F=$ the (non-complete!) algebraic closure of $\mathbb Q_p$, albeit for a different reason: Each compact subgroup of that is contained in $GL_n(E)$ for some finite extension $E \vert \mathbb Q_p$.
Comment: How would you describe $GL_n(O_{\Bbb{C}_p})$ as being special then? As the subgroup of isometries of $\Bbb{C}_p^n,\|.\|_\infty$?
Comment: @reuns: I guess so.


Assessing which player "wins" a series of predictions

Question: A group of friends makes predictions about the outcome of the elections and we would like to assess who's predictions are closer to the final "outcome". For example, Here is a table of predictions for 4 parties (A, B, C, D) and the final "outcome" of the elections:
<code>| Party  | Andrew | Bob  | Claire | Dominic | Eva  | Outcome |
|--------|--------|------|--------|---------|------|---------|
| A      | 44     | 41   | 44     | 45      | 43   | 44      |
| B      | 36     | 41   | 43     | 40      | 42   | 41      |
| C      | 7      | 8.5  | 5      | 7       | 8    | 7       |
| D      | 8      | 3    | 5      | 5       | 4    | 3       |
| Others | 5      | 6.5  | 3      | 3       | 3    | 5       |
| Sum    | 100%   | 100% | 100%   | 100%    | 100% | 100%    |
</code>
It is tempting to use the formula for standard deviation:
$$
\sigma = \sqrt{\frac{\sum_{i=1}^{n}(x_i - \mu)^2} {n}}
$$
to calculate each player's deviation from the final "outcome". For example, Eva's standard deviation is:
$$
\sigma_E = \sqrt{\frac{(43-44)^2+(42-41)^2+(7-7)^2+(4-3)^2+(3-5)^2} {5}} = 1.26
$$
which is the lowest of the lot. However, this is not a correct use of the standard deviation formula since we are not measuring the st. dev. of a sample with a given mean. Furthermore, the sum of predictions for the 4 parties + Other always sums up to 100 so the "free" predictions are really 4, not 5. My questions are:

Is this calculation valid?
Is there a better way to formulate the problem, without getting into parametric tests?
Comment: What do the numbers mean? How does one assess whether a prediction is "good" or "bad"? How should one quantify *how* good it is?  For instance, if each election has a single winner determined by the plurality vote, then the standard deviation will have little or nothing to do with how accurately an individual predicts the outcome, because it primarily measures how accurately they predicted the portion of the popular vote given to the minority parties, which is nearly irrelevant.
Comment: Thanks for the comment. I clarified the objective of the game, which is to get as close to the final outcome of the election as possible.
Comment: Thank you for making that more specific. However, "close" can be measured in many different ways. Several might be germane to your problem, depending on how you quantify the discrepancy between a prediction and an outcome. You could use the difference, the relative difference, the log ratio, or the difference of logits, for instance.
Comment: How would you interpret and formulate the problem? Please post a response below.
Comment: As @Glen_b points out in his answer, this is something you will have to tell us: we cannot tell you why you are doing this or how you should go about measuring the accuracy of a prediction.
Answer: The quantity you have specified is not a standard deviation, because $\mu$ is not the mean prediction.
It's called a root-mean-square deviation, and it's a common measure of accuracy.
However, it's not necessarily a suitable measure of accuracy in this case.
1) the variance of sample proportions is larger near $\frac{1}{2}$ than near the ends -- in some sense it's "easier" to get within a few percent of a very small proportion than one near $\frac{1}{2}$, so you might want to weight accuracy in different regions according to how hard it would be to predict proportions in that region.
2) in terms of predicting outcomes of elections, the relationship between the proportions and the outcomes may be relatively complex -- and depend on the particular kind of election -- a vote is handled very differently when voting for an American president (where accuracy on anything but the top two matter not at all) compared to voting for a StackExchange moderator election, the Irish house of representatives or the Australian Senate (where accuracy in the "small party" votes may be much more important).
Comment: If your only task is to approximate those proportions, then yes, you could use that RMSD measure you suggest, as long as that represents your loss function/what represents 'close' for your purposes when it's small.
Comment: Thanks for the pointer to the RMSD. Point 1) is correct but let's assume the variance is the same for all parties (i.e. we have no prior knowledge of scores of other years). Point 2) is not of interest. I'm only interested in the given (fictional) example.
Answer: You could use a "proper score function", which was intended just for your purpose!  You can read about proper score functions here: Metrics to asses the ability of a model to predict a probability  or at  https://en.wikipedia.org/wiki/Scoring_rule


Why does this HTTP header configuration cause browsers to always perform If-Modified-Since requests?

Question: On our server, we have configured http response headers as follows:
Cache-Control:max-age=28800, must-revalidate   # (8 hours)
Connection:Keep-Alive
Date:Wed, 24 Apr 2013 21:36:19 GMT
ETag:W/"173520-1366833451000"
Expires:Thu, 25 Apr 2013 05:36:19 GMT          # (8 hours from access)
Keep-Alive:timeout=15, max=484
Server:Apache-Coyote/1.1
Vary:Accept-Encoding,User-Agent

Our intent was for the resource to be cached by the browser for 8 hours, after which the browser should check if it has been modified (with a 304 request) before using the cached copy.
However, I have found that the browser always makes a 304.  (It continues to used it's cached copy, but checks the server for modifications before doing so - which I want to occur after 8 hours, not all the time.)
As I thought it should work, Cache-Control:max-age=28800, must-revalidate should instruct the client to use the cached resource until it reaches max-age in the cache, after which it must-revalidate with the origin server.  I believe that the Expires directive is more of a fallback and that Cache-Control supersedes is - but if it were at play, I would expect the browser to use the cached copy until the expiration date, then fetch a new copy.  Most of that is gleaned from this writeup, and perusing the spec a little.
Obviously, my understanding is incomplete - what am I missing?
EDIT: I mistakenly assumed that by refreshing the current page I would be testing what happens when the browser goes to subsequent pages that have the same resources linked.  I was wrong - hitting the "refresh" button generally seems to force the browser to check if any of the resources have been modified before using the cached copies, which makes insanely obvious sense.   When I click through to other pages, the resources are pulled directly from cache as expected.
Comment: Did you hit the browser's reload button?
Comment: Yes.  I clear the cache and load the page.  On the first load the resource is fetched as you'd expect. Reloading the page causes the browser to make the 304's.
Comment: That's what it's supposed to do! Try browsing around the site instead.
Comment: I am not sure I follow.  Perhaps a concrete example would help.  Every page in the site references main.css. Regardless of which page I load, the browser makes a conditional GET for main.css when it already has a cached copy, the max-age (cache-control directive) has not been reached, and the expiration date is still eight hours away. Shouldn't the browser use the cached local copy instead of making conditional GETs?  Why is it checking to see if the resource has been modified?  (How can I instruct it not to?)
Comment: Realizing my first comment may have thrown you off. To be clear, I emptied the cache at the outset to start with a clean slate, but all subsequent reloads were with a full cache.
Comment: What do you mean by "reload"? Do you mean you navigated back to a page you had previously visited? Or do you mean you hit the reload button? Because your question sounds an awful lot like "I asked my browser to reload something, why did it reload it?"
Comment: Wow, I can't believe it's this simple.  I was under the impression that reloading (IE, hitting the refresh button) the current page was equivalent to navigating to it (or another similar page that has the same static resources) for the purposes of testing how the caching was working. As you both pointed out _very_ clearly, that's not the case.  When I click through to other pages the browser hits the cache rather than issuing 304's.   I'll edit the question to clarify my mistake - anyone care to write a "you are dumb, reloading is different" answer?
Answer: This is desired behavior specifically for the browser reload button.  The reload button will attempt to validate the page, and some content like CSS.
There's other ways to load your page, like navigating away and back.  Or click on the URL bar and click "enter" in those cases, the browser will go with the cached data without revalidating.


Closing questions

Question: I've been working lately on cleaning up the old and unanswered questions.
(My hidden agenda is to get the answered percentage as high as possible but this is not why I ask this).
So I've been browsing this section and tried to answer some of the questions and close others.
I admit that maybe I was overdoing it and voted to close some of the questions that shouldn't be closed. But I guess that's why you need more than one vote to close a question.
But I'm almost sure that most of the questions should be closed.
I've read this to get an idea of what should be closed and what shouldn't, but this is kind of vague and it depends on each SO website in particular. So I went on and took a look here.
My conclusion... we should define a better scope of this website.
There are a lot of questions still open that are not going to help future readers or questions requesting for very custom code that apply to one case only.
Here are some of them:

Saving a review requires a website ID?
Page content in CMS doesn't reflect live page
Which Magento modules allow to set tiered pricing depending on category?
https://magento.stackexchange.com/q/13195/146

And I can go on if needed.
To sum this up...I have 2 questions:

How can we define a little clearer the questions that can be asked here?
How can we make the voters more responsible for their actions? I know that clicking "Leave open" is easier than to read the question and maybe provide a reason for closing but let's try to keep a clean website.

[EDIT]
This turned you to be a "here is why I didn't closed the question" list.
I wasn't expecting that. I don't care about the reasons you don't close questions. I'm sure (most of them) are legit reasons.
I wanted to focus more on how we can make the closing process and the on topic questions a little more clear...if that is possible.
Answer: Side note, this is related.
As a moderator I try to be very careful when closing questions or deleting answers. I always stop to consider that it may not seem relevant to me, but it might be relevant to someone else. A good example are the non-code questions, which I believe we have decided to allow as a community. That was part of the logic for starting this site in the first place.
Above all, the Stack Exchange ethos dictates that we correct rather than censor content; in other words, the goal should be to help people ask better questions or write better answers rather than make their content (or them) go away.
I apologize for the occasional inconsistency in which close/delete requests are handled, and I do wish that we had some clear reference in place which can always be cited. When I err though I will always err on the side of leaving things open.
As a side note, I sure wish there were something besides chat to have the extended discussions in comments. Sometimes it's really necessary and historically valuable.
Answer: To speak for me, who did vote against closing for at least one of your examples:
I voted against the closing of Which Magento modules allow to set tiered pricing depending on category? as I could see a valid but bad formulated Question. So instead I made the Question more clear with an edit. I think we are not only responsible to clean up, we are also responsible for improve possible valuable questions.
I know my answer on this question is far away from being good (thats another issue), but I see the question as valid and think it could help other people. Maybe it still needs some more content/focus.
Other questions,
especially the a few day old questions get partially skipped from me, dont know how this affects the result

Closing questions


Serialize Object

Question: I am new to serialization and I cannot for the life of me figure out how to fix this exception I am getting...
I have an object that has the following structure
<code>[XmlRoot("MaxCut2")]
public class MaxCut2File : IFile
{
    public MaxCut2File()
    {
        MyJob = new Job();
        Job.Reference = "MyRef";
    }

    [XmlElement("JobDetails", typeof(Job))]
    public IJob MyJob
    {
        get;
        set;
    }
}
</code>
An inteferface...
<code>   public interface IJob
    {
        string Reference { get; set; }
    }
</code>
And an class
<code>[Serializable()]
public class Job : IJob
{
    [XmlElement("Reference")]
    public string Reference { get; set; }
}
</code>
When I try to serialize an instance of the MaxCut2File object I get an error
{"Cannot serialize member 'MaxCut2File.MaxCut2File.MyJob' of type 'MaxCut2BL.Interfaces.IJob', see inner exception for more details."}
"There was an error reflecting type 'MaxCut2File.MaxCut2File'."
However if I change my property MyJob from the IJob type to the Job type it works fine...
Any ideas?
Answer: You cannot serialize an interface. How would the serializer know which type will be used? You simply said there's an interface.
Answer: There is a little trick You might give a try :
Serializing an interface
Answer: Try adding:
<code>public interface IJob : ISerializable
</code>

Serialize Object


Error while trying to update google sheet using PostgreSQL data via Python

Question: I'm using the below code to update the google sheet i have with the data from a PostgreSQL table.
The table refresh every 15 to 30 minute and i need to update this Google Sheet with the latest data.
Below is the Google sheet columns.Need to update the values from the database from the 4th row onwards.

Below is the code,
import psycopg2
import gspread
#Service client credential from oauth2client
from oauth2client.service_account import ServiceAccountCredentials
# Print nicely
import pprint
#Create scope
scope =  ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']

cnx_psql = psycopg2.connect(host="xxx.xxx.xxx.xx", database="postgres", user="postgres",
                         password="**********", port="5432")
print('DB connected')
psql_cursor = cnx_psql.cursor()

Sql_query = '''select product_id,low_stock_date,sku from test.low_stock_date;'''
psql_cursor.execute(Sql_query)
results = psql_cursor.fetchall()
cell_values = (results)
#print("Executed the query...")
#print(cell_values)

creds = ServiceAccountCredentials.from_json_keyfile_name('/Users/lino/Documents/GS_secret/secret_key.json',scope)
client = gspread.authorize(creds)

sheet = client.open('https://docs.google.com/spreadsheets/d/*****cBOfy***z8WFOS*****').sheet1
pp = pprint.PrettyPrinter()
#Access all of the record inside that
result = sheet.get_all_record()

for i, val in enumerate(cell_values):
    cell_list[i].value = val
    sheet.update_cells(cell_list)

psql_cursor.close()

cnx_psql.close()

Getting the below error,
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gspread/client.py", line 123, in open
    self.list_spreadsheet_files()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gspread/utils.py", line 37, in finditem
    return next((item for item in seq if func(item)))
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/lino/Documents/Googlesheet_update.py", line 30, in <module>
    sheet = client.open('https://docs.google.com/spreadsheets/d/*********').sheet1
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gspread/client.py", line 131, in open
    raise SpreadsheetNotFound
gspread.exceptions.SpreadsheetNotFound

Note: Have shared the google sheet with the client email address.
Answer: You are trying to open the spreadsheet using the full URL, but you're using the open function that only works with titles.
From the docs:

You can open a spreadsheet by its title as it appears in Google Docs:
sh = gc.open('My poor gym results')

If you want to be specific, use a key (which can be extracted from the spreadsheet's url):
sht1 = gc.open_by_key('0BmgG6nO_6dprdS1MN3d3MkdPa142WFRrdnRRUWl1UFE')

Or, if
  you feel really lazy to extract that key, paste the entire
  spreadsheet's url
sht2 = gc.open_by_url('https://docs.google.com/spreadsheet/ccc?key=0Bm...FE&hl')

In your case the last example is the way to go, so use client.open_by_url instead of client.open


Phonegap local directory select

Question: How to save a file to a specific directory with Phonegap?
I'm new to Phonegap, and the file API is driving me crazy!...
When this code runs I get error 5 (encoding error), the file on the console log seems correct... Please help!
I'm trying the following code:
function saveToFile() {
  window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSSuccess, onFSError);
}

function onFSSuccess(fileSystem) {
  var filePath = cordova.file.dataDirectory + 'test.txt';
  console.log(filePath);
  fileSystem.root.getFile(filePath, {create:true, exclusive:false}, gotFileEntry, onFSError);
}

function gotFileEntry(fileEntry) {
  console.log('Save to: ' + fileEntry.toURL());
  alert('Save to: ' + fileEntry.toURL());
  fileEntry.createWriter(gotFileWriter, onFSError);
}

function gotFileWriter(writer) {
    writer.onwrite = function(evt) {
      console.log('Write success!');
      alert('Write success!');
    };
  writer.write('Imperyal Test!');
}

function onFSError(err) {
  alert(err.code);
}

Comment: what OS are you using?
Comment: I'm trying to target android and ios. That's why I'm using cordova.file.dataDirectory, it is read/write on both...
Comment: can you log the app and say where you get this error?
Comment: I'm getting the error on fileSystem.root.getFile
Comment: dont have the device to try now but, if you didnt, look at here https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md. it was working to me
Comment: That's the page I was using, and http://docs.phonegap.com/en/1.4.1/phonegap_file_file.md.html also. The code seems correct...
Answer: Make sure that your app loads cordova.js and that the file is present in your platform project.  Check the console to see if cordova.js isn't found on load. Make sure your calling saveToFile in the onDeviceReady event handler.
In this SO question the user was missing cordova.js from the project.
I don't see errors in your code. Sometimes when a plugin misbehaves, simply running the add script again fixes issues. Try running
 cordova plugins add org.apache.cordova.file

Phonegap local directory select


What scales can I use to jam out to a G major scale?

Question: I am playing this track:

Along with this track, I can do the following:

G Ionian Mode (Major Scale): G A B C D E F# (G)
G Major Pentatonic/E Minor Pentatonic
B Minor Pentatonic
Chords: Gmaj7 - Cmaj7

Here are my two questions:

What other scales can I do that can sound good to change it up to for a single measure (I feel too much monotony)?
Maybe even an amalgamation of one scale into another (which maybe creates a named scale too).

I'm thinking of giving a momentary taste of any other scale, be it Latin, Indian, Blues, or anything to jazz it up.
Comment: G maj. pent., yes, but Em pent. would centre around E, so not be so convincing.
Comment: Maybe you should try jumping into the Melodic world :). Most jazz soloing doesn't depend on modes. So if you're looking to "Jazz it up" try learning to improvise by using your arpeggios! Or you could get a bit more complex by playing arpeggios while tritone substituting.
Comment: @Qweevs, that sounds interesting. I wasn't sure what tritone substituting was, but that seems to be the type of thing I'm looking for. As for arpeggios, I would like to see some notes written to give me some new ideas, because it may be that I'm running out of arpeggios. Can you link to a resource that would provide arpeggios that I should keep in my arsenal? Also, your reply deserves to be an answer. THANKS!
Answer: Lots of possibility, including:

G blues scale
Alternating GMaj D7
GMaj bebop scale (ionian with additional D# which must not fall on a beat)
G lydian
G harmonic major (ionian with b6)
...

Check the Scale Syllabus for more ideas
Answer: Jazz is one of the most sophisticated genres to improvise over and it can be seen as a style to add in the most theory as possible that not only sounds good, impressive or inspiring for other conscious musicians listening, but to also to sound nice to the average music listener who has no experience in music.
The scales that you are already playing are nice. But as you said, it can sound a bit monotone due to most of them having similar notes. As I said in the comments, in jazz players tend to not rely on modes for improvisation.
So, what is another improvisation method?
To use your arpeggios, which, as you already know, is just individualising the notes of a chord. e.g. in your case of playing the chords Gmaj7 - Cmaj7, you can play your Gmaj7 or Cmaj7 arpeggio (pretty obvious).
Arpeggios are good because you're not just improvising over one or two scales throughout a song, instead you have to change your improvising structure each chord change and take into account majors, minors, suspendeds, additives, augments, alterations and substitution! :D The possibilities are endlesssssssssssssssss!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
A good friend of mine Jens Larson makes an awesome playlist showing you how to use arpeggios to improvise. But I recommend that you learn some of the theory from the links that I am yet to provide before you go to his playlist. Just so it's not too confusing :)
!From here on down think of all chord structures as arpeggios eg. Gmaj7 = Gmaj7 arpeggio!
After knowing some basic arpeggios you can then add in tritone substitution. Here is the most common example where you completely substitute out a chord (or arpeggio)
 for another (we will use the simple standard ii - V - I, make sure you think about using these as arpeggios and not chords)
Initial Standard:

Dmin9 - G7 - Cmaj7

Standard with substitution:

Dmin9 - Db9 - Cmaj7

Where the G is completely substituted out for the Db.
You can also add in Alterations where you add in other notes to create more tension in improvising which can sound nice if your bass player and other instruments are sticking on the root chords(It's not going to sound nice if the whole band tritone substitutes, you need a root notes in order to substitute off of). I'll use the same standard as before for example purposes.
Standard with Alterations:

Dmin9 - G7b5#9 - Cmaj6/9

There are a literal tonne of different alterations that you can add in that depend on the song. The most common (and easiest to first learn) is b5, #5, b9 or #9 alteration. Justin Guitar does a good video explaining a lot about alterations here. Just make sure you arpeggiate the chord structures in which you will be learning in order to improvise over. After watching that video that explains basic alterations, here is a link that explains all about it in depth.
!!!SOLO AWAY!!!
EDIT: Depending on what kind of style you want out of your improvisation, you can learn how to pop and bop which is to change up the pronunciation of each note and to add pauses, cuts and holds to add unusual timing that somehow sounds appealing. At the start of this jamming track by QuistJam he does a lot of popping and bopping. It sounds awesome!


MySql Query for fetching first record of every hour in Table

Question: I have a table with thousands of records of meter data. Every smart meter will keep on sending data. I want to fetch only the first record of every hour, for each meter.
Here is an example of data in the table:
meter_id    meter_time
300020013   2014-03-01 02:06:06
300020013   2014-03-01 02:06:06
300020013   2014-03-01 02:06:06
300020013   2014-03-01 02:06:06
300020013   2014-03-01 02:06:06
300020013   2014-03-01 02:06:06
300020007   2014-02-19 16:05:31
300020007   2014-02-19 16:05:31
300020007   2014-02-19 16:05:31
300020007   2014-02-19 16:05:31
300020007   2014-02-19 16:05:31
300020007   2014-02-19 16:05:31

Comment: Can you post any code that you have tried to do this? Also, please post the layout of your table such as field names and types
Comment: meter_id meter_time
300020013 2014-03-01 02:06:06
300020013 2014-03-01 02:06:06
300020013 2014-03-01 02:06:06
300020013 2014-03-01 02:06:06
300020013 2014-03-01 02:06:06
300020013 2014-03-01 02:06:06
300020007 2014-02-19 16:05:31
300020007 2014-02-19 16:05:31
300020007 2014-02-19 16:05:31
300020007 2014-02-19 16:05:31
300020007 2014-02-19 16:05:31
300020007 2014-02-19 16:05:31
Answer: This should be your solution:
SELECT HOURS, RECORDS FROM HOURS GROUP BY HOURS

Here is the SQL Fiddle.
Comment: Then can you please elaborate your problem with some demo data.
Comment: It's not my problem, it's from my understanding of the users problem.
Comment: Then as per my understandings the solution is absolutely correct. U must prefer them at least.
Comment: @ankit there is no problem in existence for which this should be considered the correct answer


Strato VM stops connecting via SSH after reboot

Question: I have a virtual machine by strato. After rebooting VM can't access via ssh. Strato has  a Recovery Manager which keeps the recovery sytem under /repair. How should I start to debug the issue which logs should I check?
Answer: Could be anything.

is the ssh daemon starting at boot time?
check /var/log/* for anything suspicious (grep -r ssh /var/log)
is ssh using port 22? Check /etc/ssh/sshd_config
check the firewall configuration whether port 22 is blocked

If all fails, purge then reinstall the ssh package, this should reset everything to the well known defaults.


Delete cells in table view Iphone with edit button

Question: I have a table view with different cells and basically I would like an edit button which would then make those red circle appear in each cell and be able to delete them. I already know how to make the "Edit" button appear and also I have overridden the commitEditingStyle method for the table view so I would like to know how to link the button to the action which trigers the red circle and how to make them appear and finally how to actually delete the cells thankyou :)
Answer: The editing style on your table view cells should be set to UITableViewCellEditingStyleDelete, and then you just need to make sure to call setEditing:animated: on your table view. UITableViewController can help provide a lot of this functionality pre-baked.
Answer: That's actually done through an undocumented API (though I'm not quite sure why) - using it would probably get your app rejected.
However, lots of apps simulate this functionality with their own code - you'd basically define a custom UITableViewCell subclass which changed its background color / toggled that extra red circle image when tapped, keep track of which cells had been tapped, and finally delete them all by calling deleteRowsAtIndexPaths: on the table with the collected list of rows.
Comment: This is incorrect. All the methods for the standard delete appearance are public and well-documented.
Comment: I was referring to the multi-row selection API from email etc, which is what I assumed he meant.


Planar bipartite graph

Question: I know that the number of edges for a face in a bipartite is at least 4. Clearly, we cannot have 3, because we will need to move back to the other side to have face. But, I'm having difficulty in imagining a face of a planar bipartite graph. Where can I find an example of it?
On the other hand, I have found the following equality and inequality, but I couldn't grasp exactly what they are saying, if someone can elaborate for me them, I would be glad.
$$2 |E| = \sum_{i \geq 4} i F_i$$ where $i$ is the number of edges of the face $F_i$ and $F_i$ is the number of faces with $i$ edges. Clearly this is somehow consequence of the handshaking lemma, but why multiplying number of edges of a face with the faces give us this result? Shouldn't we use the degree of each vertex for handshaking lemma?
The second inequality is this one
$$4 \sum_{i \geq 4} F_i \leq \sum_{i \geq 4} i F_i$$
$$4 |F| \leq 2|E|$$
I mean, the second part is form the above equation, but first part the 4 confuses me. Is it because we need at least 4 edges for a face in bipartite graph? If yes, why do we need it actually in this inequality? Second question, why does this inequality hold? A clarification would be highly welcomed.
Answer: Here's a simple example of a planar bipartite graph:
<code>           a
          / \
         /   \
        b--c--d
         \   /
          \ /
           e
</code>
It has three vertices, $a,c$, and $e$, in one part and two, $b$ and $d$, in the other. It has three faces: one is the triangular region bounded by the cycle $abcd$, another is the triangular region bounded by the cycle $bcde$, and the third is the external face bounded by the cycle $abed$. Each of these faces has $4$ edges and $4$ vertices.
To see why $$2|E|=\sum_{i\ge 4}iF_i\;,$$ note that each edge of a planar graph is adjacent to two faces, one on each side of it. Suppose that the graph has faces $f_1,\ldots,f_n$, and face $f_k$ has $e_k$ edges for $k=1,\ldots,n$. Then $e_1+\ldots+e_n$, the sum of the numbers of edges of the faces, counts each edge twice, once for each of the two faces adjacent to it. Thus, $e_1+\ldots+e_n=2|E|$. But $e_1+\ldots+d_n$ is the same thing as $\sum_{i\ge 4}iF_i$. $F_i$ is the number of faces with $i$ edges, so $iF_i$ is the total number of edges for all of the faces with $i$ edges, and when we sum over $i$, we get the total number of edges of all of the faces of the graph. The degrees of the individual vertices don't enter into it.
In the example above, $F_4=3$, and $F_i=0$ for $i\ne 4$, so $\sum_{i\ge 4}iF_i=4\cdot3=12=2\cdot6$, which is as it should be, since there are $6$ edges.
The see why the inequality
$$4\sum_{i\ge 4}F_i\le\sum_{i\ge 4}iF_i$$
holds, notice that if $i\ge 4$, then $4F_i\le iF_i$. Since we're summing only over values of $i$ greater than or equal to $4$, we therefore have
$$\sum_{i\ge 4}4F_i\le\sum_{i\ge 4}iF_i\;:$$
each term on the left is less than or equal to the corresponding term on the right, so the sum on the left must be less than or equal to the sum on the right. And of course
$$4\sum_{i\ge 4}F_i=\sum_{i\ge 4}4F_i\;.$$
Finally, $\sum_{i\ge 4}F_i$ is simply $|F|$, the total number of faces, since every face has at least $4$ edges: we're just adding up the number with $4$ edges, the number with $5$ edges, and so on. Thus, $4\sum_{i\ge 4}F_i=4|F|$. Combining this with the inequality and the original equation, we see that $4|F|\le 2|E|$ (and hence $2|F|\le|E|$: the number of edges of a planar bipartite graph is at least twice the number of faces).
In the example above $|F|=3$ and $|E|=6$, so in this case the inequality is actually an equality: the number of edges is exactly twice the number of faces.
Comment: Thank you very much Brian!
Comment: @portal: You're welcome!

Planar bipartite graph


Bayesian regression confidence intervals with Pymc3

Question: This question is based on question 1 of the week 2 Statistical Rethinking problems, i.e. q1 here:  https://github.com/rmcelreath/stat_rethinking_2022/blob/main/homework/week02.pdf
I have a pandas data frame df with observed weights and heights (df.weight and df.height resp.)
I am trying to use linear regression (predicting weight from height) with Pymc3 to find an 89% confidence interval for the weight of an 140cm tall individual.
This is my setup so far
with pm.Model() as q1_model:
    # specify the model
    alpha = pm.Normal('alpha', mu=45, sd=100)
    beta = pm.Normal('beta', mu=0, sd=10)
    sigma = pm.Uniform('sigma', lower=0, upper=50)
    weight = pm.Normal('weight', mu=alpha + beta * df.height_c, sd=sigma, observed=df.weight)

    # find the posterior distribution of the weight
    trace = pm.sample(1000)

where df.height_c is df.height - df.height.mean(). But I'm not sure how to get the interval. I tried:
pm.hdi(trace.alpha + (140 - df.height.mean()) * trace.beta, 0.89)

which gives [35.0, 36.6] but I think this is just an interval for the mean height mu of an 140cm person, not for height itself. The actual interval is supposedly meant to be [29.1, 42.8] confirming my suspicion here.
Comment: What is the function of 'sigma' in your model and is it involved in computing the posterior distribution for the weight of a person of 140cm?
Comment: Sigma is a parameter of the normal distribution that the weight follows. I.e. if weight and height are $w$ and $h$, then $w$ follows distribution $N(\mu, \sigma^2)$, $\mu = \alpha + \beta h$. So sigma is just the standard deviation.
Comment: Is this sigma used in the computation of the interval? Or do you only use the posterior of $\mu$?
Comment: Regarding terminology, it is a credible interval you wish to calculate.
Comment: @SextusEmpiricus Yes sigma is used in the computation of the interval
Comment: @AzamatBagatov how did you tell the `hdi` function to include sigma in the computation?
Comment: @SextusEmpiricus Sorry I didn't realise which interval you meant. In my interval [35.0, 36.6] I didn't use sigma. But in the correct interval which I am trying to get, that is [29.1, 42.8], I am fairly certain that it uses sigma. I am, however, not sure how to use sigma in my calculation.
Answer: This exercise asks for a model of weight given height and a 89% compatibility interval for the weight of an individual with height = 140cm.
Aside: @GrahamBornholt comments that "it is a credible interval you wish to calculate". So let's clarify the terminology. McElreath prefers the term "compatibility interval" to highlight that the "the interval indicates a range of parameter values compatible with the model and data." The crucial thing to keep in mind is not the name of the interval but its interpretation, which is fundamentally different from the meaning of a frequentist confidence interval. See What's the difference between a confidence interval and a credible interval?
I'll use a bit of math to go with the python code. Let $x$ denote height (in cm) and $y$ denote weight (in kg). Then the regression model for $y$ given $x$ is:
$$
\begin{aligned}
y = \alpha + \beta(x - \bar{x}) + e, \quad e \sim \operatorname{N}(0,\sigma^2)
\end{aligned}
$$
The weight of a 140cm-tall individual ($x = 140$) is modeled as the sum of two quantities: the average weight of 140cm-tall persons $\operatorname{E}(y) = \alpha + \beta(140 - \bar{x})$ plus the difference $e$ between the individual's weight and the average weight at that height; this difference is called the error.
So to construct a compatibility interval for the weight of a person (rather than a compatibility interval for the average weight) at a specific height, you have to simulate both $\operatorname{E}(y)$ and the error from the posterior. As McElreath explains in Section 18.104.22.168: sample from the posterior to simulate $y$s, not a distribution of plausible average $y$.
First set up and fit the model.
import numpy as np
import pandas as pd
import pymc3 as pm
import scipy.stats as stats

np.random.seed(1234)

howell = pd.read_csv("Howell1.csv", sep=";")
adults = howell.query("age >= 18")
x = adults["height"].values
y = adults["weight"].values
xbar = np.mean(x)

with pm.Model() as model:
    alpha = pm.Normal("alpha", mu=45, sd=100)
    beta = pm.Normal("beta", mu=0, sigma=10)
    sigma = pm.Uniform("sigma", lower=0, upper=50)
    weight = pm.Normal("weight", mu=alpha + beta * (x - xbar), sd=sigma, observed=y)
    trace = pm.sample(1000, tune=1000)

The exercise asks about the weight of a 140cm-tall person.
x0 = 140

First we construct a 89% compatibility interval to represent the uncertainty about the average weight of 140cm-tall individuals.
pp_Ey_at_x0 = trace.alpha + trace.beta * (x0 - xbar)
pm.hdi(pp_Ey_at_x0, hdi_prod=0.89)
#> [34.8, 36.7]

Then we construct a 89% compatibility interval to represent the uncertainty about the weight of a person who is 140cm tall. [This is also called a prediction interval.]
pp_y_at_x0 = pp_Ey_at_x0 + stats.norm.rvs(0, trace.sigma)
pm.hdi(pp_y_at_x0, hdi_prod=0.89)
#> [27.8, 43.6]

PS. It would be worth it to revisit the prior specification. Does the prior weight ~ $\operatorname{N}(45,100)$ at the average adult height seem plausible? Careful consideration about the prior is a big part of Statistical Rethinking. And it's a big part of doing Bayesian analysis well. See Section 184.108.40.206 on choosing priors and especially Figure 4.5 for an illustration of prior predictive simulation.