How did students remember what to practise between lessons without any sheet music?

Question: Before the time when sheet music was popular people were good at playing keyboard instruments. I am referring to the time when printing books was expensive.
How did the students remember what to practise between lessons without any sheet music? What did they have back then that we have lost today?
I just want to know what happened to our memorization. I am especially interested how one can learn from those people and apply it to our own lives.
Comment: It's interesting that people have forgotten (or never knew) that it's possible to copy music by hand
Comment: Depending on what part of history you're talking about, there was also a lot of improvisation in olden days.  Basso continuo was almost exclusively improvised, so the written sheet music (if it existed at all) was often just a suggestion, and the player would have to make it up as they went along.
Comment: I recommend [O'Brian's *Aubrey-Maturin* series](https://en.wikipedia.org/wiki/Aubrey%E2%80%93Maturin_series). The title characters serve as captain and physician aboard warships in the early 19th century, and they like to play the violin and the cello. It is mentioned multiple times in the series how they will borrow new music when in port *and copy it themselves by hand during the next voyage*.
Comment: Hi, your question would be greatly improved if you could cite some sources indicating historical time periods when musicians did (or didn't) have access to written music.   As to memorization, what makes you think we don't memorize now?
Comment: Sheet music has been popular for longer than most (if not all) keyboard instruments.
Comment: > *Before the time when sheet music was popular people were good at playing keyboard instruments* ... Whaat? `{citation-needed}`.
Answer: Besides the copyist mentioned in the other answer, students could simply write on their own! No need to have someone copy it for them. Also it was not uncommon for teachers to write stuff down for their students. I have had teachers that  give  handwritten scores (or copies of them) and notes to their students.
This still is a way that is pretty cheap since it doesn't require hiring someone else, so if you had money for a teacher and paper you could easily study at home.
Comment: I have been told that they were better at the art of memorization back then. I am told that we are bad at memorizing today.
Comment: as keyboard teacher (groups of very young pupils)   my philosophy was: I don't teach playing keyboard,  I'm teaching music by playing keyboard!) so my concept was: 1. to sing a new piece, 2. try to play the tune, 3. search the chords, 4. choose an accompany pattern .... and 5. finally notate the tune with the chords, and the rhythm-harmony pattern just 1 bar. The task was to write down the sheet music, starting with easy songs for children.
Comment: Indeed. And I wouldn't even be surprised if students were _expected_ to do so. Being able to not only read, but also write sheet music is a valuable skill for a musician, amateur or otherwise. Just like it is in any other language. Doesn't mean you have to be able to **_compose_**, just to know the musical alphabet, and know how to write in it.
Comment: @Hank: Might be true, might not be. It's certainly _easier_ nowadays to just "forget and find" whatever it is you need. Anyway: "Practice from memory" has a very big potential of practicing the wrong thing. I'd say that "in the old days", being sent to a music teacher was definitely a luxury item (and still is), and most likely came with the expectation (or at least hope) that the child would start a (breadwinning) musical career, and they'd expect the child to its part. "What/who do you want to be when you grow up?" only appeared as a question to children after (let's say) the 50's.
Answer: Students could  memorize the stuff (good for memory practice) or copy out the examples. Copying out "old masters" is a very good way to learn. One picks up patterns and see stuff from a different point of view for that of just playing the piece (of course, it's not so easy to play a symphony as a single person.)
I have found this lots of help. Currently I'm copying (in Finale) the first movement of Haydn's "Emperor Quartet." I've already discovered that Haydn's rhythmic structures are much more complex that most popular music or lots of other classical stuff. It's a good way to learn something during "composers block" or when bored.
Comment: @phoog - As someone who both composes and transcribes music into Musescore, I find that I do NOT learn how to play piano music by copying it out (and then trying to memorize it). I learn far faster by playing it on an actual keyboard.
Comment: @Dekkadeci I don't mean learn to *play* but learning the notes, harmonies, etc., from a theoretical and analytical point of view, as one would before conducting or coaching a piece.  Of course the best way to learn to play something is by playing it.  I'm not trying to draw a contrast between practice and copying as learning tools, but between copying with software and copying with pen (or pencil) and paper.  I find the latter is much more effective.
Comment: Try copying it out by hand and see whether you agree that you learn the music better that way.
Comment: @ Dakkadeci: I often copy  a piece by hand, reduce, transcribe or transpose it and also guess how it might continue - also from downloaded Pdf and midi-files - even I have been using several notation software for many years.
Answer: The question is fairly vague in asking for time-period, and music style. As such, I feel the best way to answer is to give you an impression of the various ways music was shared historically.

Regarding Written Forms
Firstly, written notation of music goes back multiple thousands of years - with examples of "something musically related" being found on a Sumerian tablet (~2000B.C.), and the oldest example of a full-melody being inscribed on an epitaph from ~100AD
Closer to what we'd consider "written music"; during the middle ages of western society (5th-15th century), and continuing somewhat after the proliferation of the printing press (15th century) - the music is written in manuscripts. Many of the examples of this are chants (unsurprising as the Monks/Nuns were one of the few literate groups). Due to the literacy rate, creating a copy of music is something that would be done by a "professional" copyist, hired by the Abbess (superior nun in charge of an Abbey).
After this, is a period where printing music was possible but expensive. As such, sheet music was used - but only affordable by the aristocracy.
Beyond this, after the proliferation of the western printing press, developments were made in printing music, and for the majority of the 16th and 17th centuries - allowed for a cheap printing process that opened up written music to a much wider audience.

Regarding Literacy
While the above mentions the various ways written music was shared; it should not be taken as a given that the majority of people could read it, or copy it.
It is estimated that in the early 16th century; we're looking at approximately 10% of the male population of England being literate enough to "sign their name at marriage". While even as we reach Bach's death (1750) we're only just hitting a rate of 50%.

So how was it actually taught
We now have a clearer image of the situation:

For some small communities, of literate individuals, music was written - and shared by copying. The music could then be learned by this literate community and performed. In many of these communities (e.g. Monks), study was the main part of life - and so learning to perform music would be part of daily life.
Later, as writing developed, the aristocracy became more able to compose complex works and share them by having them manually copied. This opened up the ability for composition and performance to be studied by private individuals, and for apprentices to be tutored by their masters.
Finally, printing evolved to the point where complex pieces could be reproduced and shared easily (within the middle class) - allowing those who were educated, to learn in a style fairly similar to what you imagine in modern day (lessons and tutoring).

However, there is clearly an abundance of music that existed outside of these small enclaves and aristocracy. Looking at how this was shared, should give a good idea of the other side.
For this, it's worth considering two types of music that were shared. Firstly, folk music and secondly the music shared by Minstrels (the people you would imagine when you think of "bards").

Folk Music
As with many folk traditions, tales and practices. Folk music was an oral tradition - passed down through families and communities via practice.
In the same way as many scouting songs, simple hymns and nursery rhymes are learned in modern days - folk music would be learned by hearing it and taking part. This of course includes instruments, where individuals would learn by being shown how to play that community's songs.
Of course, it is also worth remembering that while using sheet music to learn may seem important in modern times - the complexity of most folk music isn't that high, and given that there were less things to do outside work; there was more time to spend passing on your skills each day. As such, it is far from a necessity to have written music, in order to pass it on.
Minstrels
This then leaves the slightly more organized side of amateur music; Minstrels.
While Minstrels originally played in courts for nobility, unlike the religious enclaves they often were not literate and relied on memorization and improvisation.
At this point, Minstrels were generally just "entertainers", and being able to construct songs and poetry was just another "talent" - similar to those who could juggle, or do acrobatics.
For Minstrels, it's not clear how they would originally learn their music - most likely from the same roots as those performing folk music. However, in the 14th century, guilds formed that allowed Minstrels to pass on their art from master to apprentice, as a profession (again, not necessarily via written medium).
During the 15th century, printing developments (noted above) then also helped to close the gap between the clerical (who were literate) and minstrels began to break down - as more Minstrels were able to pass on their music via written form.
The decline of Minstrels around this point, is probably a fair sign that this is where the majority of music began transitioning from oral tradition & improvisation, to a craft that could be taught in a structured way with sheet music.

Conclusions
Obviously, this is a deep topic with a lot of different areas involved. There are huge areas of music that have been missed here that don't fit any of the groups above (e.g. Troubadours, and many, many others).
However, I'm hoping this answer will have given some idea of where you might want to look further - and importantly, give an idea of how varied the situation was between different communities, social classes and times.
And to add salt; this answer has almost entirely focused on just a single culture

But, to answer the question most directly:

What did they have back then that we have lost today?

Time, and lots of it.
Music for the average person was far simpler than what the average player handles today. Importantly, the amount of time learning could be the majority of some people's lives - while today, it would be surprising to spend more than a couple of hours in the company of a "master" each week.
Beyond this, if you're looking for something to take away from this; it'd be, that for the majority of people, music was a way to bring them closer to the community, and part of daily life. Being similarly open to improvisation, and playing simple music with friends may be something to consider. But that feels overreaching, and the simple answer is "they were just humans, with more time, and less things to do".
Answer:
I am referring to the time when printing books was expensive.

Before people had books, they had clay tablets, papyrus and stone carving.
This is how the greek did it:

And this is how the mesopothamians (sumerians, assyrians, babylonians etc.) did it:
(You can actually listen to someone from our time playing that score if you follow the link).

Writing into those things is way harder than writing on paper, and paper has been around for longer than books. Point being that no matter when you lived, if you could write you had no excuses.
Comment: @MichaelCurtis - As far as this answer describes, both examples are essentially sheet music. They're just not books!
Comment: @Dekkadeci, so many times I've read there aren't known examples of ancient music, but both links show that isn't the case. I thought this was just a picture of papyrus and a clay tablet and missed the line about the performance. Very interesting!
Comment: Are either of those examples music? The question is about music written and memorized.
Answer: You also have to remember that anyone rich enough to own a keyboard would be able to afford books. Tutorials and practice pieces made up a large proportion of early publishing (c. last 400 years).


How can I get the href value from a link?

Question: I have a link I render in a template file with the following markup.
{{ item.caption.link }}

I want to show only the href value. None of the following worked for me.
{{ item.caption.link[0]['#url'] }}
{{ item.caption.link.0.url }}
{{ item.caption.link[0]['#url']|render }}

Answer: I think it might be better if you pass just href value as a variable to Twig and not the complete HTML markup.
Put HTML in Twig and just fill it with the values (href value in that case) you need.
Comment: It's hard to say without knowing what this variable holds. Can you inspect it with Xdebug or sth?
Comment: This is generated dynamic by a module and I am override the twig template in theme
Answer: First look for the available attributes with this tutorial on XDebug.
Another method to inspect a variable is to  use the dd() function. See this question to install it.
Put the following in your template, it will print all the available attributes of your link :
{{ dd(item.caption.link) }}

Try the following :
{{ item.caption.link.0['#url'] }}

If this doesn't work, you should access at least to the uri. See this question to get an URL from the URI.


Undefined symbol "php_libxml_disable_entity_loader"

Question: I have php5.4 installed.It runs on freebsd server
I also use soap.so extension. But when I start php script (new SoapClient) it stopped.
Apache logs:
tail -f /var/log/httpd-errors.log :
/libexec/ld-elf.so.1: /usr/local/lib/php/20100525/soap.so: Undefined symbol "php_libxml_disable_entity_loader"

I tried reinstall php5-extensions after portupgrade
Can anybody help me? Thanks
Answer: I had exactly the same problem and it disappeared after upgrading all packages to latest versions.
I believe it was caused by version mismatch between packages (I installed php-soap later, so it was more recent version).
Comment: "I installed php-soap later". Me too.
 I had `portsnap update` and reinstall `php-extensions`.


Regarding bracket and parenthesis for formula in C++

Question: I was given a formula in this format
Data  = [ (percentage / 15) – (var1 + var2)  / 20]  *  [ var3 +  var4];

If I put the above statement in, it will compile with
sample.cpp:131:1: error: stray '\342' in program
sample.cpp:131:1: error: stray '\200' in program
sample.cpp:131:1: error: stray '\223' in program

sample.cpp:131:81: error: '(percentage/ 15)' cannot be used as a function

How do I change the data statement to make the formula work in C++?
Comment: Just replace the brackets with parens.
Comment: @baokychen: Type the code, rather than cut-n-paste. The `stray '\xxx'` errors usually indicate that there are non-standard caracters in the input that the compiler does not like.
Comment: Seriously, is this a joke? Any introductory C++ material will cover this somewhere in the first pages. SO is not a substitute for research.
Comment: doesnt work. if i replace brackets with parens
Comment: You should show us what you tried and the errors you got (after replacing the `[]` with `()`.)
Comment: For the first problem (stray characters), this is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray '\302' in program, etc.](https://stackoverflow.com/questions/19198332)*.
Comment: There must be a canonical for the second problem as well (for such a basic problem, even then. It was 4 years after [Stack Overflow](https://stackoverflow.design/brand/copywriting/naming/) launched). Though admittedly it is nontrivial to find.
Answer: There are two problems here:

You cannot use [ and ] for grouping expressions. Change them to ( and ).
The minus sign you're using is actually an en-dash (unicode character U+2013) not the normal hyphen-minus character that you should be using (U+002D). The mapping from source file characters to the basic source character set is implementation defined and your compiler doesn't map en-dash to the minus character (like most compilers, I imagine).

The tip here: don't just copy text from a document to your code, especially when that other document isn't code.
Here's the correct expression:
Data  = ((percentage / 15) - (var1 + var2) / 20) * (var3 + var4);

The error you're getting shows that there are three bytes appearing that shouldn't be there. They are (in octal): 342 200 223. In binary, that's 11100010 10000000 10010011. A quick google search will tell you that that's the binary representation of U+2013.


git submodule update --init --force --remote

Question: When I pull submodule using git submodule update --init --force --remote it creates new files containing git diff for example
diff --git a/app/Services/Payment b/app/Services/Payment
index 72602bc..a726378 160000
--- a/app/Services/Payment
+++ b/app/Services/Payment
@@ -1 +1 @@
-Subproject commit 72602bc5d9e7cef136043791242dfdcfd979370c
+Subproject commit a7263787e5515abe18e7cfe76af0f26d9f62ceb4

I don't what are these files and how to get rid of them and when I remove them the sobmodule checkout to the old commit
Comment: Technical note: you are not *pulling* a submodule. You are *cloning* a submodule or *checking out* a submodule.
Answer: TL;DR
Your issue here is the use of --remote.  Stop doing that.
Long
You mention in a comment on VonC's answer that:

When I [run] git status [I get]
    modified:   app/Services/Notification (new commits)
    modified:   app/Services/Payment (new commits)
    modified:   database/migrations (new commits)

The (new commits) part means: the commit hash ID your submodule is actively using (through its current checkout) differs from the commit hash ID your index (proposed next commit) says should be used.
There's a lot of jargon here ("submodules", "gitlinks", "index", "commit hash ID") and hence a lot to unpack.  We'll get to this in just a moment.
Note that the output of git status above is a more-compact representation of the output of git diff that you quoted in your original question:

diff --git a/app/Services/Payment b/app/Services/Payment
index 72602bc..a726378 160000
--- a/app/Services/Payment
+++ b/app/Services/Payment
@@ -1 +1 @@
-Subproject commit 72602bc5d9e7cef136043791242dfdcfd979370c
+Subproject commit a7263787e5515abe18e7cfe76af0f26d9f62ceb4

What we see here is that for app/Services/Payment, your (main, top-level, "or superproject" repository's index says that this particular submodule should use commit 72602bc5d9e7cef136043791242dfdcfd979370c.  But it's actually using commit a7263787e5515abe18e7cfe76af0f26d9f62ceb4 instead.  We've just added one more jargon term to define: superproject.
Some initial definitions
Let's start with the definition of a Git repository.  A repository is, at its heart, a pair of databases.  One is a database of commits and other internal Git objects.  The other database holds names—human-readable names, because the names Git uses for its own objects are incomprehensible.
A commit is one of the four types of internal objects that Git stores in the first—usually much larger—database.  These commits are numbered, with very large numbers that range up to 2160-1.  These numbers are expressed in hexadecimal, as, e.g., 72602bc5d9e7cef136043791242dfdcfd979370c.  (The commits are the only ones you normally interact with in the way we're about to describe, so we'll just conveniently ignore the remaining three, but they're also all numbered.)
The numbers look random, though they're actually the output of a cryptographic hashing function and hence entirely non-random.  The fact that they come out of a hash function is why we call them hash IDs too.  But the real point here is that they seem to be totally scrambled, and no human is ever going to remember them.  We need a computer for that.
Fortunately, we have a computer.  We simply have the computer remember these hash IDs for us, using things like branch names and tag names.  Each commit also stores, within itself, the hash ID(s) or some previous commits.  We don't really need to worry about that right here, but this is how branches really work in Git.
So:

a repository is
a pair of databases, where one database holds commits
which have hash IDs or big ugly numbers.

We and Git use the second database, of names, to find the hash IDs of particular commits, and we use the commits to find more hash IDs of more commits, and so on.
Commits are read-only: the working tree and the index
Now, a crucial thing to know about these commits—and indeed all of Git's internal objects—is that they are all read only.  They have to be, because of the hashing trick: the hash ID is a function of every single bit that goes into the internal object, and we find the object by the hash ID, so the hash ID must always match.  If the hash ID of some object we extract from the database doesn't match the hash ID we used to find it in the database, Git decides the database is corrupt.1
So the commits are completely read-only.  Not only that, but the files inside each commit—we didn't define this earlier, but each commit holds a full snapshot of every file—are in a special Git-only format, compressed and de-duplicated, that only Git can read.  (Literally nothing can write over them since everything is read-only.)
What this means is that just to use some commit, we must extract that commit.  Git will extract a commit by:

reading the compressed and Git-ified files that are inside the commit;
expanding them into ordinary read/write files; and
writing out those files into a working tree.

This working tree—another bit of jargon—is where we actually do our work.  Here, we can see, read, and even write to files.  They exist as files, not as read-only, Git-only database entries.  So, now we can get work done.
The working tree also enables us to make new commits, but here, Git inserts an extra stumbling block.  Before Git will allow us to make a new commit, Git requires that we copy any updated files back into Git.
This step actually makes a certain amount of sense, because the files we see and work on / with in our working tree are not in Git at all.  They may have been copied out of Git (out of a commit or one of its supporting objects) but once they are out, they are out.
Git calls the place that Git makes us re-copy updated files by three different names: the index, which as a name makes no sense by itself; the staging area, which refers to how we and Git use the index—and the cache, which is hardly ever used any more but still shows up as the flag in git rm --cached for instance.
The index's role as staging area is pretty straightforward.  It takes on an expanded role during merge conflicts, but since we are not worried about these here, we'll just look at how we and Git use it as a staging area.
When we first check out a commit—with git checkout or git switch—Git needs to expand out all the compressed and Git-ified files into our working tree.  But Git secretly sticks a "copy" of each of these files into its index / staging-area.  I put the word "copy" in quotes here because Git's internal file copies are all de-duplicated.  This is why a Git repository doesn't become enormously fat even though every commit stores every file: most commits re-use most files, and in this case, the re-used file takes no space at all, because it's been de-duplicated away.
The same goes for these index "copies": they're duplicates, because the file in question is in the commit.  So the index "copies" take no space.2  But the key for making a new commit is this: the index copies are exactly what is going to go into the next commit.
In other words, the index holds your proposed next commit.  Right now, having done a "clean" checkout of some existing commit, the index matches the commit.  But now you can modify some file(s) in the working tree, if you like.  Once you have modified a working tree file, you're required to copy it back into Git's index.  You do this with git add, which:

reads the working tree copy;
compresses it and otherwise Git-ifies it;
checks to see if the result is a duplicate; and
if it is a duplicate, uses the original (throwing away the temporary Git-ified copy), otherwise uses the new Git-ified file, and uses this to update the index.

The result is that the index now contains your proposed next commit—just as it did before you ran git add.  It's just that now, your proposed next commit has been updated.
You repeat this for all files you intend to update: update them in the working tree, then, sooner or later, but always before running git commit, run git add as needed.  The add step updates your proposed next commit from whatever you are adding.  (Note that a totally-new file goes into the index too, in this same way, it's just that it does not have to kick out some existing de-duplicated copy.)
Hence we now know two things:

The working tree holds the useful copies of your files.
The staging area—or index—holds the proposed next commit, which you update after you update the working tree.

When you do run git commit, Git simply packages up whatever is in the index at that time and puts that into the new commit as the set of Git-ified, read-only, stored-forever, compressed and de-duplicated files.3

1What we can do at this point is currently rather limited.  The most common approach to handling corruption is to throw away the database entirely and clone a new one from a good copy, which works fine since Git is distributed and every repository has thousands of copies "out there".  Of course, it stops working if there's no other copy.
2They take a bit of space to hold the file's name, an internal blob hash ID, and a bunch of cache data—that's where the name cache comes in again—which typically amounts to a bit under 100 bytes per file: hardly anything these days.
3If you use git commit -a, note that this is roughly equivalent to running:
git add -u
git commit

That is, all the -a option really does is insert an "update" style git add before committing.  Git still builds the new commit out of the (updated-by-add) index.  There are several technical complexities here though.  These have to do with atomicity and the operation of Git hooks.  Putting them all together means that if you do use pre-commit hooks, you must be very clever at writing these pre-commit hooks, and/or avoid using git commit -a.  This is not the place for the details, though.

Submodules lead to an explosion of Git repositories
Now that you know:

what a repository is; and
how the index and working tree work

we're just about ready to move on to Git's submodules.
The very shortest definition of a Git submodule is that it is another Git repository.  This definition is perhaps a little too short, though.  It leaves out a key item, so let's try again: A submodule is:

a Git repository, where
some other Git repository refers to this Git repository; and
some other Git repository exercises some control over this Git repository.

We now know that there must be at least two Git repositories involved, and one repository is put into some sort of supervisory position over the other.
This is how we define the term superproject: a superproject is a Git repository that has a submodule.  The superproject is the overseer / supervisor.
One superproject can be the superproject of multiple submodules.  (This is the case for you: you have at least three submodules.  So you have at least four Git repositories involved.)
A Git repository that is acting as a supervisor—playing the superproject role—can itself be a submodule for another Git repository.  In this case, the "middle" repository is both submodule and superproject.  I don't know if you have any of these: there's no evidence one way or another in your question.
Now, one thing about most Git repositories is this: they're clones of some other Git repository.  We mostly work with a clone.  So let's suppose that you have, as your superproject, your clone R1 of some repository R0.  If your clone R1 is the superproject for three submodules, those three Git repositories are themselves probably clones of three more repositories.  So we're suddenly talking about at least eight Git repositories here, in your basic question!
With eight or more repositories, things can rapidly become quite confusing.  There's no longer the repository, the working tree, the index, and so on.  Instead, there are eight repositories, four clones on your computer, four working trees, four Git index things, and so on.
We need to be able to talk about each repository, index, and working tree independently, even though they may be somewhat interdependent.  This means we need names for each one.  To simplify things somewhat, I'm going to use the name R for your superproject git clone, S0 for one of the repositories representing app/Services/Payment, and S1 for another of these.
How this all works
You cloned your superproject repository R from somewhere (from some repository R0), but after that, we can stop thinking about it for a while, so we'll just think about R itself.  Your repository R has commits, and these commits contain files and so on.
You selected some commit in R to check out:
git checkout somebranch

The name somebranch resolves to a raw commit hash ID H, and this is the commit your Git fishes out of R to populate the index and working tree so that you can use R.
There are, as yet, no additional repositories.  There is, however, a file named .gitmodules that came out of commit H in R.  Moreover, commit H lists some gitlinks.  A gitlink is a special entry that will go into a commit, and it contains two things:

a path name, in this case app/Services/Payment, and
some commit hash ID S (in this case 72602bc5d9e7cef136043791242dfdcfd979370c).

These gitlinks go into the index in R.  We'll just talk about this one particular gitlink.
If you now run git submodule update --init (note the lack of --remote here), your Git commands, operating on repository R, will notice this gitlink in the index.  (There's no corresponding files, just the gitlink.)
Your superproject Git commands, executing this git submodule update, will now notice that you haven't yet cloned any submodules, and—because of the --init option—will run a git clone command for you.  This git clone command needs a URL.  The URL comes out of the .gitmodules file.
The repository that Git clones at this point is repository S0 (perhaps over on GitHub: on some server anyway).  The clone gets hidden away,4 creating a new repository S1.  Your Git software now runs a git checkout operation within S1 so as to copy a commit into a working tree and index.
The index for S1 is hidden away in the repository for S1, but the working tree for S1 is placed into app/Services/Payment: the place you want the files you'll see and work with, from the submodule.  So now the ordinary directory (or folder, if you prefer that term) app/Services/Payment is full of ordinary files.  These comprise the working tree for S1.
Your submodule S1 is now ready to use.  We have three repositories we need to think about: R, S0, and S1.  We have two staging areas / index-es: one that goes with R and one that goes with S1.  We have two working trees to use, one that goes with R and one that goes with S1.  The working tree for S1 is inside the working tree for R, but the R repository won't use it.  Only the S1 repository will use it.

4In modern Git, the clone's .git directory is stuffed into R in .git/modules/.  In ancient versions of Git, submodule clones go into a .git right in the submodule path—in this case app/Services/Payment/.git.

git submodule update --remote
The --remote flag to git submodule update tells it that instead of obeying the superproject gitlink—remember, this is an entry in the R index, under the name app/Services/Payment, that currently holds hash ID 72602bc5d9e7cef136043791242dfdcfd979370c—your Git software should enter submodule S1 and run:
git fetch origin

This reaches out to repository S0.  Repository S0 has its own branch and tag names, and its own commits.  Repository S1 was cloned from S0 earlier, but S0 might be updated any time.  So the git fetch step reaches out to the Git software that handles S0 and gets, from that Git, any new commits for S0 and puts them in your clone S1.  Then, as the final step, git fetch origin within S1 creates or updates all of the remote-tracking names in S1 that go with the branch names from S0.
This updates your (local) origin/master, origin/develop, origin/feature/tall, and so on in your S1 based on the branch names as seen in S0.  You now have, in S1, all the commits* from S0, and you know which commit they (S0) call the "latest" commit on their master for instance.
What your git submodule update --remote does now is turn your name origin/master into a hash ID.  The hash ID your S1 Git gets from this operation is not 72602bc5d9e7cef136043791242dfdcfd979370c.  It's actually a7263787e5515abe18e7cfe76af0f26d9f62ceb4.
Your superproject Git now directs your S1 Git to run:
git checkout --detach a7263787e5515abe18e7cfe76af0f26d9f62ceb4

(or the same with git switch; in any case it's all being done internally in the latest versions of Git, though older ones literally run git checkout here).
This populates your S1 index and working tree from commit a7263787e5515abe18e7cfe76af0f26d9f62ceb4.  So that's now the current commit in your S1.
Meanwhile, your superproject repository R still calls for commit 72602bc5d9e7cef136043791242dfdcfd979370c.  That's what is in the index / staging-area for new commits you will make in R.
What to do about all this
If you want R to start calling for a7263787e5515abe18e7cfe76af0f26d9f62ceb4, you will simply need to run:
git add app/Services/Payment

while working in R.  This directs the R Git to run git rev-parse HEAD inside the S1 Git, which finds the current checked-out commit's hash ID.  This hash ID then goes into the R index / staging-area, so that the next commit you make in R will call for that commit by that hash ID.
If you want S to have commit 72602bc5d9e7cef136043791242dfdcfd979370c checked out instead, you have a number of options:
(cd app/Services/Payment && git checkout --detach 72602bc5d9e7cef136043791242dfdcfd979370c)

will do it, for instance.  Or you can run git submodule update.  This command, run in R, tells the R Git to read the commit hash IDs from the R index and run git checkout commands within each submodule, to force the submodule checkout back to the desired commit.
When you run git submodule update --init, if you add --remote, you're directing your R Git to fetch in each submodule and find the latest commit from some branch in the source repository (S0 in our examples here).  The chosen branch is defined in various places in R, although it tends to be master or main these days.  The same goes for git submodule update without --init.  The --init merely means do the initial clone if needed.  The --remote part means do the fetch and get the hash ID from a remote-tracking name.  The crucial part is always the hash ID.  That comes from:

your index, or
some remote-tracking name

and that controls which commit your Git instructs the submodule Git to check out.
The git status and git diff commands, run in R, merely report whether the index (R's index) and working tree (S1's working tree checkout in this case) match.  If not, git diff tells you what the difference is, and git status just says "they are different".
Comment: Yes, it would: that's the point of switching to some different submodule commit and then using `git add` in the superproject: to record (as an updated gitlink) the commit you'd like to refer-to from the new commit in the superproject.
Comment: " A gitlink is a special entry in a commit": nope: it is a special entry in the index (as you mention right after). We went over that already (https://stackoverflow.com/questions/59633536/git-submodules-without-gitmodules-file/59634716?noredirect=1#comment105444518_59634716) (and https://stackoverflow.com/questions/68767609/github-repository-folder-saved-as-shortcut-problem?noredirect=1&lq=1#comment121548074_68767609)
Comment: @torek Thank you  for your answer it was really informative but I'm wondering if I did add and commit the new commit would the superproject now be referring to the new submodules commit?
Answer: A git submodule update should not "generate" any file, beside the submodule folder content.
A git diff i, the parent repository might show you what you mention, as seen in "Starting with Submodules"

If you run git diff on that, you see something interesting:
$ git diff --cached DbConnector
diff --git a/DbConnector b/DbConnector
new file mode 160000
index 0000000..c3f01dc
--- /dev/null
+++ b/DbConnector
@@ -0,0 +1 @@
+Subproject commit c3f01dc8862123d317dd46284b05b6892c7b29bc

Although DbConnector is a subdirectory in your working directory, Git sees it as a submodule and doesn't track its contents when you're not in that directory.
Instead, Git sees it as a particular commit from that repository.
Comment: when I command git status it prints the following   ```modified:   app/Services/Notification (new commits)
        modified:   app/Services/Payment (new commits)
        modified:   database/migrations (new commits)```
Comment: keep in mind That I didn't change any files!
Comment: @OmarAbdelaziz Are those folders the ones you see in the `.gitmodules` file?
Comment: I guess @torek explained it correctly thank you


distVincentyEllipsoid() yielding NA values (geosphere package)

Question: I am using the function distVincentyEllipsoid() from the geosphere package to calculate distances between the world's ports. This function takes as input the longitude and latitude of two places and gives the distance in meters as output. It appears to work well generally, but in some cases it's been giving me NAs for no discernible reason. I was wondering whether anyone was aware of a bug (there is no documentation online I could find that addresses this issue), or could perhaps point me to what I'm doing wrong. What's strange is that it appears to affect only specific pairs – eg. f(a,b) and f(b,a) will give NA, but f(a,c) and f(b,c) will not.
Eg.
Whangarei, New Zealand (Lon:174.35 Lat:-35.76) to Gibraltar, Gibraltar (Lon: -5.35 Lat:36.13):

distVincentyEllipsoid(c(174.35,-35.76),c(-5.35,36.13))

<code>> NA
</code>
...but:
Valetta, Malta (Lon:14.51 Lat:35.89) to Gibraltar, Gibraltar (Lon: -5.35 Lat:36.13):

distVincentyEllipsoid(c(14.51,35.89),c(-5.35,36.13))

<code>> 1787499
</code>
...and:
Whangarei, New Zealand (Lon:174.35 Lat:-35.76) to Valetta, Malta (Lon:14.51 Lat:35.89):

distVincentyEllipsoid(c(174.35,-35.76),c(14.51,35.89))

<code>> 18207301
</code>
(Both of these outputs are correct according to Google Maps - note these values are in metres.)
Any help would be greatly appreciated.
EDIT: Problem solved – Vincenty's distance method fails for near-antipodal points.
Comment: Puzzling behavior from what most people would call a seldom-used function might be better directed to the package maintainer: Try: `maintainer("geosphere")`
Comment: And especially weird since `distHaversine(c(174.35,-35.76),c(-5.35,36.13))` yields an answer.
Comment: After a bit more research, it appears that Vincenty's method can fail for (near) anitpodal points, and [this website](http://www.movable-type.co.uk/scripts/latlong-vincenty.html) suggests it can fail with distances greater than 19,936 km. Which makes sense in your example as the Haversine distance is 19,988 km
Comment: no worries; it was useful for me to know too for my [`spatial.data.table`](https://github.com/SymbolixAU/spatial.data.table) package I'm putting together (the [calculations](https://github.com/SymbolixAU/spatial.data.table/blob/master/R/SpatialCalculations.R) in particular).
Comment: Good point @42, I'll get in touch.
Comment: And thanks @SymbolixAU for pointing that out. Using Haversine might be a good enough solution until my issue with the Vincenty function is resolved.
Comment: Oh, wow – it hadn't even occurred to me that it may be an issue with Vincenty's method itself. Thanks for looking into it! That seems to resolve my quandary.
Answer: Use distGeo instead of distVincentyEllipsoid.  This was added to
geosphere in version 1.5 and it computes the geodesic distance using a
better algorithm (by me!) than Vincenty's.  This returns accurate
results for all pairs of points.  In particular, Whangarei, New Zealand (Lon:174.35 Lat:-35.76) to Gibraltar, Gibraltar (Lon: -5.35 Lat:36.13)
<code>> distGeo(c(174.35,-35.76),c(-5.35,36.13))
[1] 19958627
</code>
This demonstration page shows
examples of near antipodal geodesics displayed in Google Maps.


Count number of entries?

Question: I have an XML doc:

I have the XML doc here:
   XElement entries =
                    doc.Element("response").Element("entries");

How can I get a count of the number of entry in entries?
This example would be 2.
Answer: Try this:
entries.Elements("entry").Count();

Answer: Instead of Element() use Elements(), which delivers an IEnumerable<>. You can then count the number of entries. Using the Count()-method of IEnumerable<>.
See here for reference on MSDN.

Count number of entries?


405 (Method Not Allowed) using Angular httpClient POST

Question: This is the method I use in Angular for making the POST request:
newMessage(m: Message) {
  this.http
    .post<any>('http://localhost:55820/api/message', m)
    .subscribe(res => (console.log(res)));
}

On the server side with asp.net WebApi 2, I receive the request like this:
[Route("api/message")]
[HttpPost]
public IHttpActionResult Create(Message message)
{
    return Ok("Ok");
}

With PostMan the request works fine but using Angular I get an OPTIONS request with a 405 state code instead of the POST request. Am I missing something? Thanks!
Comment: The `OPTIONS` is a [CORS Preflight request](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request). You'll need to make sure that CORS is configured on the server. Postman won't send a Preflight request because it uses a normal POST request, unfortunately AJAX requests are different.
Answer: Try with [FromBody]
 public IHttpActionResult Create([FromBody] Message message)

As For complex types (your own object, for example: Message), Web API tries to read the value from the body of the HTTP request.
Also make sure you handle CORS in your backend.
Answer: The problem was that I didn't configure CORS on the server side. As I'm using .net WebApi 2 for the backend, the only steps I had to follow for solving were the following:

Install CORS (With Nuget package manager)

Install-Package Microsoft.AspNet.WebApi.Cors

Add this line to WebApiConfig.cs

config.EnableCors();

Add this line to the controller before the class declaration

[EnableCors(origins: "http://localhost:4200", headers:
  "*", methods: "*")]

In my case localhost:4200 is my frontend side address. For more information visit the full tutorial: https://learn.microsoft.com/es-es/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api


Debugging a custom module with XDebug and PHPUnit

Question: How can I debug a custom module in Drupal 7 using Xdebug and PHPUnit? That is, I would like to debug and perhaps write some unit tests to eliminate some basic potential problems.
This is a code I inherited that is misbehaving. I am relatively new to Drupal but have some PHP skills.
Any advice is appreciated.
Comment: I'd look for tutorials using PHPUnit & XDebug with Drupal as a first step, try those out, and ask a question if you have during following those tutorials. Right now, this question is too broad to have any answer that would be off topic (we don't do tutorials on Drupal answers).
Comment: Thanks. I am literally just starting out with this so am probably asking for setup and possible tools to use.
Answer: xdebug must be added in the PHP env. Acquia Dev Desktop, DrupalVM, Vlad and other VMs come with it out of the box. As for setting the connection up, IDEs like PHPStorm, Atom and VSCode have walkthroughs on how to do that.
For PHPUnit in Drupal 7, it is doable, but not easy. There are a few articles out there that can show you how, but they may be dated. There are two paths, using SimpleTest, and using PHPUnit on it's own.
See:

https://www.lullabot.com/articles/write-unit-tests-for-your-drupal-7-code-part-1
https://www.drupal.org/node/811254
https://tlattimore.com/blog/using-phpunit-with-drupal-7/
https://www.previousnext.com.au/blog/drupal-8-now-phpunit-tests-drupal-7
http://patshaughnessy.net/2008/12/12/writing-your-first-phpunit-test-in-drupal
https://devblog.more-onion.com/content/writing-unit-tests-drupal-7
DrupalUnitTestCase

To be honest, I got going with the articles from 2008 and 2012 respectively. It requires a bootstrap file (that requires and bootstraps Drupal) that you can require in your unit test classes - this allows you to use PHPUnit bare metal.
However, you should really evaluate the tests you are doing. If they truly are unit tests and you're familiar and comfortable with PHPUnit, go for it. But if you can achieve it via SimpleTest, that may be an easier road in Drupal 7. DrupalUnitTestCase is meant for that.
Comment: Can't upvote yet, but much appteciated :-)
Comment: Also, are you saying that it is possible to debug a remote server using proper IDE? Or is it always the local environment that gets debugged?
Comment: I always use remote php interpreter and xdebug via DrupalVM w PHPStorm. So, yes.


How to insert the content of my txt file in a widget with Python 2.7 on visual studio code?

Question: I have to create a program that allows me to read a .txt file that already exists and insert the content of that file in a text widget. Can someone help me ?
from Tkinter import *

fenetre = Tk()
champ_label = Label(fenetre, text="titres incorrectes")
champ_label.pack()
ligne_texte = Text(fenetre)
ligne_texte.pack()
fenetre.mainloop()

This is my text widget
Comment: `open(), read(), close()`
Comment: and `ligne_texte.insert("end", text_from_file)` - see [Text](http://effbot.org/tkinterbook/text.htm)
Answer: Try this:
with open('yourfile', 'r') as myfile:
  yourtext= myfile.read()
ligne_texte.insert(END, yourtext)

If the text is too long, you may have problems displaying the whole text. Maybe you should try a scrollbar in the textbox.
Comment: You seems to lack the basic understanding on how python or tkinter works. I suggest you to go through some tutorials like [effbot](http://effbot.org/tkinterbook/tkinter-hello-tkinter.htm).
Comment: thank you, i just put it in but it tells me : <<>>           what do i do?
Comment: That menas you haven't defined your _ligne_texte_ variable correctly. Have you tried to do _ligne_texte.insert(END, 'sample text')_ right after _ligne_texte = Text(fenetre)_ ?
Comment: i tried but then it tells me: <<>>
Answer: This code here should work:
from Tkinter import *

fenetre = Tk()
champ_label = Label(fenetre, text="titres incorrectes")
champ_label.pack()
ligne_texte = Text(fenetre)
ligne_texte.pack()
ligne_texte.insert(END, open('file.txt', 'r').read())
fenetre.mainloop()

Here is what it brings up:

Hope this helps.


Find the Smith normal form of certain matrix

Question: I need to find all invariant factor of matrix
$\begin{pmatrix} \lambda +1 & 2 & -1 \\ 1 & \lambda & -3 \\ 1 & 1& \lambda-4 \end{pmatrix} = A(\lambda)$
that is, by existence of the Smith Normal Form there exists 3x3 matrices $B, C$ with entries in the
integers such that
$BA(\lambda) C = \text{diag}\{d_1, d_2, d_3\}.$
I must determine $d_1, d_2, d_3$. Applying row-column operations I arrive at the matrix
$\begin{pmatrix} 1 & 0 & 0 \\ 0 & -\lambda^2 -\lambda+2 & 3\lambda +2 \\ 0 & 1-\lambda& \lambda-1 \end{pmatrix}$
at this point I can't find a pivot because the absolute value of the entries which are not $0$ or $1$ in the latter matrix vary according to $\lambda$. This problem is found in Jacobson's Basic Algebra I, chapter 3, section 7, problem 3. The problem suggests the usage of the following theorem:
Let A be an m × n matrix with entries in a
p.i.d. D and suppose the rank of A to be r. For each i ≤ r let Δi
be a g.c.d. of the i-rowed minors of A, then any set of invariant factors for A differ by unit
multipliers from the elements $d_1 = \Delta_1, d_2 = \Delta_2 \Delta_1^{-1}, \dots, d_r = \Delta_r\Delta_{r-1}^{-1}$.
But this theorem wasn't covered in my lectures so I'm not supposed to use it, so I would like help on how to obtain them manually.
Comment: If you take $3$ time $R_3$ from $R_2$ that will give you a $5$ in the $(2,3)$ place; swap columns $C_2$ and $C_3$ and then clear the $(2,3)$ and $(3,20$ entries and you're done.
Answer: $$\begin {pmatrix}1& 1&\lambda-4\\0& \lambda-1&1-\lambda \\0& 1-\lambda &-1-(1+\lambda)(\lambda -4)\end {pmatrix}\to\begin {pmatrix}1& 0& 0\\0& \lambda-1& 1-\lambda \\0& 0& -\lambda-(1+\lambda)(\lambda -4)\end {pmatrix}\to \begin{pmatrix}1&0&0\\0&\lambda-1&0\\0&0&-\lambda-(1+\lambda)(\lambda -4)\end {pmatrix}$$
Finally there's a divisibility issue.   To rectify it, see here.


How to integrate ES6 Dependency Framework

Question: I want to integrate an ES6 Dependency (vtk.js) into a Qooxdoo Application. I don't know how to manage this. Here is an Example to use the vtk.js. So my Question is:

Is it Possible to integrate ES6 Dependencys?
When it is possible, what i have to do?
Answer: The short answer is yes, with some caveats.  Qooxdoo v5 (the current release) does not support ES6 constructs in code, because (a) the generator will not accept that syntax and (b) ES6 requires strict mode and there's a compatibility issue which prevents it working.
You could use Qooxdoo v5 with an ES6 library, provided that you don't want to write ES6 code yourself - strict mode is specified on a per-file basis, and your only restriction is to not enable it on code which the generator compiles (ie your code).
However, Qooxdoo v6 supports ES6 out of the box, provided that you use the new compiler (at github.com/qooxdoo-compiler).  This compiler will allow you to write ES6 code and transpile it on the fly so that you can also achieve platform independence.
Qooxdoo v6 is in beta and available via github.com/qooxdoo - the master branch is very stable and used in production by core team members so is worth consideration.
In v6 you can customise the index.html generation, or use the externalResources key in compile.json (if you're using the compiler) or handle loading yourself via qx.io.DynamicScriptLoader.
Once the javascript is loaded, you then need to create a custom class derived from qx.ui.core.Widget and override these methods:

_createContentElement- override this method to create the DOM element that implements your widget, i.e. this is where you would initialise a VTK instance
_getContentHint() - this returns a map of preferred height & width for the widget; it's job is to tell the Qooxdoo layout engine how big the widget would like to be
renderLayout - this method is called to make the element appear on screen and at a given size and position - in practice, this means that you use this method to modify the dimensions of the DOM element which implements your custom widget

Once you've done that, you will have a custom widget that integrates with Qooxdoo; all that remains is to either expose the internal VTK implementation or build an API to operate VTK through.


Android resizing layout and dynamically position change

Question: I am making a simple game and I have 2 questions:
1. How to set that IamgeButton, ImageView and other elements resize depending on the screen size and resolution?
Samsung Galaxy S4:

Prestigion 9.7 Pro:

2. How can I change the postition of some element through code? I tried with setY but it is not supported is lower APIs. I tried with this code, but it moves the whole activity content:
ImageView image = (ImageView) findViewById(R.id.imageView1);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)image.getLayoutParams();
params.setMargins(0, 0, 100, 0);
image.setLayoutParams(params);

I am searching for some simple function like "margin" in CSS that is supported in 2.2 and higher APIs.
Thanks in advance!
Comment: you need to use string.xml for various devices
Comment: How can I use string.xml for that? I used strings.xml to set strings like this: @string/app_name
Comment: string.xml is in no way helpful for solving this issue.
Comment: im sorry i mean dimensions.xml @user2627936
Comment: Thank you, but can you explain it a bit further?
Answer: It seems like you already use a RelativeLayout as your view root.
Now, just add the following to each of your ImageViews in your XML:
android:layout_alignParentRight="true"

This will make sure that your ImageViews are always displayed at the rightmost position.
Add an appropriate margin if you want a gap between the bounds of the screen and your ImageView, e.g.:
android:layout_marginRight="10dp"

If you want to compensate for the vertical position change as well, you could add a LinearLayout, put all your ImageViews into that LinearLayout, set the same weight value for each ImageView and add the two lines above to the LinearLayout.
For making sure that all ImageViews have the same size on any screen density, you will have to create your images in different sizes and put them in the corresponding drawable folders (drawable-mdpi, drawable-hdpi,...)
Images for hdpi devices will have to have 1.5x the size of the mdpi image to be displayed the same size, the factor for xhdpi is 2 and the factor for ldpi is 0.75. (The factor for mdpi is 1)
Moreover, you can create different layouts for different screen sizes or densities. This will provide the needed information:
http://developer.android.com/guide/practices/screens_support.html
Comment: Thank you very much! I will try this and tell if there are any problems.
Comment: im sorry i mean dimensions.xml @FD_


Motifs in melody writing

Question: I read in many books/teachings etc. that the first step for creating a melody is to come up with a motif, and use that for further development. Are all melodies created like that? I hear melodies that I like which have recognizable motifs, and others that don't (or their motifs are somewhat hidden).
The motifs I tend to write, are not anything special. Since they should be small (according to the resources), I can't seem to come up with something interesting with 2-5 notes. So I am not sure if I should spend time developing these somewhat random, boring things!
Lately I read (only the melody chapter) of "Music Composition for Dummies". It seems to separate motif based melodies and phrase based ones.

Often a composer's entire body of work belies a tendency towards
  melodic long-windedness — using long, elaborately developed phrases —
  whereas other composers are more at home with shorter, choppier
  motifs.

So, the choice to use or not use motifs, is a matter of choice or style rather than a kind of 'prerequisite' for all melody?
Comment: Motifs are much more common in improvization (and film scores) than in song melodies, though they do occur there. Motifs were very common in Baroque and Classical times, though.
Comment: It almost seems like the author you've quoted has a prejudiced view in favor of the short motif.
Answer: Sol Sol Sol Me....
Fa Fa Fa Re....
Those four notes are exceedingly boring. But just have a listen to Beethoven's 5th symphony! The first movement is built almost entirely off of this motif, and it is far from boring. As a matter of fact, this motif comes back throughout the entire symphony (the third movement's "Duh duh duh duh, duh duh duh duh, duh duh duh duh, yah da da da," comes to mind).
It's gorgeous.

So I am not sure if I should spend time developing these somewhat random, boring things!

Why not? Part of the brilliance of motifs is starting with something fairly simple, and developing it in a beautiful new way, so that you recognize them later on almost like actors you've seen in a previous movie in a new role.
However there are countless beautiful melodies that are written seemingly out of a moment of sheer brilliance and inspiration, and those can also be gorgeous. Very simply, it depends on what you want to achieve.
The second movement of Beethoven's 5th symphony starts with a beautiful, flowing melody that is probably my favorite in the whole symphony. While you can see some patterns in it, it is far from the very motif-y method employed in the first movement.
A master of both was Brahms, who in my opinion wrote some of the most beautiful melodies in history. His first symphony is a study in pretty melodies. The famous melody in his last movement (Sol Do, Ti Do La, Sol) is in sharp contrast to the trio in his third movement (Which is some of the most brilliant development of a motif that I've ever heard, it's lovely, listen to it now)
Neither technique is better or worse. From what you quoted of the For Dummies book, it sounds like the author doesn't disagree. At the end of the day, it depends on what you want to achieve.
Comment: I edited the comment, with more confusion!
Comment: Re- Beethoven's fifth. Me isn't there. It's me bemol. Wouldn't be minor with me.
Comment: @Tim I'm no solfége expert -- I just typed what I heard there -- but I've never heard of me bemol. Isn't "Me" a minor third away from "Do"?
Comment: @Tim is it also possible that Mi and Me are getting confused?
Comment: It is more than possible! It's what's happened. I apologise. **Mi** is the major 3rd, and **Me** or **Ma** is the minor 3rd. Trouble for *me* is that whilst they sound the same (while spoken, not sung!) they actually mean different notes. Something else learned. It's not even intuitive - me/ma= m3, mi= M3...Thanks!  And bemol is flat.  Playing with a French band, I get asked to play 'si bemol' for tuning (Bb). Comes over as 'C bemol', which would be nonsense!
Comment: @Tim No worries! Appreciate the discussion.
Comment: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/80460/discussion-between-general-nuisance-and-tim).
Answer: The first thing you must internalize is there are no rules! You will notice this is widely said in this website. So, answering you last question, it is totally a matter of choice or style. Melodies can be created in various ways, and I'm sure most of the times not by applying any formulas. I think you should interpret those books and teachings as guidance for you to come up with your first melodies, not as rules, nor prerequisites.
For beginners, or people with no intrinsic talent (like you and me), it is very hard to compose a melody from scratch. Therefore, those tips can be very useful. Though, I believe most great composers just do it naturally, without following any steps.
About the motifs you write: one motif alone will never be interesting, but what you will do with them. And maybe you don't even need to develop a random motif first. You can come up with a melody, identify a motif in it, and use it to develop the next parts, perhaps.
So, there are no rules nor prerequisites, it's always a matter of choice. You can follow some advice as a starting point, but eventually you should have your own style and "steps" for composing melodies.
Answer: Not to belabor the point but...
There are no rules,
and...
You don't have to do anything.
Having said that, the motif approach can be very powerful.  The point is that complex ideas are built from simple ideas repeated.  Repetition is a common theme in music, art, dance, comedy, architecture, etc.  It can be compared to a fractal, a large and complex "thing" that seems to have a pattern and yet is covered in complexity in all directions.  Upon closer examination the wild intricacies are a repeated common patter that is present in the larger grand design.
By its nature music is cyclic (at least western music) so any method you use to develop melodies would likely result in a repeated 'motif'.  If you are not pleased with your own 2-5 note ides just give it time.  Some of the greatest and most memorable pieces have simple motifs like this.  The motif has to be moved through the various positions within the key to create movement.  One of the most common in classical and modern music is to take a pattern on I (the tonic) and repeat it on the IV (sub-dominant), then back to I and etc, etc.  Another embellishment on the 2 note theme is phrasing and placement in time.  A couple examples from Jazz are All Blues by Miles Davis and Groovin High by Dizzy.  The opening riff in GH is 2 notes repeated over 2 bars.  Very simple.  This motif is repeated then moved to another chord.  Give that a try with your ideas before throwing in the towel.
There is nothing that says you need to follow this paradigm.  In developing solo ideas in Jazz the motif approach is often used to develop a vocabulary of licks that will mature and evolve over time.  You may be surprised at how much mileage you can get out of one lick if you are willing to explore many possible embellishments of that lick.  And when you start transcribing other music you may realize that there is underlying simplicity in what seems to be an intricate and complex musical adventure.  But if you are composing a piece for a band or orchestra you may be inspired by a rhythm, or you may be trying to create a feeling, etc.  Inspiration comes how it comes, no reason to insist on a 2-5 note theme.
As for "being small", there are musicians that create 27 note (and beyond) motifs (that is a non repeating musical line that never seems to end, but does and repeats).
Answer: You don't HAVE to do anything.  But if we're thinking 'melody', it's very likely there will be repetitions, inversions, modifications etc. of some melodic element. You could almost say it's what makes a series of notes BE a melody.
There are other ways to make a song hang together. But I can't think of any that don't involve repetition/modification of SOMETHING, whether a rhythm, chord sequence or something else.   Otherwise how does any particular bar of music belong in THAT song, not some other one?
Answer: Motif and phrase-based melodies will have different qualities, so you need to consider how you want it performed. A phrase-based melody will, by nature, have a more cantabile quality to it, but it is impossible to play the motif from Beethoven's 5th cantabile without it sounding like a silly caricature.
When choosing how to approach writing your piece, you need to think first of what you are trying to communicate and what the overall mood will be. Use these aspects of your ideas to determine which type of melody is best to use.  If you want something that has a very percussive quality to it, the motif will work better because the short groupings of notes can be separated, creating more accent. For slow, lush pieces, phrases often work better, though motifs can be intelligently developed to create a longer phrase with the same result.
Tempo, rhythm, and articulation are part of the process, too. In my own mind, melody, tempo, rhythm, and articulation are all part of one unit that comes together at the same time as I think about what I am trying to say with my music.

Motifs in melody writing


Como criar aplicativos Android em PC fraco?

Question: Eu tenho um notebook com um processador de 1,3Ghz e 4 GB de RAM.
Ele é bom, porém sempre que tento criar um aplicativo para Android me deparo com lag, lentidão, travamentos, etc...
Eu tenho no meu notebook o Android Studio e o Eclipse Android Neon.
Tem alguma forma de criar um aplicativo Android com uma IDE mais leve, e que tenha um criador de layout das activities bem levinho?
Assim eu poderia começar a estudar mais o Android, esse é meu único obstáculo.
Comment: Você deveria analisar o por quê de estar com essa lentidão, se é CPU, RAM, disco, ou software mesmo. De qualquer forma, vale notar que IDEs são tradicionalmente muito mais pesadas e violam o princípio "Do One Thing and Do It Well", fazendo com que muitos prefiram usar editores de texto para programar. Dê uma olhada no [eclim (vim + funcionalidades do eclipse)](http://eclim.org/) e sublimetext
Comment: obrigado amigo, mas eu sempre rodei eclipse de boa, mas só essas ide de android que trava mesmo
Comment: @SampaioLeal Seu problema muito provavelmente é RAM e não CPU. Quanto de RAM você tem? Ir para um sistema operacional mais leve (caso você use Windows) também ajuda.
Comment: @PabloAlmeida 4Gb cara, mas to com muitos problemas aqui mano, Internet, Plugins desatualizados, e o Android Studio sumiu, eu ein, deu ate erro de 64 bits no executavel! dentro da pasta bin do Studio
Comment: Mesmo minha máquina i5 tinha problemas em rodar o Android Studio com 4 GB de RAM, e mesmo no Linux. Te recomendo no mínimo 6 GB de RAM e, de preferência, 8 GB se quer trabalhar com Android. Processador não faz tanta diferença assim ao ponto de ser um problema.
Comment: vlw, mas acho que vo é desistir affs, meu eclipse cheio de bugs em relação ao Android,
Comment: @SampaioLeal Mas por que você tá usando Eclipse?
Comment: Porque o Android Studio (o executável) sumiu, e ele travava muito, principalmente na hora da edição de layout, na hora de abrir outros arquivos, quase tudo clicável travava!
Comment: @SampaioLeal Coloque mais 2 ou 4 GB de RAM e tente de novo com o Android Studio (baixe de novo, se sumiu). O Eclipse não tem mais suporte pra desenvolvimento Android. Não faz sentido considerá-lo.
Comment: Bom, eu uso notebook ASUS, e nem sei se daria muito certo!
Comment: O meu é ASUS também. Coloquei mais 4 GB de RAM nele e tá muito bem.
Comment: Como fizestes isso?
Answer: Experimente o IntelliJ IDEA, ele conta com um editor de layout também: https://www.jetbrains.com/help/idea/2016.2/designer-tool-window.html
Comment: muito obrigado amigão, acho que este é o que mais se encaixa com meu note, obrigado mesmo, já faço o download e começo a programar hehe
Comment: uma mini-dúvida, qual a melhor opção para download?
Comment: Se usar o Intellij no ubuntu fica bem mais leve do que no windows. Você pode usar a versão Community que é free..
Comment: A Ultimate é paga e custa tipo 300 dólares (mas tem trial de 30 dias), a Community é de graça. Eu baixaria a Ultimate pra sentir o gostinho, no entanto como você tá preocupado com desempenho, a Community pode ser melhor porque tem menos recursos – logo é mais leve.
Comment: @rodorgas para android, não tem diferença entre a versão Community e Ultimate, a Ultimate tem mais recursos para JAVA EE mesmo, o Android Studio é baseado na versão Community..
Answer: Você pode tentar usar o IntelXDK, ele é bem mais leve...
Comment: mas ele tem o editor de layout?
Comment: tipo, quando eu tento rodar o app trava tudo aki
Comment: sim, ele é uma alternativa ao Android Studio e ao Eclipse, porem ele não trabalha com java... só com HTML 5, CSS e javaScript
Comment: huuum, me parece bom, porem, estou usando a net do vizinho, acho que vou fazer umas gambiarras e fazer esse android studio rodar


Responsividade em iframes

Question: Atualmente estou usando esse código para definir o height de um iframe:
Iframe:
meutarget<" frameborder="0" scrolling="no" onload="resizeIframe(this)">

Script:

Responsividade em iframes


2-secant varieties

Question: Suppose we have $X\subset\mathbb{P}^2$ an irreducible variety, and consider the 2-secant variety $\sigma_2(X)$. In a lecture I read that if  X is a curve, and not a line, then $\sigma_2(X)=\mathbb{P}^2$, but I really can't understand why (I just started studying secant varieties and this is considered an easy example). Any hint or suggestion would be helpful!
Answer: If $P\in \mathbb P^2$ is an arbitrary point, any line $L$ through $P$ that is not tangent to $X$ and doesn't go through a singularity of $X$ will cut $X$ in $d$ distinct points:  $X\cap L=\{Q_1,\cdots,Q_d\}$.
If $X$ is not a line, $d\geq 2$ so that the  the secant  line $\overline {Q_1Q_2}$ is equal to $L$.
Thus every point $P$ is indeed on a secant of $X$, namely $\overline {Q_1Q_2}=L$, and this means that the secant variety of $X$ is indeed $\mathbb P^2$.

2-secant varieties


How to make Jest mocked function toHaveBeenCalledTimes has a fresh count for each test suite?

Question: When I assert the number of time the mocked function been called the imported mocked function always return the combined number of invocations.
For example, the first test suite has a function called the mocked function import { get } from 'axios' once and the expected toHaveBeenCalledTimes is 1. However, the second test suite, the function called get again and toHaveBeenCalledTimes is 2 instead of 1.
How to make the mocked function toHaveBeenCalledTimes return a refresh count for each test suit?
describe('fetchAData', () => {
    it('should return the right A data response', (done) => {
        const sampleResponse = { data: dataASample };

        get.mockImplementationOnce(() => {
            return Promise.resolve(sampleResponse);
        });

        fetchAData().then(() => {
            expect(get).toHaveBeenCalledTimes(1);

            done();
        });
    });
});

describe('fetchBData', () => {
    it('should return the right B data response', (done) => {
        const sampleResponse = { data: dataBSample };

        get.mockImplementationOnce(() => {
            return Promise.resolve(sampleResponse);
        });

        fetchBData().then(() => {
            expect(get).toHaveBeenCalledTimes(1); // -> Return `2`
            done();
        });
    });
});

Answer: mockFn.mockReset() just did the trick, https://jestjs.io/docs/en/mock-function-api#mockfnmockreset

Does everything that mockFn.mockClear() does, and also removes any mocked return values or implementations.

beforeEach(() => {
    get.mockReset();
});

Comment: Just in case anyone needs, `jest.resetAllMocks()` does the same for all mock functions.


std::set::operator<(const std::set&) is not using C() but std::less()

Question: cannot delete my own question, so overwrite it instead...
Comment: @MattMcNabb Well, the library is not doing it because the standard says it must not. C++11 [container.requirements.general]p12 defines `a < b` as `lexicographical_compare(a.begin(), a.end(), b.begin(), b.end())`. Of course, why the standard says it must not is a good question. I see no reason for that either.
Comment: Is this something you're seeing empirically, or is this in the spec?
Comment: This does seem kind of weird
Comment: @templatetypedef it's described here, http://en.cppreference.com/w/cpp/container/set/operator_cmp
Comment: @MattMcNabb I'm on that page, but I don't see any specific reference to `std::less` there.
Comment: I see the behaviour described in this question with GCC 4.9, and that does seem to match the spec.
Comment: @templatetypedef It's not actually using `std::less`, but `std::lexicographical_compare` -- still, that's not the specified comparer.
Comment: @hvd Can't `std::lexicographical_compare` take in a comparator?
Comment: @templatetypedef It can, but then `operator<` needs to pass on that comparator, and it doesn't seem to be doing so.
Comment: @hvd I can't think of any reason why it should not pass on the comparator
Comment: @hvd: While I write my answer and tripple-check that I didn't overlook something obvious, you answer in a comment? ;-)
Comment: @Deduplicator Heh, I didn't think it really answered the question unless it also included why the standard says what it does, that's why I only posted it as a comment. :) But perhaps I shouldn't have, there's not really any more that we can know.
Comment: @hvd: My guess is writer's cramp. Or they ran out of paper.
Answer: It's not actually a bug in the implementaton, though it is arguably one in the standard:

23.2.1 General container requirements [container.requirements.general]
  13 Table 98 lists operations that are provided for some types of containers but not others. Those containers for which the listed operations are provided shall implement the semantics described in Table 98 unless otherwise stated.

The table contains:

a < b
  convertible to bool
lexicographical_compare(a.begin(),a.end(),b.begin(),b.end())
  pre: < is defined for values of T. < is a total ordering relationship.
  linear

While later sections specify that std::set provides comparison-operators, it unfortunately does not change the definition from the one given above.
As an aside, std::lexicographical_compare is not actually using std::less, but using < directly. Not that that is in any way significant.


Is it possible to make a graph eulerian by adding exactly one node?

Question:
Let $G=(V,E)$ denote a connected graph with $|V|\geq 2$. Is it possible to add a new node $v$ with corresponding edges $e_k=\{v,w\}$ with $w\in V$(*1) such that $(V\cup\{v\},E^\prime)$ contains an eulerian cycle where $E^\prime=E\cup\left(\bigcup\{e_k\}\right)$? Prove if possible; otherwise, show a counterexample.
(*1) It is not mandatory to connect the new node $v$ to every other node. One is allowed to omit some of them.

Thoughts. Basically I think it is possible, however I don't know exactly how to argument. I was thinking about comparing the degrees of all nodes and when adding new edges connecting the new node to the old graph to argument when degrees get even/odd to show, that in the end it is possible that all nodes will have even degree, no matter which graph we had at the beginning. This is the result I got when adding one edge and inspecting that there can't be a circle, and obviously the degree of the new node is 1. That way I would have to add an even number of edges to achieve what has to be done.
Question. Can anyone give me some hints on how to start and what exactly to prove?
Comment: How many vertices of odd degree can a graph have? [Handshaking lemma](http://en.wikipedia.org/wiki/Handshaking_lemma)
Comment: This lemma and Michaels answer helped me out!
Answer: Use the property: A connected graph has an Eulerian path if and only if it has at most two vertices with odd degree.
Then look at the number of odd degree vertices in $G$, and figure out the correct edges to use to make $(V \cup \{v\},E^\prime)$ have at most two vertices with odd degree.
Edit: If you want an Euler cycle, then you must make $(V \cup \{v\},E^\prime)$ have no vertices of odd degree. We'd then want to connect the new vertex to every odd degree vertex in $G$ and then argue that the new vertex has even degree.
Comment: This statement should also work for Eulerian cycles if you use the parity argument for vertices of odd degree. See Martin Sleziak's comment.
Comment: I know that a connected graph has an Eulerian path iff all vertices have even degree. I even proved that yesterday, isn't that contradicting with your mentioned property?
Comment: It has an Eulerian cycle iff every vertex has even degree. Paths are less restrictive.
Comment: I am sorry, then I have translated it wrong. I have to work with a cycle - editing it now!
Comment: The handshaking lemma and your edit gave me a good clue to solve this. Thanks!


How do I format a date value for a 3-column date drop-down widget?

Question: I would like to pass a date in the format 2013-04-23 00:00:00 as a #default_value into a form builder function:
$form['date'] = array(
    '#title' => t('Date'),
    '#type' => 'date',
    '#default_value' => $my-array['date'],
);

...but the form renders dates in a three column drop-down widget (which I want to keep). How do I reformat my date and/or form builder function so that my three drop-downs display 23 Apr 2013? At present, they display 02 Feb 1900.
Thanks
Solution
See @tostinni's answer for half of the soluion. This is the second half:
$timestamp = strtotime($my-array['date']);
$day = date('d', $timestamp);
$month = date('n', $timestamp);
$year =  date('Y', $timestamp);

Answer: The Form API documentation will help you figure this out, you'll have to pass an array with the year, month and day keys like this:
$form['date'] = array(
    '#title' => t('Date'),
    '#type' => 'date',
    '#default_value' => array('year' => 2013, 'month' => 4, 'day' => 23),
);


Does weighted MAPE (wMAPE) provide an accurate estimate of error?

Question: I'm trying to use wMAPE to calculate demand standard deviation for future forecasts, however, the wMAPE that we are using is derived from 13 buckets of actuals over a period of 52 buckets of time. If there are 13 weeks of actuals (can be continuous or intermittent) over a horizon of 52 weeks, we calculate the wMAPE based on those actuals. I'm trying to determine if this is the right way of estimating error as the intermittency (demand volatility) seems to be ignored.
I tried finding academic texts on weighted MAPE but I'm not finding anything. Any help will be appreciated.
Comment: What do you mean by "calculating demand standard deviation for future forecasts", and how would this be connected to the wMAPE? Are you trying to forecast volatility? (I assume not, but I don't quite see what else you could mean.)
Comment: Trying to calculate demand standard deviation for gamma distribution by using the value 1.25*wMAPE*mean forecast
Comment: @NGSK why would you assume  1.25*wMAPE*mean tells you anything about standard deviation of the data? wMAPE is an error metric, it can be arbitrarily high or low depending on the performance of the model, regardless of the data.
Answer: There is no single "error" that we can estimate using an error metric. An error is whatever we measure. We can definitely measure the error using the MAPE (which may be undefined), the wMAPE, the MSE and so forth. All these errors will be different, and more importantly, each error will be minimized by a different forecast. So the question is one of choosing an error measure that elicits the forecast we want. (Saying "we just want a good forecast" begs the question, because what a "good" forecast is depends on the error measure.)
You may be interested in What are the shortcomings of the Mean Absolute Percentage Error (MAPE)? Although it's about the plain vanilla MAPE, it should be enlightening about the wMAPE.
Since the wMAPE is just the MAE divided by the mean (assuming you use the same definition as Kolassa & Schütz, 2007), it elicits the same forecast as minimizing the MAE - that is, the conditional median. The difference in "optimal" forecasts for different error measures are illustrated here for lognormally distributed data and here for gamma distributed data.
A median forecast may or may not be what you want. I personally have never seen a business process that would be better served by a median forecast than by an expectation or high quantile forecast.
Note in particular that for intermittent demands, if you can't reliably forecast when demand occurs, your conditional median may well be zero, so the wMAPE- or MAE-minimal forecast may well be a flat zero, which is a bit of a problem for people working on intermittent demand forecasting and using the MAE (Kolassa, 2016).


How to recognise polyrhythm in a piece

Question: I came across a part I found really interesting and quite challenging to my piano level in the piece Arabesque No.1 in E major by Claude Debussy, where both hands seems to not follow the same time pattern.  I realized while practicing that it could be an example of polyrhythm, which is a concept I didn't really know, so I started to do some research to prove or not my assumption.  I understands the idea of the concept, but I don't feel able to recognize it in a piece.

My question to you would be, is this part an example of polyrhythm, since to me it looks like triplets over dublets in four beats ?  If not, is there some clues or tips to quickly recognize a polyrhythm part in a piece ?
Thank you very much !
Answer: Yes, you could call this 'two against three' pattern a simple example of Polyrhythm.  Not sure why it's so important to label it?  More importantly, have you a strategy for PLAYING it?
The count is 1 2-and 3.
The 3-group hits 1 2 3.
The 2-group hits One and.
Practice it tapping two hands on the table before trying to play it.
Comment: Thanks, I know labeling it might not be important, but I've been working on it for a while and was wondering why this particular part took me more time than others.   I also love to understand what I'm playing and why it has been written this way, so I'm kind of a fan of labels haha !  Is there clues to quickly identifies polyrhythms parts in sheets ?
Answer: A two-against-three is sometimes called a "hemiola." (Next time you see it in a trivia game, you'll know.)
You can always work out polyrhythms by taking the least common multiple of the two voices, and working out where the notes hit. So, with two against three, the LCM is six. Count in sixes. Both voices hit on one, the three hits on 3 and 5, and the two hits on 4. So, the two hits right between the second and third three. You can tap it out like this (keep saying "pa" under your breath as you go) BOTH pa R L R pa BOTH pa R L R pa. Then you can try reversing your hands.
For three against four, you do the same thing with 12. The four hits every third 12th, and the three hits every fourth 12th. You can tap it out like this: BOTH pa pa L R pa L pa R L  pa pa.
Chopin's Fantasie Impromptu is a well-known piece with three against four through most of the piece:

And here's a part of Debussy's L'Île Joyeuse that has some tougher polyrhythms: five against threes with a few five against sixes on the last beat, and some five against twos. I'll leave the arithmetic to you if you're interested. :)

How to recognise polyrhythm in a piece


Parsing Rest query output

Question: I am trying to parse the output of a rest api query of the form
$response = Invoke-RestMethod -Uri $uri -Headers $headers
$response.name | Select-String -Pattern ^role

returns an output similar to this below (elements separated by ::)
role::servicing2
role::collaboration::lei
role::commercial_lines::npds
role::nvp::windows::ucce_gold
role::oracle::linux::oracle_oid
role::splunk::splunk_enterprise::add_on

I need to read this output line by line and parse.
If there are just 2 elements eg. role::servicing2 ignore the line
If there are 3 elements, ignore the first element "role", prepend puppet_ to the second element and it becomes the project, the third element is the role (OS is unknown)
If there are 4 or more elements, ignore the first element "role", prepend puppet_ to the second element and it becomes the project, if the third element is "windows" or "linux" that is the OS, else OS is "unknown", and the last element \:\:'(\w+)'$ is the role.

Need an output in the form of an array or table or list in this format
(Don't necessarily need header)
Project         OS      Role

puppet_collaboration    unknown     lei
puppet_commercial_lines unknown     npds
puppet_nvp      windows     ucce_gold
puppet_oracle       linux       oracle_oid
puppet_splunk       unknown     add_on

I have tried various regex expressions. Couldn't figure out the logic of walking this line by line and parsing appropriately into a list or array.
Comment: "I have tried various regex expressions. Couldn't figure out the logic of walking this line by line and parsing appropriately into a list or array." - can you share what you tried so far, and how it failed? :)
Comment: I was trying to parse along the lines of $response.name | Select-String -Pattern ^role\:\:'(\w+)'\:\:'(\w+)'$ | foreach {$_.Matches.Groups[2].Value}. Not sure how to add all the logic above.
Answer: I think below code should do what you want:
$roles = @'
role::servicing2
role::collaboration::lei
role::commercial_lines::npds
role::nvp::windows::ucce_gold
role::oracle::linux::oracle_oid
role::splunk::splunk_enterprise::add_on
'@ -split '\r?\n'

$result = $roles | ForEach-Object {
    $parts = $_ -split '::'
    switch ($parts.Count) {
        2 { continue }  # ignore this line
        3 {
            [PsCustomObject]@{
                'Project' = 'puppet_{0}' -f $parts[1]
                'OS'      = 'unknown'
                'Role'    = $parts[2]
            }
        }
        default {
            [PsCustomObject]@{
                'Project' = 'puppet_{0}' -f $parts[1]
                'OS'      = if ('windows', 'linux' -contains $parts[2]) {$parts[2]} else {'unknown'}
                'Role'    = $parts[-1]
            }
        }
    }
}

# output on screen
$result

# output to CSV file
$result | Export-Csv -Path 'D:\roles.csv' -NoTypeInformation

For testing I have put the result of your $response.name | Select-String -Pattern ^role in a here-string.
Output:

Project                 OS      Role
-------                 --      ----
puppet_collaboration    unknown lei
puppet_commercial_lines unknown npds
puppet_nvp              windows ucce_gold
puppet_oracle           linux   oracle_oid
puppet_splunk           unknown add_on

Comment: This worked great. Thank you very much. I learned a lot from it.

Parsing Rest query output


How can I configure CKEditor to show content in 'plain text editor'?

Question: I would like to configure my CKEditor to show content that I edit in plain text editor by default as I have some widgets on my site (e.g. Twitter) that get removed by CKEditor's rendering to rich text - how can I avoid that?
Thanks!
Answer: Assuming Drupal 7 - goto admin/config/content/formats and change the order of the text formats, placing Plain Text at the top of the list. This will default the edit format, however content that is already created would default to whatever format was used to create it in the first place.
This will however filter quite restrictively the output. If you mean to include a text format that does not perform any formatting at all, on the same page, you can 'Add Text format', label it unaltered or whatever title you prefer, set roles to administrator (very high security risk with giving this format to untrusted persons), and leave everything else blank. This will create an unaltered format which allows things like direct html, javacript and php writing in blocks, etc.


Why gcloud doesn't show default forwarding-rules of http?

Question: In Google Compute Engine, after I created a instance with http option checked and can pass through web.
But its forwarding rule isn't shown with "gcloud compute forwarding-rules" in command or "Load Balancing" in console.
Is HTTP forwarding rule configured as any special rule?
or anything wrong in my understandings?
Comment: I may be wrong. No forwarding rules are needed. With only a firewall rule it works. `gcloud compute firewall-rules list`
Answer: The HTTP option that you have checked when creating the instance is mapped to a firewall rule in GCE network firewall, which is for incoming traffic on port 80. As such, this will allow incoming HTTP traffic to your VM instance. To learn more about firewall rules you can go through this link.
The forwarding rules are used for load balancing and protocol forwarding purposes. If you have not configured a load balancer or protocol forwarding the gcloud compute forwarding-rules will not output anything. You can refer to this link for more information on forwarding rule.
Comment: OK. I was wrong to confuse the forwarding with the firewall. Your answer is backing my understanding. Thanks.


Join the two dataframe by conditions

Question: I have a datasets collected by alternative auto-time setting.
This is the example format.
file = data.table(ID = c(1:19), time = as.hms("6:01:00 ", "6:03:00 ",
                                                  "6:05:00 ", "6:08:00 ",
                                                  "6:10:00 ", "6:12:00 ",
                                                  "6:15:00 ", "6:17:00 ",
                                                  "6:19:00 ", "6:22:00 ",
                                                  "6:24:00 ", "6:26:00 ",
                                                  "6:29:00 "),
                  Turn = c("A", "A", "B", "B", "C", "C", "A", "A", "A", "B",
                           "B", "C", "C"),
                  Value = c("16.00", "18.00", "17.00", "19.00", "21.00",
                            "26.00", "25.60", "27.34", "29.09", "30.83",
                            "32.57", "34.31", "36.06"))

From this dataset, I separated it into three dataframes for each turn by using the following code:
Data_A <- file[file$Turn %in% c("A"), ]
Data_B <- file[file$Turn %in% c("B"), ]
Data_C <- file[file$Turn %in% c("C"), ]

Data_A
ID  Time    Turn    Value
1   6:01:00 A   16.00
2   6:03:00 A   18.00
7   6:15:00 A   25.60
8   6:17:00 A   27.34
9   6:19:00 A   29.09

Data_C
ID  Time    Turn    Value
5   6:10:00 C   21.00
6   6:12:00 C   26.00
12  6:26:00 C   34.31
13  6:29:00 C   36.06

I want to combine Data_A and Data_C by the nearest time as follow:
ID  Time    Turn    Value Time C Turn C Value C
1   6:01:00 A   16.00  6:10:00  C   21.00
2   6:03:00 A   18.00  6:12:00  C   26.00
7   6:15:00 A   25.60  6:26:00  C   34.31
8   6:17:00 A   27.34  6:29:00  C   36.06
9   6:19:00 A   29.09

As you see, there is an extra A in Data_A. I will exclude it. There are so many such irregular data in the time series dataset. Can anyone help me how to code for this result?
Thanks!
Comment: So there should be only one matched Time of Data_C in the join?
Comment: Why does `ID` have 19  values and all other columns have only 13?
Comment: which package does `as.hms` come from?
Answer: In order to combine two frames like this, you need to ensure they both have the same number of rows. This means that (for instance) Data_C will need to have a row of NA values appended. This is fairly straight-forward:
maxrows <- max(nrow(Data_A), nrow(Data_B), nrow(Data_C))
Data_C <- do.call(rbind, c(list(Data_C),
                           replicate(maxrows - nrow(Data_C),
                                     Data_C[1,][NA,],
                                     simplify = FALSE)))
names(Data_C) <- paste0(names(Data_C), "_C")
cbind(Data_A, Data_C)
#       ID     time   Turn  Value  ID_C   time_C Turn_C Value_C
#    <int>    <hms> <char> <char> <int>    <hms> <char>  <char>
# 1:     1 06:01:00      A  16.00     5 06:01:00      C   21.00
# 2:     2 06:01:00      A  18.00     6 06:01:00      C   26.00
# 3:     7 06:01:00      A  25.60    12 06:01:00      C   34.31
# 4:     8 06:01:00      A  27.34    13 06:01:00      C   36.06
# 5:     9 06:01:00      A  29.09    NA       NA   <NA>    <NA>

The use of Data_C[1,][NA,] is meant to get a single row where each value is the appropriate form of NA (there are at least six distinct classes of NA).

Side thoughts:

It's generally better to keep the data all in one frame instead of multiple frames, that way grouping operations are defined in one place and can be done easily using dplyr::group_by, base::ave (and other grouping functions), and data.table's by= argument.

Even if you do split a frame into multiple frames, it is often better to keep them as a list of frames, since what you often do to one is easily done to all using lapply. One could generate this easily with spl <- split(file, file$Turn). From there, reference sdl$C instead of your Data_C.

This might be done more efficiently on file as a pivot.
library(dplyr)
library(tidyr)
file %>%
  group_by(Turn) %>%
  mutate(rn = row_number()) %>%
  ungroup() %>%
  pivot_wider("rn", names_from = "Turn", values_from = c("ID", "time", "Value")) %>%
  select(-rn)
# # A tibble: 5 × 9
#    ID_A  ID_B  ID_C time_A time_B time_C Value_A Value_B Value_C
#   <int> <int> <int> <time> <time> <time> <chr>   <chr>   <chr>
# 1     1     3     5 06:01  06:01  06:01  16.00   17.00   21.00
# 2     2     4     6 06:01  06:01  06:01  18.00   19.00   26.00
# 3     7    10    12 06:01  06:01  06:01  25.60   30.83   34.31
# 4     8    11    13 06:01  06:01  06:01  27.34   32.57   36.06
# 5     9    NA    NA 06:01     NA     NA  29.09   NA      NA

or with data.table:
file[, rn := seq_len(.N), by = Turn]
dcast(file, rn ~ Turn, value.var = c("ID", "time", "Value"))[, rn := NULL][]
#     ID_A  ID_B  ID_C   time_A   time_B   time_C Value_A Value_B Value_C
#    <int> <int> <int>    <hms>    <hms>    <hms>  <char>  <char>  <char>
# 1:     1     3     5 06:01:00 06:01:00 06:01:00   16.00   17.00   21.00
# 2:     2     4     6 06:01:00 06:01:00 06:01:00   18.00   19.00   26.00
# 3:     7    10    12 06:01:00 06:01:00 06:01:00   25.60   30.83   34.31
# 4:     8    11    13 06:01:00 06:01:00 06:01:00   27.34   32.57   36.06
# 5:     9    NA    NA 06:01:00       NA       NA   29.09    <NA>    <NA>

Ordering of columns should be relatively straight-forward.
Comment: Thanks, r2evans! Your code seems to work for the values, but I wonder why the time changed like this. I want to keep the time as original. Any idea??? Thanks.
Comment: My guess is that the real value is really the same. Tidyverse packages tend to prefer fancy rendering of values (using `pillar`) in custom ways, I suspect it's just a size reduction of what is printed but no change in the numeric value.
Comment: Thanks again, r2evans! I tested the code based on your suggestions.

library(dplyr)
library(tidyr)
file %>%
  group_by(Turn) %>%
  mutate(rn = row_number()) %>%
  ungroup() %>%
  pivot_wider("rn", names_from = "Turn", values_from = c("ID", "time", "Value")) %>%
  select(-rn)

It works to some extent, but the value for ID_A 9 matched the values for the following ID_B and ID_C in the remaining time series.
Again, those values are linked with the ID_A 14, and so on.
Answer: You could use data.table's roll='nearest' join option.
In order to do so, time needs to be converted to numeric:
library(data.table)
library(hms)

file = data.table(ID = c(1:19), time = lapply(c("6:01:00", "6:03:00","6:05:00", "6:08:00 ","6:10:00 ", "6:12:00 ", "6:15:00 ", "6:17:00 ", "6:19:00 ", "6:22:00 ",       "6:24:00 ", "6:26:00 ", "6:29:00 "),as.hms),
                  Turn = c("A", "A", "B", "B", "C", "C", "A", "A", "A", "B",
                           "B", "C", "C"),
                  Value = c("16.00", "18.00", "17.00", "19.00", "21.00",
                            "26.00", "25.60", "27.34", "29.09", "30.83",
                            "32.57", "34.31", "36.06"))

# numeric join field
file[,itime:=as.numeric(time)]

Data_A <- file[Turn %in% c("A"), ]
Data_B <- file[Turn %in% c("B"), ]
Data_C <- file[Turn %in% c("C"), ]

Data_C[Data_A,.(ID = i.ID,
                time = i.time,
                Value = i.Value,
                Turn = i.Turn,
                time_C = x.time,
                Value_C = x.Value,
                Turn_C = x.Turn),on=.(itime),roll='nearest']
#>       ID     time  Value   Turn   time_C Value_C Turn_C
#>    <int>   <list> <char> <char>   <list>  <char> <char>
#> 1:     1 06:01:00  16.00      A 06:10:00   21.00      C
#> 2:     2 06:03:00  18.00      A 06:10:00   21.00      C
#> 3:     7 06:15:00  25.60      A 06:12:00   26.00      C
#> 4:     8 06:17:00  27.34      A 06:12:00   26.00      C
#> 5:     9 06:19:00  29.09      A 06:12:00   26.00      C
#> 6:    14 06:01:00  16.00      A 06:10:00   21.00      C
#> 7:    15 06:03:00  18.00      A 06:10:00   21.00      C

Comment: Thanks, Waldi! I tried your code, but it gave the repeated values of Data_C.  Actually, I don't want to repeat the same values of Data_C. Anyway, thanks for your kindness.
Answer: I would try something in that logic:
First, arrange both dataset by descending order of time, using the arrange() function from the tidyverse packages.
Now that the two datas are arranged the same way,
Join them together according to dataset C using the left_join() function (also from tidyverse).
library(tidyverse)
A = arrange(Data_A, Time)
C = arrange(Data_C, Time)

left_join(A,C)

I tend to confuse left, right or inner join. Please make sure you get your desired result and change to either inner or right (there's also full/anti join, you'll figure out what each does if you play with it. It's basically a venn diagram of datasets).
To use the tidyverse packages use install.packages("tidyverse") if you don't have them installed.
Comment: Thanks, RYann! I tested that code before, but it gave me the undesired result. One value of Data_A joined with several values of Data_C. But I want to keep only one-to-one from Data_A and Data_C. Thanks indeed.

Join the two dataframe by conditions


The sum of compact set with a bounded set is a compact?

Question: Let $X=(X,|\cdot|)$ be a Banach space and let $A,B \subset X$. If $A$ is a compact set and $B$ is bounded set, then $$A+B=\{a+b \; ; \; a \in A \: \text{e}\: b \in B\}$$
is a compact set?
I tried to prove it as follows: let $(x_n)_{n \in \mathbb{N}} \subset A+B$, then
$$x_n=y_n+z_n,\: \forall \; n \in \mathbb{N}, $$
for some, $(y_n)_{n \in \mathbb{N}} \subset A$ and $(z_n)_{n \in \mathbb{N}} \subset B$. Since $A$ is bounded, . Moreover, since $B$ is compact, exist $(z_{n_k})_{k \in \mathbb{N}}$ such that $z_{n_{k}} \longrightarrow z$, for some $z \in X$.
But I do not know what I can conclude with such information.
Is this true or not? If not, is there any additional hypothesis that makes it true?
Comment: Take $A = [0,1]$ and $B = [0,1).$ Is $A+B = [0,2)$ compact?
Comment: $A=\{0\}$ is compact. If $B$ is bounded, is $\{0\}+B$ compact?
Comment: How about taking $B$ to be compact as well?
Comment: If $A,B$ are both compact, then $A+B$ is a continuous image of the compact set $A\times B$.
Comment: If $A$ is nonempty, then it's a necessary condition for $A + B$ to be compact that $B$ is relatively compact. So you can't get much beyond "compact + compact is compact".
Comment: No. Is there any additional chance that makes this true?
Comment: Perhaps it would work if $B$ is also closed. Clearly this works in $\mathbb{R}^n$, but what about in other banach spaces?
Comment: @Sobi I know it's true that sum of compact with compact is compact.
Comment: Under these conditions (or some additional) can we conclude that $A + B$ is relatively compact?
Answer: If $I$ and $J$ are bounded intervals in $\mathbb{R}$, then $I+J$ is also an interval and $\sup (I+J)=\sup(I)+\sup(J)$ and $\inf(I+J)=\inf(I)+\inf(J)$. It follows that $I+J$ is compact if and only if both $I$ and $J$ are compact.
In general it is possible for $A+B$ to be compact even if $A$ and/or $B$ is not compact:
Let $A=\{1/n: n\geq 1\} \cup \{0\}$ and $B=\{-1/n: n\geq 1\}$. Then $A$ is compact, $B$ is not compact, but $A+B$ is compact.
Let $A=\{1/n: n\geq 1\}$ and $B=\{-1/n: n\geq 1\}$ then $A$ is not compact, $B$ is not compact, but $A+B$ is compact.