Is it possible to sell a software to enterprises, then release its source code for free? The title says it all. Out of curiosity and because I didn't find any result when searching about that, I'm asking here if it's technically possible to sell a software to an enterprise, then months later make it open source, or you have a kind of contract that completely disallow you from doing so ?
It depends on what you are selling to the enterprises. You could be selling just a licence to use the program, and retain all the rights on the source code. You could be selling the rights to the source code. For #1, the source code is yours and you can do what it pleases with it1. In fact many programs offer both an open-source licence (which usually forces the user to make its changes to the code publicly available) and a commercial one (which allows the user to keep the modifications of the source code for themselves). For #2, the source code is no longer yours so it is not up to you to decide what to do with it. 1I am assuming no other agreements imposing limits on those; for example that none of your contracts to your customers have a clause forbidding you from making the code available to the public.
Unknown based on what you have posted in your question. But answer lies in the terms under which the source code is made available or licensed. The most common scenario is that such &quot;sample&quot; source code is provided as help to the purchaser of their product and you'll often see things that permit its use in conjunction with the hardware product. You'll also often see disclaimers that say the code is for demonstration purposes only and it not warrantied to do anything at all. But again, you'll need to review the actual language under which the code is provided and then understand and follow its terms and conditions.
You can't patent an algorithm, but I'll assume you are talking about the case where you have patented a machine or process that uses an algorithm, but that adds significantly more, and that the software being distributed implements much of this process. Courts might find an implied licence or promissory estoppel when distributing software under an open source licence that doesn't explicitly exclude patent licencing as part of its terms. It would be prudent to state your patent rights and explicitly exclude a patent licence if you intend to enforce your patent rights. As an example, this software implicates a patent , so they allow "permission to use, copy, modify, and distribute this software and its documentation for educational, research, and non-commercial" purposes. Users that want to use the software commercially need to contact the authors who also happen to be the patent owners, and I assume would negotiate a patent licence at that point.
Germany may be different, however in the United States this would be considered work-for-hire and the employer would be the rightful owner of the source code. Regardless of jurisdiction, and from a more practical point of view, you are better off not having a copy of the source code. Using it as reference or example in the future could easily turn into (unintentional) copyright infringement. If, in the future, you write code you would like to be able to freely keep and reuse in any project, make sure the owner/employer licenses it using something like the BSD, MIT, or ISC license.
To answer the question in your title: Yes, software licenses are copyrighted. They are written works that involve (significant, expert) creative effort to create. The best solution would be for Grammarly to hire a lawyer and say "we want a new EULA. We think this one covers a number of points our current one doesn't". Most legal documents will be copyright for the same reason (there may be a few that are so stereotypical that there is essentially no creative effort in putting them together).
If it's patented then it doesn't matter that you independently came up with it. Most software is not patented, though. Most developers do not even think about patents when writing code. In theory you could spend your time keeping up to date on software patents so that you avoid infringing. But this probably only makes sense for specialists who would want to read the latest patents in their field anyway. All software is protected by literary copyright, though. In this case they will try to prove that you did not independently created it, and did copy it. Whelan v. Jaslow in 1986 ruled that structure, sequence and organization of a computer program were protected by copyright. So you could be liable even if you did not just copy and paste sections of code. But even if you're worried the court would get things wrong and think you copied a program when you never even saw it in the first place, there is really nothing you can do about it.
If the blog author holds the copyright on the ebook, they can distribute the ebook anyway they choose, either via download from Github or elsewhere, or sell it in an online store. They hold the copyright, they alone can decide how to distribute it. If they also sell the ebook in the Microsoft press Store, they may have an agreement with the store to also allow their own free downloads; it's hard to say without knowing the agreement. If there are ebooks on Githb available for viewing or download, the owner of the Github page should hold copyright of the ebook, both 1) for their own protection against copyright infringement, and 2) to not break GitHub's TOS against copright infringement: https://help.github.com/articles/github-terms-of-service/#f-copyright-infringement-and-dmca-policy
There are two common approaches. The first approach is simply to let copyright law apply. Under the default terms, the IT provider has no rights to copy your software. Running software is allowed, of course, and not a problem that you need to deal with vis-a-vis the IT provider. You still can sue them if they copy your software, even in the absence of a contract. That is the chief function of copyright, after all! The second approach is to allow the customer to subcontract third parties to act on behalf of them, while acknowledging that such subcontracting does not dissolve them from any responsibilities towards you. In other words, if the 3rd party would do something unauthorized, you have a claim towards the customer and they have a distinct but related claim towards their IT supplier.