Compression of a video with constant background

Question: (sorry if my english is bad, I can read it but I don't write it quite well...)
I want to compress some videos, which have two particularities:

there is a background that covers ~90% of the area, during the whole video
most of the others elements can be separately described by a picture in move

My videos are like this one, and don't have audio. As you can see, almost everything can be described only by using a fixed background, few small images in move, plus a noise. Moreover, this noise will be almost nul and then an entropic coding would be very efficient. I think it will produce tiny files (< 5 Mo) even if the duration is in hours, a result that is very appreciable since I have actually recorded ~30h of game (actual size is 3 Go).
Is there any way to get new video files, that benefit of these informations? If yes, what are the implication of a such encoding for watching these videos with Windows Media Player, or for usage with ffmpeg?
I searched with Google after anything that can help me, but I don't know which keyword I can use for this, then I didn't found anything usefull :-(
Thanks in advance :-)
PS: another example, the video is accelerated but shows the interesting moves
Answer: x264/5 will automatically allocate fewer bits to static parts. Your size will depend on keyframe frequency (-g N, N is is frames) and overall quality level (-crf X). There are a few other parameters you can tweak, but none will result in a < 5MB output for videos that is hours long.
Comment: No. But that's essentially what the encoder does anyway. It generates motion vectors i.e. these group of pixels move to the right in the next frame. However, the horizon is narrow and won't connect a set of pixels to an earlier occurrence in a frame 20 seconds earlier. For your given content, it may be worth exploring Flash.
Comment: I tried this, and can get slightly better results than my original command line (ffmpeg -i input.avi -vcodec h264 -qscale:v 2 -pix_fmt yuv420p output.mp4). Do you have an idea about the moving elements? Is it possible to indicate to ffmpeg a list of images that will often appear? Like that it can do "for this frame, the 3rd picture appears at position (x, y)" or something like this
Comment: Without much experience with h265, i could imagine h265's advantage to h264 might in this case even bigger than the general (expected) compression advantage, due to macroblock->ctu replacement (of course the encoder always plays a big role; VP9 should be comparable).


How do I revert master branch to a tag in git?

Question: We have branches origin and develop.
The initial state of master was tagged at tag_ABC.
We have few changes made to the develop branch and pushed to origin.
Then we have accidentally merged develop into master and pushed to origin.
Now we would like to revert master to the checkpoint tag_ABC. How can we do that?
Answer: You can do
git checkout master
git reset --hard tag_ABC
git push --force origin master

Please note that this will overwrite existing history in the upstream repo and may cause problems for other developers who have this repo checked out.
As per Luke Wenke's comment, other developers who have got master checked out will have to do the following:
git pull
git reset --hard origin/master

Comment: This way all the branches will be pushed with force. You may want to try `git push --force origin master`
Comment: For reference, to revert to the previous commit, you can do a `git reset --hard HEAD^`
Comment: BTW `git reset --hard HEAD^` can be used multiple times to step back one commit at a time then if it is on remote, `git push --force origin master` can be used.
Comment: Also to reset the master branch of other people's local copies to the earlier version use `git pull` and `git reset --hard origin/master`
Comment: A little advice after this revert, could be tell to the team : pull from master branch!! Thanks!!
Comment: does this actually "revert", as in leave the commit history? I have a feeling you're confusing revert and reset
Comment: @Emobe while "revert" is indeed a git term for "unapplying" a commit, the question seemed more interested in restoring the previous state of the branches, hence this answer.
Comment: A note about this method: When you are using a protected master branch, you can't reset that branch. You have to unprotect the branch first, reset and protect it again.
Answer: This isn't a direct answer to the question but this page comes back when searching for ways to revert a branch's code to a tag release.
Another way is to create a diff between the current state of the branch and the tag you want to revert to and then apply that to the branch. This keeps the version history correct and shows the changes going in then coming back out again.
Assuming your branch is called master and the tag you want to go back to is called 1.1.1
git checkout 1.1.1
git diff master > ~/diff.patch
git checkout master
cat ~/diff.patch | git apply
git commit -am 'Rolled back to version 1.1.1'
git push origin master

Comment: This should be the accepted answer since it keeps the history intact and doesn't cause problems for others who have the repo checked out.
Comment: This seems elegant.  But I tried to revert qa branch to a previous tag and just got patch fail messages.

    $ cat ../diff_qa.patch | git apply

    :55: trailing whitespace.
    :336: trailing whitespace.
    :12692: trailing whitespace.
    :12695: trailing whitespace.
    {{ $tag['rank']+1 }}:
   :12706: trailing whitespace.
    error: patch failed: .env.wholo:1
Comment: This is the correct way to do. It's non-destructive and preserves full history
Comment: I've tried several solutions, but none of the worked. This one worked like a charm. Thanks a lot @John
Comment: This does not work for me. I can run the first 3 commands without any issue, but when I do ``cat ~/diff.patch | git apply``, it tells me ``error: unrecognized input``. Any idea? @NitinBansal perhaps since you commented recently?
Comment: Just a guess but sounds like a problem with your git config and how it produces patch files.  Try https://stackoverflow.com/questions/37347350/all-git-patches-i-create-throw-fatal-unrecognized-input
Comment: I just wonder why this isn't a built-in git command. This is probably the most basic feature you would expect by any VCS
Comment: @nitin-bansal Regarding the point of preserving history: if you merge using pull requests rather than performing them at the command-line, then you will retain the change history in the merged PR - would that be an adequate resolution?  If you don't use PRs, then losing the history could indeed be catastrophic.  Or would PRs make no difference to this at all?


How to Sort Views results based on two fields

Question: I have a view that lists nodes of type Article. Each Article includes a boolean field and a date field. Neither field is required. I want to sort the list of articles so that the first articles are the ones with the boolean field checked and with a date that is in the future (sorted by published date – newest first) followed by all the other articles sorted by published date (newest first) (which includes ones without the boolean checked and ones that have the boolean checked but the date is in the past). The list has a pager showing 5 articles and there are approx 3,000 articles currently.
There is no way to create a sort like this in Views. I can separately create the two views above no problem, but I can't seem to figure out how to merge them into one list. I have tried using a View Attachment to attach a view of the checked and future articles above the other articles but the attachment appears on all pages of the pager. And if there are more that 5 articles in the attachment, then they are the only ones you ever see when paging.
So from what I can see I need to use a views_query_alter hook or maybe a views_data_alter hook to programmatically alter the sort of query but coding it not my forte and I'm a bit lost. I've created mymodule.info.yml and mymodule.views_execution.inc and placed the two of them in a folder in modules->custom. My info file is
type: module
name: 'Views Article Custom Sort'
description: 'Custom Sorting of Articles'
package: 'custom'
core_version_requirement: ^9 || ^10

dependencies:
  - views

My mymodule.views_execution.inc
<?php

use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\query\QueryPluginBase;

function article_custom_sort_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
  if ($view->id() == 'article_list' && $view->current_display == 'block_1') {
    $query->addField(
    NULL,
    'CASE WHEN (COALESCE(field_display_in_sticky_until, 0) >= CURRENT_TIMESTAMP AND COALESCE(field_stick_to_top_of_list, 0) == TRUE)',
    'sticky'
    );
    $query->addOrderBy(
    NULL,
    NULL,
    'ASC',
    'sticky'
    );
  }
}

Firstly, the module is not showing on my Module page, so I can't enable it and I'm fairly sure my code is full of errors. If anyone can help me, I'd really appreciate it.
Thanks
F
P.S. I had thought that maybe an alternative is to have the boolean unchecked if the date field is in the past when cron is run, but I have no idea where to start with coding that one. If I could get that working, then I could simply sort the view by the boolean field followed by published date. Sadly the module Scheduler only publishes and  Unpublishes nodes on cron, it doesn't offer options to alter other fields.
Comment: why is the hook in a file named `mymodule.views_execution.inc`? it should probably be in a file named `mymodule.module`. In hook functions, the HOOK part of the function name needs to be the same as the module filename. eg. your `article_custom_sort_views_query_alter` should be `mymodule_views_query_alter`
Comment: Thanks @2pha. I had previously tried using the .module file type but it didn't work, which is why I tried the .inc file type (I had read somewhere that that was what I needed). Anyway, I've since discovered I had a typo in my file name which once I fixed and also changed filetype to .module, I can now enable the module. However, as I thought, there are errors in my code. I'm getting 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax'. Do you know how I can access field values from each row of the view in my views_query_alter?
Answer: In case anyone comes across this question, I used a different route to solve my problem. Rather than trying to merge two Views into one list, I use the module ECA: Event - Condition - Action to unselect the Boolean Field on Cron, so now I can sort my View by the Boolean Field followed by sorting by Published Date.
ECA is an excellent module by the way. It allows me to execute a View and then perform an action on the Views Results. It's similar to Rules, except it actually works with D9/D10. So I created a View that lists Nodes of type Article that have the Boolean Field selected and have a date in the past in the Custom Date Field. On Cron, the View is executed, and the Boolean Field is unselected and saved in each Node in the Views Result. So after cron, the only Articles that have the Boolean Field selected are the ones with the Custom Date in the future.


.map is not a function in React production

Question: When running my express react app build locally the map function works flawlessly, however whenever I switch to production. I get the error that map is not a function.
Error comes up pointing towards 'let returnlist' line. I have included the index.js and where the error occurs.

import React, { useState, useEffect } from 'react'
import ReactDOM from 'react-dom'
import AddNewPerson from './component/addNew'
import Filter from './component/filter'
import Persons from './component/persons'
import axios from 'axios'

const App = () => {
  const [persons, setPersons] = useState([])
  const [tempPersonList, setTempPersonList] = useState([])
  const [ newName, setNewName ] = useState('')
  const [ newNumber, setNewNumber] = useState('')

  let searchInput = false;

useEffect(() => {

  axios
    .get('http://localhost:3001/init')
    .then(response => {
      console.log(response.data)
      setPersons(response.data)
      setTempPersonList(response.data)
    })
}, [])

  return (

      <Filter persons = {persons} setPersons= {setPersons} tempPersonList = {tempPersonList}
      searchInput = {searchInput}/>
      <AddNewPerson persons = {persons} setPersons= {setPersons} newName = {newName}
      setNewName = {setNewName} setNewNumber = {setNewNumber} newNumber = {newNumber} />
      <Persons persons = {persons} setPersons = {setPersons} tempPersonList = {tempPersonList} searchInput = {searchInput} />

      ...

  )
}

ReactDOM.render(<App />, document.getElementById('root'))

The error occurs in the code below on 'let returnList'.

const Persons = (props) => {

    const persons = props.persons
    const setPersons = props.setPersons
    const tempPersonList = props.tempPersonList
    let searchInput = props.searchInput

    let returnList = persons.map((person) =>
{person.name} : {person.number}  <button onClick={
        () =>{  Axios.delete(`${url}/${person.id}`)
        .then((response) =>{

            setPersons(persons.filter(personCheck => personCheck.id !== person.id ))

        })}}>Remove</button>
)

  let returnSearchList = tempPersonList.map((person) =>
{person.name} : {person.number}  <button onClick={
    () =>{  Axios.delete(`${url}/${person.id}`)
    .then((response) =>{

        setPersons(persons.filter(personCheck => personCheck.id !== person.id ))

    })}}>Remove</button>
)

    return(

            Numbers

    {searchInput ? returnSearchList   : returnList}

    )
}

export default Persons

Many Thanks
Answer: Your response data doesn't return an array, it's probably an object. Check in the network tab of your browser what your AJAX call returns.
Or just open this in your browser: http://localhost:3001/init
The data field of whatever is shown has to be an array.
Comment: Thank you I did not think of that! However for some reason, I thought I'd debug it how you mentioned and for some reason it started working again in production. After my PC had restarted.
Comment: @firedust is it possible that your server wasn't running and as such your AJAX call didn't actually work? I suppose in that case your `response.data` would be undefined and that would also mean no `.map()`

You should probably add a `.catch()` to your axios call to catch any sort of errors thrown because of connectivity issues.


Deletar uma Imagem especifica de um Arquivo

Question: Atualmente estou a trabalhar num novo projeto, usando Codeigniter, é a minha primeira experiencia e não encontro grande ajuda, quero que o utilizador possa eliminar uma foto escolhida por ele da sua pasta, O controlador:
`
public function delete()
    {
        delete_files('C:\wamp64\www\uploads\_back');
    }`

A view:`
{imagesback}

                                        {ver}

{name}

                                    <button name="nameimagetodelete" onclick="do_delete('{name}')"></button>

                                    {/imagesback}

`
e o  JavaScript`<
script type="text/javascript">
    function do_delete(name){
        var r = confirm("You sure?");
        if (r == true)
        {
            window.location.href = "<?php echo site_url('admin/delete');?>?name="+name;
        }
        else
        {
            x = "Action canceled";
            alert(x);
        }
    }
</script>

`
Agradeço desde já!
Comment: https://stackoverflow.com questions english
Comment: Bem-vindo ao StackOverflow **em português**. Tal como o nome sugere, o idioma oficial usado aqui é o português. Assim sendo, você poderia por favor traduzir sua pergunta? Caso prefira, você também pode fazer essa mesma pergunta no [site em inglês do StackOverflow](http://stackoverflow.com/questions/ask).
Comment: Desculpe não entendi! Prefere a pergunta em português?
Comment: Sim claro vou traduzir! Agradeço desde ja a ajuda!
Comment: @GabrielGomes o link [**editar**](https://pt.stackoverflow.com/posts/305408/edit) fica abaixo das tags, para formatar o código, basta selecionar ele e apertar o atalho `CTRL+K` ou no boão `{}` no editor, aproveite faça o [**Tour**](https://pt.stackoverflow.com/tour) para saber como funciona o site.
Comment: ja está editado @NoobSaibot
Answer: uma vez que não indicas qual o erro que estás a obter, torna se mais dificil ajudar.
mas pode ser por falta do carregamento da lib do condingniter responsalvel pelos ficheiros
poderás faze lo adicionado a seguinte linha de código ao teu controlador
$this->load->helper('file');
depois podes estar com problemas por estar a usar o caminho absoluto do ficheiro
Comment: Sim já está resolvido, alem de faltar a lib também tinha vários outros problemas que acabaram por ficar resolvidos.
Comment: finaliza o tikect


How to initialise a ViewVC commit database on Debian?

Question: I'm in the process of trying to move a ViewVC setup (along with Subversion repositories) from one server to another.
I have already created an empty "ViewVC" MySQL database and a database user to access it.
The command
/usr/lib/viewvc/svndbadmin -v rebuild /path/to/repo

still fails, apparently because the the database is not initialised properly (I was hoping "rebuild" would do that for me).
According to the INSTALL file, one should probably use the <VIEWVC_INSTALLATION_DIRECTORY>/bin/make-database script for this. However, the Debian ViewVC packages do not contain such a file! These are the packages I have installed:
$  dpkg -l|grep viewvc
ii  viewvc                1.0.5-0.2  view CVS/SVN repositories via HTTP
ii  viewvc-query          1.0.5-0.2  utility to query CVS commit database

My question is, how are you actually supposed to set up a ViewVC commit database on Debian? Google and ViewVC FAQ didn't seem very helpful with this, so I thought I'd give Server Fault a shot.
Answer: Ah, /usr/lib/viewvc/make-database script is included, in the viewvc-query package. Silly of me to miss that one (or I'm just too tired today).
So it's a simple matter of:
 sudo /usr/lib/viewvc/make-database

...which will prompt you for  MySQL username, password and database name. (Note that this clears all commit data if a ViewVC database with that name already existed.)
After this, sudo /usr/lib/viewvc/svndbadmin -v rebuild /path/to/repo works nicely.
Thanks and sorry.


Lucene search return no records

Question: I am facing a quite strange issue searching with Lucene. I have a query with 3 clauses. If I launch the query with just 2 clauses in share, it returns several documents, included the one I am seeking for. Nevertheless, if I add the third clause to the query and perform the query in share it returns no results, but it returns the document I am looking for when I launch it in the alfresco console!.
I guess it is not a grant issue since I get the document I am looking for when the query is less restrictive. The query with the third clause just fails for a specific value, for the others it works fine.
It maybe an indexing problem but in that case I think it should fail when launching the query in alfresco console as well.
Any help?
Answer: Querying in Alfresco Share differs from querying in the Nodebrowser or directly through JavaScript.
If you take a look at: alfresco/templates/webscripts/org/alfresco/slingshot/search/search.lib.js which is a repository webscript triggered by Share. You'll see in the code it fail saves results.
So you'll need to play around to get the right results.
Comment: Hi! I have just found out that the search just work if I use a 3-character clause!!! For example, if it fails for "home", it works for "hom". Any idea???
Comment: I'm sorry come again? why don't you list your actual query in the topic? Just saying clauses doesn't help us figure out the problem :).

Lucene search return no records


Randomness generated by deterministic processes

Question: The tag excerpt of randomness says:

Randomness <...> can also be generated by deterministic processes.

Is that not intrinsically contradictory? Or does it consider randomness epistemically where an ontologically deterministic process appears random when insufficient conditioning information is available (an example of pseudo random number generator comes to mind -- thanks to Tim)? If not, could you offer a clarifying example?
 P.S. The other part of the excerpt is Randomness is often modeled with probability distributions, but can also be generated by deterministic processes. In my opinion, this sounds like an apples-to-oranges comparison, making the use of but questionable.
Comment: Either someone meant PRNGs, or this is a deeply philosophical comment.
Comment: Had to Google *PRNG*. It turns out to be *pseudo random number generator*.
Comment: @whuber, to the extent that the question is about statistical concepts and their definitions, I think it is more at home here than on Meta. I have phrased the question so as to discuss a statistical claim, not to discuss the properties of the excerpt for its own sake. Had I focused on editing the excerpt instead, I would have posted it on Meta. Perhaps the P.S. got in the way... I hope that makes sense.
Comment: It's a pretty bad tag wiki -- an anonymous user contributed it long ago and (apparently) it was never seriously reviewed.  Discussing bad tag wikis is the province of our Meta site: does it really belong here?
Answer: one example that comes to mind that I saw being used as an example in a similar context, is calculating digits of pi or sqrt(2) or any other irrational number. The individual digits are uniformly distributed as far as we know with no relationship between the previous digits and the next digits. You don't know what the next digit will be until you observe it, e.i., compute it, so you can say that it will be random, but of course completely deterministic.
Yes, this is similar to how the pseudo-random numbers are computed. So is it random or pseudo-random? Is the billionth billionth billionth digit of pi that we won't be able to compute until hundred years from now less random than a decay time of some specific atom? You decide
edit:
digits of pi or sqrt of 2 are going to pass pretty much any randomness criteria used to test pseudo-random generators, which is not the case for other pseudorandom generators. At least that's what mathematicians believe, I a not sure, I am not a number theorist
Comment: it is definitely deterministic since everybody will get the same answer, or you will get the same answer if you calculate it again. It is already determined what the digits are if you wish.
Comment: @whuber thanks that's exactly what I had in mind. The similarity is that they are results of computing some mathematical function. If this is a big or small similarity is I guess a matter of opinion.
Comment: Thank you. I wonder how to characterize the process that generates the digits of $\pi$ or $\sqrt{2}$. Can we say it is a deterministic process? (I do not have an immediate answer.)
Comment: Determining whether $\pi,$ $\sqrt{2},$ or other (easily expressed) irrational numbers is a *normal number* in this sense is [an unresolved problem](https://mathworld.wolfram.com/NormalNumber.html).  The computation of their digits bears little similarity to the generation of pseudo-random numbers


Is there a recorder-analog for the flute?

Question: I have used soprano baroque recorders for students aged 8-10 as a "pre-band" instrument.  I find that most students enjoy practicing note-reading, and the average student is able to progress reasonably far in two years of study.  I find that students who can master at least the first octave of the instrument progress very quickly on clarinet or saxophone in their next year after playing recorder.  I suspect it's because there are so many similarities (the basic fingerings, breathing, etc.).
I have also noticed that beginner flute players struggle tremendously because it's so much harder to produce a tone on a flute.  I know that playing a single-reed instrument is obviously different than a fipple flute but it's a similar shape and size and students seem to adapt quickly.  The concert ("band") flute is quite different and in my experience, harder.  Flute students at this age (10 or 11 years) seem to more frequently lose interest as their reed-playing classmates advance beyond their skill level.
I'd like to be able to give all the students a chance to learn some rudimentary skills for flute playing, too.
I'm curious... does there exist a simple instrument that could do for the flute what the recorder does for clarinet and saxophone?  Is there such thing as a "transverse recorder," say?
Comment: How about arranging private flute lessons?   Frankly, if your single-reed players aren't getting lessons, they may be producing more sound sooner but they are equally at risk of developing all the wrong breathing and embeauchure habits.
Comment: And from your response to the suggestion of private lessons we gather that you are not a flute player yourself? That of course makes a difference.
Comment: Do you have any sense of the degree to which the different orientation of the instrument is responsible?  Or the embouchure and different needs of breath control?  Or other factors?
Comment: Nope, no idea.  I suspect it's mostly the necessity of proper lip placement/air direction on a flute when compared to the recorder which works when you simply blow into it
Comment: +1 for private lessons, which I encourage as much as possible (providing families with names of good local teachers, etc.)  Not all can afford,  unf
Comment: @VictorEijkhout I can play flute to some degree, as I can all band instruments as the instructor,  but not at the level of a private teacher
Answer: TL;DR

Step 1: Soda bottle
Step 2: Fife

Soda bottle
Flute players are sometimes told that blowing across the top of a soda bottle is similar to blowing a flute. (Anecdotally, A flute-playing acquaintance confirms that this offered some help in developing their embouchure.)
Though the flute tone hole is generally smaller and differently shaped, the techniques are similar, and the bottle can be easier. Using a common object can be very appealing and fun for kids.
Some additional advantages:

Very inexpensive
Lends itself to a natural physical experiment: put various amounts of water in the bottle and observe the changes in pitch.)
Neat party trick with friends; awesomely annoying party trick with parents and siblings.

A couple of internet reference points:
(Note that these do not directly advocate soda bottles as a teaching tool.)

Flute Embouchure: What is Normal?

A common way to explain the flute embouchure is to equate flute playing to blowing into a pop, or soda, bottle.

Flute Techniques, by Dr. Karen McLaughlin-Large, Kansas State University, 2013

Exercise 2

1.ALWAYS begin students with head joint exercises.

2.Cover the lip plate and blow over the end of the head joint like playing a bottle.

3.Use little tension. Very relaxed.

4.Remember to use the surprise breath.

However, for a contrary opinion, see

Tips For Teaching Beginning Flute Players

The flute should not be played like a coke bottle.

Fife
I would look first at the fife (Wikipedia). It's held and blown like a transverse flute, but is smaller, lighter, and non-keyed. Given the setting, where many students many need instruments, there are inexpensive plastic fife's available. For example, at the time of this post, Yamaha makes a plastic fife, available on Amazon for $10.55.

And here is a detail showing the mouthpiece.

There are other transverse flutes, such as those listed on Wikipedia:

Indian classical flutes (the bansuri and the venu), the Chinese dizi, the Western fife, a number of Japanese fue, and Korean flutes such as daegeum, junggeum and sogeum.
Comment: I had both a fife and a recorder as a child (though I never had any formal instruction in either, nor in any other wind or brass instrument).  I had a horrible tone, but I could play the full lower octave and some simple tunes.  One could even imagine a fife-and-drum corps of sorts (even though my autocorrect seems to prefer a five-and-dime corps!), which would seem to be useful in preparing the students for a marching band.  I don't suppose recorders lend themselves to marching.  Anyway, this seems the most obvious suggestion, so +1.
Comment: @CarlWitthoft I may have come up with a way to address your criticism, at least partially: soda bottles. Although not identical to flute embouchure, do you agree that it could be helpful in sparking kids' interest in the instrument by giving them something easier and simpler to start on, thus making it a little easier to sustain the motivation to work through the flute embouchure's initial difficulties?
Comment: My wife played flute a little bit as an elementary school student and many years later picked up a couple bansuris (different keys) and a dizi.  She found the bansuri easier to play.
Comment: @Theodore Bansuri was easier than dizi or easier than flute? (Or both?)
Comment: @Aaron Bansuri was easier than dizi.  She no longer owns a flute and hadn't played in decades.
Comment: I fail to see how this makes learning flute embeauchure any easier.  Cheaper, yes.
Comment: @CarlWitthoft That's a fair criticism. Do you know whether any of the other transverse instruments provide an easier entry point?
Comment: Not easier,  just a simpler way for them to get a feel for it ahead-of-time.  $10 to try it out instead of hundreds
Comment: @nuggethead "Simpler" is what I had in mind when I answered — fife is smaller, lighter, and simpler mechanically — but Carl does make a good point about the embouchure, which is the most difficult challenge. But even if some other instrument is easier to blow, there would still be the issues of cost and simplicity, which may or may not come out in favor of the fife.
Comment: @CarlWitthoft That you fail to see doesn't mean that there isn't something there. The shorter pipe for instance makes the instrument more responsive. I think the Fife was an entirely reasonable suggestion.
Comment: In the category of "neat party trick with bottles": [Bottle choir](https://youtu.be/NkbZlautuUc?t=17). Maybe for the older kids...
Comment: @Aaron the soda bottle thing is a helpful idea.
Answer: Not meaning to detract from the excellent answer from @Aaron, I tried out some of the Yamaha fifes.  The answer is...
Yes, Yamaha makes a fife that is in the same price range as a recorder, but no, it is not a good pre-band instrument.  The size of the tone hole is smaller than a flute (and harder to hit squarely).  The fingerings are different enough that a recorder player gets them confused easily, and it's more difficult to play than a flute.
Answer: I have seen flutes with a recorder headjoint. However, those are not cheap and usually considered a crutch anyway. Your flute students need to learn to deal with embouchure at some point.
The suggestion of a fife is a reasonable one, especially the Yamaha with a plastic lip plate that is flute like, rather than the traditional "military" fife. The shorter instrument is more responsive, and because of the higher register carries more than a concert flute.
But I wonder, is it the band environment that is putting them off? In a distant past I learned flute and never gave it a second thought that my tone got better and better. Yes, my teacher, and flute players on records, were better but that never discouraged me.
Comment: Could you be more explicit about the band environment and how that might affect things?
Comment: @Aaron That's what I'm actually asking of the OP. I wonder if young person would not be so discouraged if they didn't have to deal with the comparison with other instrumentalists their age.
Comment: It's the competitive part that I'm suggesting be more explicit. It's fairly clear that's what you mean, but I think it could be said even more directly.
Comment: I think you missed the point - or perhaps I was unclear.?  I do not want anything to do with a flute with a recorder head joint.  We can agree that would not be prudent
Comment: Also, re competition, it is not in any way a competitive ensemble.  But when after a short duration of lessons the other wind players can play 8-bar phases and the flute players are still struggling to string three decent notes together, it can be disconcerting!
Comment: Oh, I get your point. See everything from the second half of my second sentence on. And I don't think a easy way into acquiring an embouchure exists. Come to think of it, contrabass flutes have something that goes over the normal mouthpiece to direct the air stream. But I've never seen that for the normal flute.


Error trying to compile v8 on OSX Lion: scons: *** No SConstruct file found

Question: I'm getting the following error trying to compile v8 on OSX Lion:
<code>sh-3.2# scons

scons: *** No SConstruct file found.
File "/usr/local/lib/scons-2.3.0/SCons/Script/Main.py", line 905, in _main
</code>
I've installed scons using Homebrew.
Comment: Either you havent defined a SConstruct or it cant be found. This answer should help: http://stackoverflow.com/a/17185787/1158895
Comment: possible duplicate of [SCons- \*\*\* No SConstruct file found](http://stackoverflow.com/questions/17182799/scons-no-sconstruct-file-found)
Answer: Either cd to the directory that contains the SConstruct file, or use the -f flag to tell scons where it is. It works like "make", which needs to find a "Makefile" or it can't build anything.
Answer: AllJoyn is built using xcodebuild for OS X. Using scons directly is not supported.


Can I put robots.txt for "sorry" server?

Question: I'm considering whether I should put following robots.txt for my "sorry server" that returns some sorry message to our customer that we are under maintenance.
User-agent: *
Disallow: /

So here's my concerns/questions:

Won't it tell crawlers to not to index our site forever in spite of our server is ready after the maintenance is done?
If I put the robots.txt for my sorry server, should I put another robots.txt for our regular server that tells crawlers to "please index our site"?
[EDIT] Speaking of extremes, Won't it delete our site from Google?
Answer: You should not use robots.txt for that situation.
A bot that fetches the robots.txt while you're in maintenance mode might cache it and apply its rules also when your site is back online (with a changed robots.txt that this bot won't see for some time). And a bot that fetches the robots.txt while your site is online might apply its rules also when your sites is in maintenance mode.
Instead, you should provide an appropriate HTTP header for the maintenance mode: 503 Service Unavailable. This signal alone should be sufficient (at least for somewhat capable bots) not to index the pages.
In addition, you could provide a meta-robots element with a noindex value, or the corresponding HTTP header X-Robots-Tag (see example).


VPN Network and Kubernetes Clusters

Question: I have a question regarding a best practice when it comes to setting up a kubernetes cluster with VMs across multiple, physical servers. We were able to successfully setup a cluster between multiple VM instances on one single, physical server. One of these VM instances is the master node. The VM instances do not have a unique public IP of their own, only internal IP.
Eventually this single server will run out of resources. The idea is to just setup an additional server with again multiple VM instances on it, and join those new VM instances as new nodes to the existing cluster.

Does something like this work ?
Do all VM instances have to be in the same network ?
Would that work with VPN ?
Does this need another master node for each physical server ?

Thanks for any pointers and suggestions !
Comment: Hello. Creating Kubernetes cluster on multiple `VM`'s should work considering all of the requirements are met. As a pointer you could look on this official documentation about [creating highly available clusters with kubeadm](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/high-availability/). Talking about the VPN are you trying to connect nodes/masters between sites or it serves a different purpose?  You could also look on this SF answer: https://serverfault.com/questions/1035490/can-kubernetes-cluster-nodes-be-geologically-spread-out/1036447#1036447
Comment: So creating the cluster on multiple VM's is not a Problem. We already have that. They're all connected through a private network, but all are running on one and the same physical server, so that's cool. But what about additional VM's which run on a different server ? Do they have to be in the same private network as well ? Or do you just create a master node on each server and join only the master nodes together ?
Answer: Posting this answer as community wiki as the question portrayed could be wide and not get the definitive answer.
Feel free to expand it.

As for:

Does something like this work ?

Yes. In fact there are multiple ways to configure your cluster. I encourage you to visit sites below for an overview of Kubernetes components and architecture:

Kubernetes.io: Docs: Concepts: Overview: Components
Kubernetes.io: Docs: Concepts: Architecture

You can use below link (with a guide) to setup a cluster that will use the minimum of 3 masters and 3 workers nodes for highly available setup:

Kubernetes.io: Docs: Setup: Production environment: Tools: Kubeadm: High availability

Some tips!

For production environments, you would need a dedicated HAProxy load balancer node (physical, virtual)
While master components can run on any machine, best practice dictates using a separate server for the master and not running any user containers on this machine.
It is best practice to run your clusters in a multi-master fashion in Production – to ensure high availability and resiliency of the master components themselves. This means you'll need at least 3 Master nodes (an odd number, to ensure quorum

As for quorum in etcd!
Please remember that etcd requires a quorum to be operational. You can read more about it by following below link:

Github.com: Etcd-io: Documentation: FAQ: Why an odd number of cluster members

Do all VM instances have to be in the same network ?

It will depend on the networking architecture of your setup. The easiest solution would be to create a private network that would span across multiple physical machines that you intend to deploy Kubernetes (to have nodes in the same network).
Paraphrasing what was just said:

VM #1 on Physical server #1 could easily communicate with VM #2 on Physical server #2

Would that work with VPN ?

Please specify what exactly you mean by a VPN connection:

Is it the connection between nodes in your network?
Is it the connection that will connect the nodes between themselves from an offsite location?
Is it a connection for developers/sysadmins to get access to your Kubernetes cluster?

As for a side note you can look on Wireguard (network plugin with built-in encryption):

Gravitational.com: Blog: Announcing Wormhole

Does this need another master node for each physical server ?

In short no but. There is always a but:

You can create a cluster where there will be single master node  and multiple workers on multiple physical machines. This setup will work but it won't be highly available solution.
You can create a cluster where there will be multiple master nodes span across multiple physical servers. This heavily depends on what exact needs you have.

I thought about this question and it could be a long shot but if you think that master and worker on each physical machine are coupled in any term, they aren't. Each worker should be able to communicate with each master node and vice versa.

Do they have to be in the same private network as well ? Or do you just create a master node on each server and join only the master nodes together ?

You need to run $ kubeadm init to initialize the cluster on a single master node. Then you will need to run  $ kubeadm join on each of the nodes (master/worker). The difference between them (master/worker) is the parameter:

--control-plane # <-- this parameter will indicate a master node (use it only on a master node).

I also encourage you to check additional resources:

Platform9.com: Blog: Kubernetes on premises why and how
Serverfault.com: Questions: Can kubernetes cluster nodes be geologically spread out?
Github.com: Kelsey Hightower: Kubernetes the hard way

VPN Network and Kubernetes Clusters


Estrutura de projeto

Question: Estou com um projeto sendo desenvolvido com VRaptor e tenho uma dúvida sobre estrutura de
projeto.
O projeto que estou desenvolvendo será instalado em vários clientes,
cada um com uma estrutura diferente.

Não sei como será a configuração do JPA no cliente, e, como
haverá vários clientes, cada um com uma configuração distinta, como
posso fazer para o cliente configurar isto corretamente? Deixo isto
para o cliente configurar? Pensei em utilizar um datasource ja
definido no persistence.xml, mas se o cliente quer fazer o deploy de
duas instancias no mesmo servidor, como ficaria? Ou há alguma maneira
de, ao fazer o re-deploy, não sobrescrever o arquivo de configuração do
JPA?
Arquivo com algumas definições, isto também é por cliente e varia
muito de ambiente para ambiente: Há alguma maneira de ler o arquivo
mas no re-deploy não sobrescrever o mesmo (mantendo as configurações
pré-existentes)? Lembrando que neste caso, dependendo do aplicativo,
não terá acesso a base de dados para utilizar a configuração do JPA.

Sei que existem environments para tratar diferentes configurações,
mas tem muitas informações que não terei do cliente (principalmente
nome do banco e senhas) e não gostaria de ter que criar um .WAR
especifico para cada um dos clientes já com suas configurações
definidas.
Em PHP consigo tratar a
sobrescrita de arquivos. Neste caso talvez haja outra
maneira de tratar estas dúvidas, estou aberto a
sugestões.
Gostaria de uma solução o mais prática possível, podendo ser usada em qualquer container  (Jetty, WildFly, Tomcat, etc.).
Comment: Para resolver o segundo item, eu costumo distribuir um arquivo ***config.properties.modelo*** com as configurações padrão (não incluo no pacote nenhum *config.properties*). Então, na instalação o cliente remove o *.modelo* do nome do arquvio e customiza seu conteúdo; e durante a atualização o arquivo do cliente nunca será substituído pois o arquivo substituído será apenas o arquivo modelo.
Comment: Seja bem vindo ao SOPT! Removi as saudações e agradecimentos de sua pergunta(http://meta.pt.stackoverflow.com/a/851/3907) e tornei ela mais objetiva. Por favor leia esta pergunta do Meta para entender melhor porque fiz isso.
Answer: Quanto à primeira dúvida, o padrão da arquitetura Java EE é que a aplicação declare no web.xml de quais DataSources ela depende e a configuração seja realizada no servidor de aplicação no momento do deploy pelo cliente ou responsável.
Para os casos onde o cliente pode querer duas instâncias da aplicação apontando para diferentes DataSources, cabe a ele configurar corretamente o servidor.
Infelizmente, cada servidor de aplicação tem sua configuração própria. Por exemplo, no Tomcat cria-se um arquivo context.xml para cada aplicação com os respectivos DataSources. Já no Websphere e Weblogic é possível vincular as dependências de recursos aos DataSources através do painel administrativo.
Por outro lado, é bem possível ignorar os DataSources do container e deixá-los a carga da aplicação. Uma forma bem simples é carregar o persistence.xml a partir de um diretório ao instanciar manualmente o EntityManagerFactory. A configuração desse diretório poderia ser feita por variável de ambiente, então o cliente ainda teria a flexibilidade de apontar para qualquer diretório. Sendo possível definir variáveis específicas para cada JVM ou para cada aplicação (em alguns servidores, pelo menos), ainda seria possível ter diferentes arquivos de configuração para cada instância da aplicação.
Dados como usuário e senha são sempre responsabilidade do cliente, sua aplicação nunca deve carregar esses dados dentro do pacote.
Quanto a sua segunda dúvida, configurações dependentes de ambiente devem ser armazenadas em algum local do ambiente.
A grande maioria das aplicações corporativas armazena as configurações ou "parâmetros" de sistema em banco de dados. Isso facilita o gerenciamento por parte do cliente, afinal somente é necessário conhecer um pouco de SQL para fazer a manutenção quando necessário.
Outra forma comum é armazenar as configurações em arquivos XML, Json ou properties (este último mais comum por ser um padrão da plataforma Java). Não recomendo apontar diretamente para um diretório, mas usar a mesma técnica descrita logo acima, isto é, utilizar uma variável de ambiente. A variável de ambiente pode ser definida em vários níveis: sistema operacional, usuário do SO, JVM, Servidor de Aplicação ou para uma única aplicação.
Em todo caso, um item muito importante é ter um roteiro para instalação inicial e atualização do sistema.
Também é importante fazer uma espécie de homologação da aplicação nos diversos servidores de aplicação. Infelizmente há diferenças enormes entre eles e nem sempre a compatibilidade é tão fácil de ser atingida. Alguns servidores JEE vêm com um caminhão de bibliotecas que podem conflitar com o que tem sua aplicação, cada um tem uma forma de resolver esses conflitos.

Atualização
Configurações específicas no Tomcat
No Tomcat, o context.xml é o arquivo de configuração ideal para apontar para Data Sources, principalmente no que se refere a bancos de dados. Basta usar a tag <Resource>, conforme a documentação.
Você também pode usar o arquivo context para definir parâmetros de contexto ou variáveis de ambiente específicas da aplicação. Veja a documentação.
Configurações específicas no JBoss
No JBoss você pode configurar os Data Sources no arquivo standalone.xml, que fica num subdiretório do servidor.
Existem outros arquivos para configurações específicos da aplicação, veja a documentação aqui.
Esses arquivos de configuração ficam dentro do WAR e, assim como o arquivo context.xml do Tomcat, são chamados de deployment descriptors, pois são arquivos que configuram o deploy da aplicação num servidor específico. Cada servidor deve ter o seu, com mais ou menos flexibilidade.
Como carregar um arquivo específico por aplicação
Você também pode carregar um arquivo de configuração externo diferente para cada aplicação ou instância da aplicação da seguinte forma:

Defina uma variável de ambiente apontando para um diretório de configuração, por exemplo: /path/to/conf.
Crie um ServletContextListener para carregar a configuração durante o startup do sistema.
Leia a configuração usando o diretório configurado, mais o context path como nome da arquivo.

Dessa forma se houver duas instâncias da mesma aplicação em diferentes contextos, por exemplo /myappinstance1 e /myappinstance2, cada uma acessará sua própria configuração, respectivamente:

/path/to/conf/myappinstance1.properties
/path/to/conf/myappinstance2.properties
Comment: Entendi. Mas no caso, teria algum exemplo de como apontar e ler um arquivo de configuração por context, pode ser no WildFly, Tomcat ou Jetty?
Comment: @Walkovyr Havia lhe respodido em comentários, mas devido ao tamanho acabei apagando-os e coloquei como atualização na minha resposta.

Estrutura de projeto


Mudar o fundo do HTML quando input for true

Question: Estou fazendo um site onde terá como fundo uma foto do Heisenberg dizendo "Say My Name" com um input do tipo text no meio da tela e quando o usuario digitar Heisenberg o background irá mudar para uma foto dele dizendo You Goddam right, porém não estou conseguindo, como faço isso usando JQuery?

$("#SayMyName").focusout( function(){
    var SayMyName = $("#SayMyName").val();
    if (SayMyName == "Heisenberg") {
        $("body").css("background-image", "url(/myimage.jpg)");
    }
    else {
        SayMyName = " "
    }
});
<!DOCTYPE html>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <form action="">
        <input type="text" id="SayMyName" name="SayMyName">
        <input type="submit" value="submit">
    </form>

Comment: prefiro JQuery pois é o que estou estudando no momento
Comment: Tem que ser com JQuery? CSS não basta?
Comment: não, pois preciso verificar se o usuario digitou o nome corretamente
Comment: Eu sei disso, eu perguntei se a mudança no back tem que ser feita com o jquery? A verificação pode ser feita com vanilla javascript?
Comment: o erro se dá inicialmente pois ```url()``` é uma função que espera receber uma string com o path e ela está recebendo algo que não é uma string, o certo seria usar aspas simples ali ```"url('/myimage.jpg')"``` isso inicialmente, depois tem que conferir se o path está correto.
Answer: Provavelmente o path para a url da imagem está errada, caso seja o diretório corrente não precisa da / no /myimage.jpg ou podes usar também ./myimage.jpg, além disso, faltam os apóstrofos dentro do url. Fora isso, o else não está fazendo nada... já que só atribui um espaço em branco pra uma variável que não é mais utilizada dentro do escopo dela.
A seguir eu coloquei o seu código, só que alterando o background-color, afim de mostrar que a lógica em si está correta, possivelmente, precisando verificar só o path do background-image.
A seguir eu coloquei o seu código, utilizando uma imagem qualquer...

$("#SayMyName").focusout( function(){
    var SayMyName = $("#SayMyName").val();
    if (SayMyName == "Heisenberg") {
        $("body").css("background-image", "url('https://cdn.pixabay.com/photo/2014/05/02/21/49/laptop-336373_960_720.jpg')");
    }
});
<!DOCTYPE html>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <form action="">
        <input type="text" id="SayMyName" name="SayMyName">
    </form>

Comment: não está errado, ta tudo correto, mas mesmo assim não está funcionando
Comment: Você mudou a url da imagem?
Comment: Editei para funcionar com uma imagem...
Comment: @FelipeAvelar se a pessoa digitar `Heisenberg` bater enter o form recarrega. Troque `` por ``
Comment: @VitorCorrea, a imagem só aparece quando a pessoa clicar fora do `` o evento escolhido é `focusout`.


How to break out of playing scales up and down when improvising

Question: I play piano, and when I am playing a gospel or a blues song, I always improvise with my right hand. I have been practicing major scales and pentatonic scales for a while now, and when I play, i usually just play the scales up and down the keyboard. It does sound good, and I switch the scales with the modes and stuff, but how can I break out of this habit and explore new stuff with them?
Comment: Just don't allow yourself to play consecutive notes!
Comment: What approaches to breaking away from playing scales up and down have you tried so far, and what problems have you had with them?
Answer: Try working around chord tones.
Three things you can add to playing only chord tones are auxiliary tones, passing tones, and enclosures.

The enclosure example shows enclosures targeting each tone of a major scale, but you can use an enclose to target chord tones.
All three can be modified in various ways...

If only the various figures for auxiliary and passing tones are used, it will provide for lots of interesting lines. The nice thing is it's easy to remember the basic approach: focus on the broken thirds that make up chords and either: play a chromatic auxiliary tone under it, or fill it in with chromatic passing motion.
Those examples show only swing eight notes, but you should try playing other rhythm patterns too, things like syncopated quarter notes, and triplet figures. Start figures on or off the beat for variety. You can omit a note hear or there to suite the rhythm.
When you put it altogether you can get lines like these...

...of course those could be adapted to solo keyboard.
Comment: I tried to say, it's better to think about playing over chords as "what can I turn this into" rather than "I must emphasize and obey the chords that were given to me". If everyone else is playing a C major chord, you can turn the harmonic situation into lots of things by imagining different notes and chords over it. For example Bb, D, Db, A or F# major chords. The piano keyboard offers an excellent birds-eye view for seeing what happens. Your answer about working around chord tones is great, but I'd add: "the chords don't have to be the ones that are written, you can imagine your own chords".
Comment: +1 IMO, rhythm-guided emphasizing of chord tones is the correct answer, because that's the way to create new melodies and riffs. Even if you create melodies by instinct without explicitly thinking about chords and rhythms, every melody and riff _implies_ some chordal harmony and rhythm, so it's better to try and see and control the "master ingredients" behind the scenes. And it's important to not fall victim to pre-written chord changes and rhythms. You can and should improvise your _own_ chords and rhythms by playing things over what others are playing. It's like live arranging and composing.
Comment: This kind of music is homophonic. If you are improvising over _chord_ changes, it's backwards to think scales to derive chords. One way I like to think of is: fill in passing tones on a seventh chord and you get a scale.
Answer: Two broad strategies:
Since you're familiar with scales, keep practicing them, but in different patterns

Break up the scales into different patterns

X: 1
T: Scale in 3rds
M: 4/4
K: C major
L: 1/8
"C"CEDF EGFA | GBAc Bdcd | ecdB cABG | AFGE FDED | C8||

X: 1
T: Scale in 3-note groups
M: 4/4
K: C major
L: 1/8
(3CDE (3DEF (3EFG (3FGA | (3GAB (3ABc (3Bcd c2 | (3edc (3dcB (3cBA (3BAG | (3AGF (3GFE (3FED C2 ||

Combine scales with chord outlines

X: 1
T: Chord/scale combination 1
M: 4/4
K: C major
L: 1/8
"CM7"CEGB AGFE | "Dm7"DFAc BAF^F | "G7"GBdf- ffed | "C"c8 ||

X: 1
T: Chord/scale combination 2
M: 4/4
K: C major
L: 1/8
"CM7"CDEF GEC^C | "Dm7"DEFG AFDC | "G7"B,CDE FDGB | "C"c8 ||

Play familiar tunes/licks

Over chord changes where they work

X: 1
T: "Twinkle, Twinkle, Little Star" and "New World Symphony" over Blues
M: 4/4
K: C major
L: 1/4
"C7"C C G G | "F7" A A G F | "C7"E3/2 G/2 G2 | G3/2 F/2 E2 ||

Over chord changes other than expected (with adjustments)

X: 1
T: "Twinkle, Twinkle, Little Star" in C, over F7
M: 4/4
K: C major
L: 1/4
"F7"C C G G | A A G2 | F F _E E | D D C2 ||

Comment: @WayneConrad I wrote these examples myself, but I can recommend the book "Patterns for Jazz" by Jerry Coker. Its whole purpose is to give exercises like these that take you through a variety of chords and chord changes in every key.
Comment: IMO you should attempt to see chords behind all these lines. The sequential step-by-step lines outline chords as well. For example the latter half of bar 1 of "Chord/scale combination 1", A-G-F-E outlines a Dm or F chord, because the note pair A-F probably gets more emphasis than G-E, due to their rhythmic placement. The pitches in scales are only palettes or toolkits for painting harmony. If you play C-D-E-F-G-A-B, its harmonic effect depends on where you start. Starting on C, you play a C major chord, but if you play it with an anacrusis, C | D-E-F-G-A-B ... then it does a D minor'ish thing.
Comment: I've been searching the internet for practice ideas like this.  What is the source of these examples?  If it's a book, I might like to buy it.
Answer: Learn riffs, and licks.  Try developing a set of these by listening to other's and transcribing their work.  Scales and arpeggios are the foundation of melodies, some might say the interval is the foundation of melody since that is more primitive than a scale (which is a sequence of intervals).  Rhythm is an important part of melody as well.  So playing fragments and letting in some space could help break that habit.
Answer: There's a structured series of books for piano by Bradley Sowash that will probably be helpful for you.  They're really fun to work with and will help you work with patterns and little riffs.
You could make some transcriptions of some solos that you find intriguing.
You could experiment with some blues improvisation.
Do you ever sing the same line you are playing with your right hand?  Or perhaps I should say, do you ever improvise with your voice, and let your right hand double what your voice is doing?
You could cross-pollinate by improvising with the left hand.
Take a little figure (short riff) and play it going around the circle of fifths.  The next step is then to play it (in the appropriate key) for each chord in your tune.  How do you choose the little riffs?  By listening to recordings and bringing your favorite riffs into your riff repertoire.
Answer: When you improvise, you call upon a personal vocabulary of phrases.
The way you build that vocabulary is not necessary via improvising though.
You can work on developing some new phrasal pattern deliberately, in a slower tempo. Then rehearse it up to tempo, and then try mixing it between your existing improvisational phrases that you can play in "auto pilot" mode. By doing that you find ways to nicely transition into the new phrase from existing phrases and the best situations for using it.
In improvisation, you might start and end a solo using material you know very well. In the middle somewhere, you transition into some of this new stuff. If it looks like it's not working out, find a way to exit to familiar territory.
When you're working on developing new phrases, you're not doing it all in real time, so you have time to think. If you're tired of scalar patterns, you can consciously break out of it. "Write" a pattern that includes some non-diatonic leaps in it, and rehearse it.


Add a Azure WebApp to an Existing VPN using a Point-to-Site connection (RM Powershell)

Question: I have hunted around for an answer to this, but I am not having much luck. All the articles I can find are either setting up a Point-to-Site or are instructions for classic Azure, not Azure 2.0 (Resource Group)
Currently, we are dialing up a whole new resource group everytime we do a new built. This consists of Web apps and SQL DBs. When we have a new build we start up the new and del the old resource group. Simple. To minimize the start-up time we have a static resource group that isn't deleted that houses the VPN connection to our on Prem resources.
The problem I'm having is when I add the new websites using AzureRM Powershell cmd's to the Point-to-site it says it's successful. The Azure Portal says its good but it does let me communicate. If I remove and add it from one of the 8 WebApps they all start working.
I am out of ideas. Any help would be greatly appreciated.
Azure VPN
Below is the function I have put togeather from what I can find out there.
function AddExistingVnet{
param(
    [string] $subscriptionId,
    [string] $resourceGroupName,
    [string] $webAppName

)

$Vnet = Get-AzureRmVirtualNetwork | Where-Object {$_.ResourceGroupName -like "*Static*"}

IF($Vnet.Name.count -gt 1) {write-host 'Two or networks have been returned. Unable to continue ' return}

    $gatewaySubnet = $vnet.Subnets | Where-Object { $_.Name -eq "GatewaySubnet" }
    $vnetName = $vnet.Name
    $uriParts = $gatewaySubnet.IpConfigurations[0].Id.Split('/')
    $gatewayResourceGroup = $uriParts[4]
    $gatewayName = $uriParts[8]
    $gateway = Get-AzureRmVirtualNetworkGateway -ResourceGroupName $vnet.ResourceGroupName -Name $gatewayName

    Write-Host "Creating App association to VNET"
    $propertiesObject = @{
     "vnetResourceId" = "/subscriptions/$($subscriptionId)/resourceGroups/$($vnet.ResourceGroupName)/providers/Microsoft.Network/virtualNetworks/$($vnetName)"
    }

    $virtualNetwork = New-AzureRmResource -Location $location -Properties $PropertiesObject -ResourceName "$($webAppName)/$($vnet.Name)" -ResourceType "Microsoft.Web/sites/virtualNetworkConnections" -ApiVersion 2015-08-01 -ResourceGroupName $resourceGroupName -Force

# Now finish joining by getting the VPN package and giving it to the App
Write-Host "Retrieving VPN Package and supplying to App"
$packageUri = Get-AzureRmVpnClientPackage -ResourceGroupName $vnet.ResourceGroupName -VirtualNetworkGatewayName $gateway.Name -ProcessorArchitecture Amd64

# Put the VPN client configuration package onto the App
$PropertiesObject = @{
"vnetName" = $vnet.Name; "vpnPackageUri" = $packageUri
}

New-AzureRmResource -Location $location -Properties $PropertiesObject -ResourceName "$($webAppName)/$($vnet.Name)/primary" -ResourceType "Microsoft.Web/sites/virtualNetworkConnections/gateways" -ApiVersion 2015-08-01 -ResourceGroupName $resourceGroupName -WarningAction silentlyContinue -Force

}

Comment: Logged a Case with Azure support and so far they seem to be stuck.     They had one fix which didn't help fix the VPN, but cleared up one of the minor problems. If you are getting a "loading" on the cert sync in the azure web console it can be caused by the length of your WebApp being over 42 characters long.
Answer: So after 2 weeks of going back and forth with Microsoft (had a really good guy Charles) we managed to find the problem.
When requesting
$packageUri = Get-AzureRmVpnClientPackage -ResourceGroupName $vnet.ResourceGroupName -VirtualNetworkGatewayName $gateway.Name -ProcessorArchitecture Amd64

It was giving me an output of:
"https://mdsbrketwprodsn1prod.blob.core.windows.net/cmakexe/xxx~xxx/amd64/xxxx~xxxx&sp=r&fileExtension=.exe"

For some reason (that Microsoft could explain) why it kept adding in " to the beginning and end of the variable.
I find it odd that it lets the script work with " and allows the WebApps to join to the VPN.
Any why here is the fix which basicly removes the " from the begining and end of $packageUri :
$packageUri = $packageUri.ToString();
$packageUri = $packageUri.Substring(1, $packageUri.Length-2);

So hope that helps someone else out there who is banging there head agaist the same problem.
Here is the complete function if any one is intrested:
function AddExistingVnet{
    param(
        [string] $subscriptionId,
        [string] $resourceGroupName,
        [string] $webAppName

    )

$Vnet = Get-AzureRmVirtualNetwork | Where-Object {$_.ResourceGroupName -like "*Static*"}

IF($Vnet.Name.count -gt 1) {write-host 'Two or networks have been returned. Unable to continue ' return}

        $gatewaySubnet = $vnet.Subnets | Where-Object { $_.Name -eq "GatewaySubnet" }
        $vnetName = $vnet.Name
        $uriParts = $gatewaySubnet.IpConfigurations[0].Id.Split('/')
        $gatewayResourceGroup = $uriParts[4]
        $gatewayName = $uriParts[8]
        $gateway = Get-AzureRmVirtualNetworkGateway -ResourceGroupName $vnet.ResourceGroupName -Name $gatewayName

        $webApp = Get-AzureRmResource -ResourceName $webAppName -ResourceType "Microsoft.Web/sites" -ApiVersion 2015-08-01 -ResourceGroupName $resourceGroupName
        $location = $webApp.Location

        Write-Host "Creating App association to VNET"
        $propertiesObject = @{
         "vnetResourceId" = "/subscriptions/$($subscriptionId)/resourceGroups/$($vnet.ResourceGroupName)/providers/Microsoft.Network/virtualNetworks/$($vnetName)"
        }

        $virtualNetwork = New-AzureRmResource -Location $location -Properties $PropertiesObject -ResourceName "$($webAppName)/$($vnet.Name)" -ResourceType "Microsoft.Web/sites/virtualNetworkConnections" -ApiVersion 2015-08-01 -ResourceGroupName $resourceGroupName -Force

    # Now finish joining by getting the VPN package and giving it to the App
    Write-Host "Retrieving VPN Package and supplying to App"
    $packageUri = Get-AzureRmVpnClientPackage -ResourceGroupName $vnet.ResourceGroupName -VirtualNetworkGatewayName $gateway.Name -ProcessorArchitecture Amd64

    $packageUri = $packageUri.ToString();
    $packageUri = $packageUri.Substring(1, $packageUri.Length-2);

    # Put the VPN client configuration package onto the App
    $PropertiesObject = @{
    "vnetName" = $vnet.Name; "vpnPackageUri" = $packageUri.ToString()
    }
    $date = Get-Date -format "HH:mm tt"

    New-AzureRmResource -Location $location -Properties $PropertiesObject -ResourceName "$($webAppName)/$($vnet.Name)/primary" -ResourceType "Microsoft.Web/sites/virtualNetworkConnections/gateways" -ApiVersion 2015-08-01 -ResourceGroupName $resourceGroupName -WarningAction silentlyContinue -Force

}

Enjoy
Comment: Was just stuck with this for 2 hours. Thanks!


LINQ Case statement within Count

Question: Can you help me translate this sql into Linq please:
select
    count(case when t.TypeID = 1 then t.TypeID end) as a,
    count(case when t.TypeID = 2 then t.TypeID end) as b,
    count(case when t.TypeID = 3 then t.TypeID end) as c
from myTable t

I've searched the internet and found some similar sql but nothing that fits this scenario.  Is it possible?
Thanks
Answer: I think you want something like this
var query = new
            {
              a = (context.MyTable.Where(t => t.TypeID == 1).Count(),
              b = (context.MyTable.Where(t => t.TypeID == 2).Count(),
              c = (context.MyTable.Where(t => t.TypeID == 3).Count(),
            }

Edit - If you want it all in one query you could do this:
var query = from x in context.MyTable
            group x by 1 into xg
            select new
            {
              a = xg.Where(t => t.TypeID == 1).Count(),
              b = xg.Where(t => t.TypeID == 2).Count(),
              c = xg.Where(t => t.TypeID == 3).Count(),
            };

Comment: You're absolutely right, it had occurred to me just after i posted that it would be easier to use extension methods.  Thanks... i'll mark it as the answer as soon as it'll let me

LINQ Case statement within Count


Necessary condition of $|\sum a_n|=\sum |a_n|$

Question: Let $A\in M_{n\times n} (\mathbb{R})$ in which each entry is positive.
Let $v$ be a nonzero vector in $\mathbb{C}^n$ where $v_k\neq 0$
Suppose $|\sum_{j=1}^n A_{kj} v_j|=\sum_{j=1}^n |A_{kj} v_j|$.
Then, how do i prove that "there exist nonnegative real numbers $c_1,...,c_n$ and a nonzero $z\in \mathbb{C}$ such that $A_{kj}v_j=c_j z$"?
If i take $d_j = \frac{v_j \overline{v_k}}{|v_k|^2}$, then $v_j=d_j v_k$ for all $j$, but i'm not sure if $d_j$'s are all nonnegative real numbers..
Comment: What does it mean for a complex number to be positive?  Do you mean that $A\in M_{n\times n}(\mathbb{R})$?
Comment: In some contexts we're interested in complex numbers with positive real component (i.e. in the right half-plane of $\mathbb{C}$).  But honestly I've never heard anyone use the term "positive complex number" before in any context.
Comment: @vadim123 Isn't it usual to say 'positive complex number' to mean positive real? If you don't like it, i'll edit it. I just wanted to emphasize that the field is $\mathbb{C}$
Comment: Note that $A$ and $v$ are relevant here only for the $n$ numbers $A_{k,j}v_j$. So you might simplify the question by giving just those values a name. Not only could you then remove the (matrices) tag, but you'd be a lot closer to a solution of the problem.
Comment: I don't know in which context you are working on this problem. If it is for research purpose, you may be interested looking at Perron-Frobenius theory, which is quite much all about these kind of objects and relations.
Answer: You have an (extended) triangle inequality where actually equality holds.  That means that all the elements ($v_j$) are nonnegative multiples of each other.  You could prove this by induction on $n$, or using Cauchy-Schwarz.


how can i stop some words/letters from being swapped in php?

Question: I am using php to swap text from one textarea and display in another, and most of it works, but sadly some parts dont.
I am using str_ireplace and then so far, 60 different words, with many more to come. A couple of examples of my problem are:
old - auld
old man - gadgie

if you look above, the first word is the unswapped and the second is the new word. However, if i put old man in the text, it would come as "auld man" instead of "gadgie".
I know that this may be because i have declared "old-auld" before "old man - gadgie"
but another problem is that:
yes - aye
no - nar

Again, first word is original, second is after swap. If i were to write "yesterday" it would be displayed "ayeterday" or if i had "nose" it would be "narse"
Is there anyway to change ONLY "yes" on its own and not if it is part of another word?
And is there any way to have "old man" and "old" as separate replacements?
Hope that makes sense
My code for str_ireplace:
<form method="POST" action="post.php" >
<textarea name="status2" cols="50" rows="5"/>
<?php echo str_ireplace(array  ('old','awkward','all','again','behind','along','alright','hello','among','children','yes','child','kids','food','barnard castle','beer','book','blow','beautiful','bird','burst','brown','burn','boots','came','nice','cold','church','clothes','stick','dirty','clever','cloth','cow','crow','stool','crown','pigeon','dad','darlington','dead','do','devil','dont','do not','durham','down','drown','punch','ditch','eye','fall','trouble','condition','four','stupid','old man','go','going','jumper','give over','grandad','hold','get away','home'),
array ('auld', 'aakwad', 'aall','agyen','ahint','alang','alreet','alreet','amang','bairns','aye','bairn','bairns','bait','barney','beor','beuk','blaa','bonny','bord','borst','broon','bourn','byeuts','cam','canny','card','chorch','claes','clag','clarty','clivvor','cloot','coo','craa','cracket','croon','cushat','da','darlo','deed','dee','deil','divvent','divvent','dorham','doon','droon','dunsh','dyke','Eee','faa','fash','fettle','fower','gaumless','gadgie','gan','gannin','ganzie','giveower','granda','haad','hadaway','hyem'),$status); ?>

</textarea>

As i said, there are 60+ words.
I didn't add my code initially as i thought it may not have been relevant.
Comment: Some actual code would be a big help.
Comment: `preg_replace`? maybe, you're gonna want regex to check for either a space after each of these words, or the end of the line
Comment: i just tried using preg_replace. i used this preg_replace("/(\b)yes(\b)/", "aye", $status); but it still shows 'ayeterday'
Comment: now i feel like an idiot! i didnt realise i already had a replace when i was testing, so no matter what i changed it done it wrong, now i have removed it and used preg_replace it works brilliant
Answer: About first part. You should replace more specific word first. i.e "old man", and then "man" or use strtr
<?php
$trans = array("h" => "-", "hello" => "hi", "hi" => "hello");
echo strtr("hi all, I said hello", $trans);
?>
The above example will output:
hello all, I said hi

About the whole words. You may look to regexps (and \b in particularly)


Question regarding cartesian product

Question:
Suppose $\bigl\{(x,y)\mid x^2+y^2<1\bigr\}$ is a subset of $\Bbb R\times\Bbb R$, where $\Bbb R$ is the set of real numbers.
Is the given set also the cartesian product of two subsets of $\Bbb R$?

Does
$$X=\{x\in\Bbb R\mid 1>x>-1\}\\Y=\left\{y\in\Bbb R\mid\left((\forall x\in X)\left[-\sqrt{1-x^2}<y<\sqrt{1-x^2}\right]\right)\right\}$$
define infinitely many pairs $(x,y)$ for given $x$, such that $y$ suffices the condition in $Y$?
Also, could there be two other sets (except of just, in this case, replacing "$x$" with "$y$", "$y$" with "$x$", "$X$" with "$Y$" and "$Y$" with "$X$"), whose cartesian product yields the given subset?
Comment: Very Clever. Copied the images. How much time you put in doing it?
Comment: @MonK I can't find those images on other sites by using google search-by-image. And they probably won't be taken from math.stackexchange since they're not rendered in LaTeX. So I'm not certain that they've been copy-pasted.
Comment: No, I think you also din't get it. He has an image on his system. He took snip images out of it, put it over here in places in bits and pieces :)
Comment: Welcome to Math.SE! What are your thoughts on the problem so far? What have you tried? The more we know about your efforts and thinking, the easier it will be for us to help you (and the more likely it will be that people will *want* to help you).
Comment: Why do you think I copied them? I used Word, Snapping Tool (in windows 7) and microsoft Paint to save the pics. Anyhow, this problem is given in the first set of exercises about cartesian products, so really I've no experience about it, Cameron Buie.
Comment: "A function f from X to Y is a subset of the Cartesian product X × Y subject to the following condition: every element of X is the first component of one and only one ordered pair in the subset.[4] In other words, for every x in X there is exactly one element y such that the ordered pair (x, y) is contained in the subset defining the function f." (from wikipedia page "Function (mathematics)") - how then could you have functions, like y=sqrt(1-x^2), if none of them (X, Y) is to be defined in terms of the other? That is, what do you mean by "simple pair"?
Answer: If you define $Y$ that way, then $Y=\{0\}$. That's because when $y\neq 0$, with $-1<y<1$, then for $x=\sqrt{1-y^2}$, $x\in X$ it is obviously not true that $-\sqrt{1-x^2}<y<\sqrt{1-x^2}$. So $y\notin Y$.
If $U=X\times Y$ then if $(x_1,y_1),(x_1,y_2),(x_2,y_1)\in U$ then $(x_2,y_2)\in U$. When $X,Y\subseteq \mathbb R$, this can be read as:

If three corners of an "axis-aligned" rectangle are in $U$, then the fourth corner is, too.

Now, $U=\{(x,y)\mid x^2+y^2<1\}$ is a unit disk. Can you think of an axis-aligned rectangle with three points inside $U$ but the fourth outside?
Comment: @availanche Nope, there is such a rectangle. Try again.
Comment: Such a rectangle does not exist, because the fourth vertex shares coordinates of the already existing 3 vertices, which are, at any order, define a point that is not outside the unit disk. I wanted to form ordered pairs, where, if the first coordinate is x, the second coordinate is limited by -sqrt(1-x^2) and sqrt(1-x^2). Does the cartesian product of two closed intervals always geometrically correspond to a rectangle?
Comment: Sorry, you are still wrong. Draw a circle. Can you create a rectangle with three points inside the circle and the fourth outside?
Comment: Well, yes, I succeeded in finding infinitely many such surprising rectangles, in regard to the unit circle: take the points (0.5, -0.5), (0.5, -0.7), (g, -0.5) and (g, -0.7), where -(sqrt (51))/10>g>-(sqrt(3))/2...Oh I see, in regards to "If three corners of an "axis-aligned" rectangle are in U, then the fourth corner is, too." theorem, it means that a circle cannot be the result of any cartesian product, hence disks cannot be so as well.
Comment: You can just use $(0,0)$, $(x,0)$, $(0,y)$ and $(x,y)$ with $x,y\in(-1,1)$ and $x^2+y^2>1$....
Comment: It is clear that if I do it, I could take any real numbers x,y, where 1>|x|>1/sqrt(2) and 1>|y|>1/(sqrt2), where 1/sqrt(2) is 0.707, to the precision of 3 digits after the decimal point (i.e., for example, take any values of x,y less than 1 and greater than 0.71 in absolute value).
Comment: Yes, but you really only need one such rectangle to show that $U$ is not $X\times Y$ for any sets $X,Y$.
Answer: The given set is not cartesian product of two subsets X,Y of the reals;
Supoosing X,Y are subsets of the reals whose Cartesian product is the unit disk (excluding the unit circle), it also means that their cartesian product corresponds to an axis-aligned rectangle.
In this case, the following theorem holds: "If three corners of an "axis-aligned" rectangle are in U, then the fourth corner is, too" (worded by Thomas Andrews), where U=XxY.
But, in case of circle with radius r, one may choose 3 points, each of which is a subset of the cartesian product of X and Y: (0,0), (x,0), (0,y) and (x,y), where x,y belong to the opened interval (-1,1), and x^2+y^2>r^2 (specifically, it would mean that at least one of |x|, |y|, must be greater than r/sqrt(2), otherwise their sum cannot be greater than r^2).
Therefore, we deduce that the given disk (x^2+y^2<1) cannot be the cartesian product of two subsets of R.
Comment: It would be better and clear if you have used images in your answer too :)
Comment: Here is some relevant demonstration from desmos (finding such configuration for the unit circle itself: https://www.desmos.com/calculator/yglrzwlmkt

Question regarding cartesian product


Import google service play appears with other file

Question: Im just a beginner im  trying to import the google play service lib but its importing some more file not importing as a 1 single library file
How to get the library file as a single library file
https://i.stack.imgur.com/tA87w.png
Comment: It's not a single file, you don't. What IDE do you use?
Comment: eclipse please check the image link given below how you can understand what im asking @EugenPechanec
Comment: Scroll away from samples till find lib
Comment: but how its automatically taking all files @minafawzy
Comment: i scrolled but there are no lib @minafawzy
Comment: follow this tutorial https://code.tutsplus.com/tutorials/integrating-google-play-services-on-android--cms-19828
Comment: or this Video https://www.youtube.com/watch?v=NCGYxe4vbYU , all you need to import google play service library in project name
Answer: Change the import root to C:\Eclipse\sdk\extras\google\google_play_services\libproject and import google-play-services_lib project. Check Copy projects into workspace as you want to have a stable copy in your project when you update the SDK.


Unrecovered read errors on Linux RAID10 device

Question: I have an HP DL380p Gen8 running Ubuntu 14.04 and apparently it's been having some trouble with its RAID10 filesystem for almost a month, despite everything seeming to be okay otherwise. I'm seeing a lot of these messages in dmesg/syslog/etc. though the hex values in the Read lines do vary a bit.
Nov 18 08:09:25 server03 kernel: sd 2:0:0:1: [sdb]
Nov 18 08:09:25 server03 kernel: Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
Nov 18 08:09:25 server03 kernel: sd 2:0:0:1: [sdb]
Nov 18 08:09:25 server03 kernel: Sense Key : Medium Error [current]
Nov 18 08:09:25 server03 kernel: sd 2:0:0:1: [sdb]
Nov 18 08:09:25 server03 kernel: Add. Sense: Unrecovered read error
Nov 18 08:09:25 server03 kernel: sd 2:0:0:1: [sdb] CDB:
Nov 18 08:09:25 server03 kernel: Read(16): 88 00 00 00 00 03 f8 48 f5 38 00 00 00 80 00 00

The iLO and hpssacli both report all disks are fine and the filesystem is not read-only. The /dev/sdb device is a RAID10 using the server's RAID controller, consisting of 20 x 900 GB disks.
This is a production server and while I've rebooted it once to try to clear this up, I'm reluctant to try an fsck without trying to determine what these messages mean when there are no other apparent issues.
So, any thoughts on what might be wrong here?
Comment: That disk is plainly _not_ fine.
Comment: Something is wrong, certainly, but so far everything I've looked at indicates nothing is wrong from a hardware perspective. I'll update the post with the RAID disk layout. Looking for other suggestions to narrow down the problem, whether it may be in the RAID itself or one of the disks and the controller just can't detect it for some reason.
Answer: Okay, I'll answer with the normal troubleshooting techniques, but here's my disclaimer:

I really don't advocate running Ubuntu on bare metal hardware; especially HP ProLiant systems.
The support ecosystem is just not there for Ubuntu when it comes to HP systems, drivers, monitoring and value-add software.
The HP firmware packages are not built for Ubuntu, so god knows what firmware revisions you're running on.
Ubuntu tends to introduce some quirky bugs that I never see with more commercial Linux distributions.

Please provide the following in your question or a separate pastebin.

I'd like the output of hpssacli ctrl all show config.
I'd like the output of hpssacli ctrl all show config detail.
Please give the output of df -h and fdisk -l.
Please post the output of lsscsi.

Since you're on Ubuntu, you probably don't have the HP Management Agents installed. While hpssacli can provide a spot check of the array health, the hp-snmp-agents package is what provides actual continuous monitoring.
If you do have some of the HP Health Agents installed, please run hplog -v to extract the IML log.

My guess is that you're running an HP ProLiant DL380p Gen8 25-bay SFF server. Unpatched, many of those units suffered from Smart Array controller and controller cache failures. There are also some critical expander backplane updates that need to be run on that platform.
Comment: I have pasted all requested output at http://pastebin.com/xv37rawG. I do need to review the firmware on this server and the others in the database cluster. I am curious, though, as to your further thoughts on Ubuntu and HP. We could discuss that through a private channel if you're so inclined.
Comment: Did you know you lost disks in July and November?
Comment: Yes, via email alerts from the iLO, and we had our on-site people replace them with new ones from HP.
Comment: The RAID controller should be on [firmware 6.68](http://h20566.www2.hpe.com/hpsc/swd/public/detail?sp4ts.oid=5194969&swItemId=MTX_96d4648b5e214cbb8c904dfda7&swEnvOid=4103#tab-history)... Everything else looks good. this may be an Ubuntu or `hpsa` driver problem. Are you on a current kernel?
Comment: No, It's on kernel 3.13.0-32 while the latest 14.04 kernel in the repo is 3.16.0-55. It's a bit of an ordeal to schedule an upgrade of the server since it's in a live 10-node database cluster.
Answer: I ended up fixing this by unmounting and recreating the filesystem and I've not seen any error messages since re-enabling the database application on the server, even after it recreated nearly 4 TB of data from other cluster nodes. (I'm wondering if the past disk replacements in this server somehow contributed to the filesystem getting corrupted.)


How can I modify a Python traceback object when raising an exception?

Question: I'm working on a Python library used by third-party developers to write extensions for our core application.
I'd like to know if it's possible to modify the traceback when raising exceptions, so the last stack frame is the call to the library function in the developer's code, rather than the line in the library that raised the exception. There are also a few frames at the bottom of the stack containing references to functions used when first loading the code that I'd ideally like to remove too.
Thanks in advance for any advice!
Answer: You can remove the top of the traceback easily with by raising with the tb_next element of the traceback:
except:
    ei = sys.exc_info()
    raise ei[0], ei[1], ei[2].tb_next

tb_next is a read_only attribute, so I don't know of a way to remove stuff from the bottom.  You might be able to screw with the properties mechanism to allow access to the property, but I don't know how to do that.
Comment: Any idea how to manage this in python 3? I can't get this to work myself.
Comment: The equivalent of this in Python 3 would be: `raise ei[0](ei[1]).with_traceback(ei[2].tb_next)`
Comment: That's not what he's asking. The causal chain was never mentioned. This guy wants to change, what is shown in the stack trace... put in some extra "virtual calls" etc.
Answer: Take a look at what jinja2 does here:
https://github.com/mitsuhiko/jinja2/blob/5b498453b5898257b2287f14ef6c363799f1405a/jinja2/debug.py
It's ugly, but it seems to do what you need done. I won't copy-paste the example here because it's long.
Comment: At the time that I write this, the above link gives a 404 error.
Comment: Here's the current link: https://github.com/pallets/jinja/blob/master/src/jinja2/debug.py
Answer: Starting with Python 3.7, you can instantiate a new traceback object and use the .with_traceback() method when throwing. Here's some demo code using either sys._getframe(1) (or a more robust alternative) that raises an AssertionError while making your debugger believe the error occurred in myassert(False): sys._getframe(1) omits the top stack frame.
What I should add is that while this looks fine in the debugger, the console behavior unveils what this is really doing:
Traceback (most recent call last):
  File ".\test.py", line 35, in <module>
    myassert_false()
  File ".\test.py", line 31, in myassert_false
    myassert(False)
  File ".\test.py", line 26, in myassert
    raise AssertionError().with_traceback(back_tb)
  File ".\test.py", line 31, in myassert_false
    myassert(False)
AssertionError

Rather than removing the top of the stack, I have added a duplicate of the second-to-last frame.
Anyway, I focus on how the debugger behaves, and it seems this one works correctly:
"""Modify traceback on exception.

See also https://github.com/python/cpython/commit/e46a8a
"""

import sys
import types

def myassert(condition):
    """Throw AssertionError with modified traceback if condition is False."""
    if condition:
        return

    # This function ... is not guaranteed to exist in all implementations of Python.
    # https://docs.python.org/3/library/sys.html#sys._getframe
    # back_frame = sys._getframe(1)
    try:
        raise AssertionError
    except AssertionError:
        traceback = sys.exc_info()[2]
        back_frame = traceback.tb_frame.f_back

    back_tb = types.TracebackType(tb_next=None,
                                  tb_frame=back_frame,
                                  tb_lasti=back_frame.f_lasti,
                                  tb_lineno=back_frame.f_lineno)
    raise AssertionError().with_traceback(back_tb)

def myassert_false():
    """Test myassert(). Debugger should point at the next line."""
    myassert(False)

if __name__ == "__main__":
    myassert_false()

Comment: excellent - this makes it possible to write a function decorator that removes itself from a stack trace when an exception occurs.
Answer: You might also be interested in PEP-3134, which is implemented in python 3 and allows you to tack one exception/traceback onto an upstream exception.
This isn't quite the same thing as modifying the traceback, but it would probably be the ideal way to convey the "short version" to library users while still having the "long version" available.
Answer: What about not changing the traceback?  The two things you request can both be done more easily in a different way.

If the exception from the library is caught in the developer's code and a new exception is raised instead, the original traceback will of course be tossed.  This is how exceptions are generally handled... if you just allow the original exception to be raised but you munge it to remove all the "upper" frames, the actual exception won't make sense since the last line in the traceback would not itself be capable of raising the exception.
To strip out the last few frames, you can request that your tracebacks be shortened... things like traceback.print_exception() take a "limit" parameter which you could use to skip the last few entries.

That said, it should be quite possible to munge the tracebacks if you really need to... but where would you do it?  If in some wrapper code at the very top level, then you could simply grab the traceback, take a slice to remove the parts you don't want, and then use functions in the "traceback" module to format/print as desired.
Comment: I downvoted, here's why: this answer offers good advice, but it doesn't actually answer the question.
Comment: @BryanOakley: if advice is very relevant, and if it's too big to fit into a comment, it belongs in an answer. It's either that, or keep the knowledge away from SO, which would be very sad. So I don't think downvoting in these cases is appropriate.
Comment: @max: I suppose you're right. I find myself answering questions like this as well -- "you can do that, but why.... here's something else to think about". Thanks for holding me accountable. I'd change my vote if I could.
Comment: Must disagree with the argument "[it] won't make sense since the last line in the traceback would not itself be capable of raising the exception".  Take the line  `a += 1`.   It doesn't look "capable" of raising an exception (doesn't contain the word `raise`).  But it will, if `a` is of type `str` - and the exception will make sense.  Now suppose `a` is an instance of some custom class with an `__iadd__`, and that, just like `str`, it's nonsensical for the operand to be an `int`. With the same syntax, the traceback will now point to a deeper  location rather than the line where the mistake is.
Comment: Downvoting because I need to modify the stacktrace for valid reasons only to find this. Question: "how do you modify traceback". Answer: "you don't". I'd instead suggest a way to do it while at the same time strongly stressign you shouldn't.
Comment: @jez, with an 8 year old post I can't be 100% sure what I meant, but I suspect I could have better phrased it as merely "... would not *appea* capable of raising the exception". With your "a += 1", one would not expect to find, say, a KeyError being raised. If you got a traceback pointing to that line but with the lower levels (which did raise the KeyError) removed, troubleshooting would become much harder. Better to leave it (noisy though it is), showing explicitly how an apparently innocuous line like "a += 1" could have failed in that manner. But... 2009! :-)
Comment: I'm okay with this answer offering an alternative, but I downvoted because I don't like that answer also doubts the necessity of doing the original thing -- I feel like a comment would be more appropriate for that.
Comment: With that said, it's perfectly reasonable to black-box certain parts of code that you would expect to run perfectly, so that you can focus more on the remaining traceback. Besides, if I'm allowed to catch and discard an entire exception, can't I discard just part of it?
Comment: Horrible advice for cases, when we have complex graphs.
Answer: For python3, here's my answer. Please read the comments for an explanation:
def pop_exception_traceback(exception,n=1):
    #Takes an exception, mutates it, then returns it
    #Often when writing my repl, tracebacks will contain an annoying level of function calls (including the 'exec' that ran the code)
    #This function pops 'n' levels off of the stack trace generated by exception
    #For example, if print_stack_trace(exception) originally printed:
    #   Traceback (most recent call last):
    #   File "<string>", line 2, in <module>
    #   File "<string>", line 2, in f
    #   File "<string>", line 2, in g
    #   File "<string>", line 2, in h
    #   File "<string>", line 2, in j
    #   File "<string>", line 2, in k
    #Then print_stack_trace(pop_exception_traceback(exception),3) would print:
    #   File "<string>", line 2, in <module>
    #   File "<string>", line 2, in j
    #   File "<string>", line 2, in k
    #(It popped the first 3 levels, aka f g and h off the traceback)
    for _ in range(n):
        exception.__traceback__=exception.__traceback__.tb_next
    return exception

Comment: How do you use this? Before raising, an exception's `__traceback` is `None`, and after raising, I see no way for the raising code to modify it.
Answer: This code might be of interest for you.
It takes a traceback and removes the first file, which should not be shown. Then it simulates the Python behavior:
Traceback (most recent call last):

will only be shown if the traceback contains more than one file.
This looks exactly as if my extra frame was not there.
Here my code, assuming there is a string text:
try:
    exec(text)
except:
    # we want to format the exception as if no frame was on top.
    exp, val, tb = sys.exc_info()
    listing = traceback.format_exception(exp, val, tb)
    # remove the entry for the first frame
    del listing[1]
    files = [line for line in listing if line.startswith("  File")]
    if len(files) == 1:
        # only one file, remove the header.
        del listing[0]
    print("".join(listing), file=sys.stderr)
    sys.exit(1)

Comment: The focus here is on 'simulating' - this does not change the traceback of the exception thrown (by `sys.exit`).
Comment: Yes, but it shows how to modify tracebacks. A little thinking of your own does not hurt ;-)
Comment: Quite a number of people have invested quite a bit of thinking into that, and I have not found a working solution yet. So please don't imply that your answer + "a little thinking" will easily answer the OP's question.
Comment: The accepted answer was about "not changing the traceback". My answer assumed that also, and then this is simply some fiddling with a list of strings, which is easy to do instead of traceback modification.
Comment: Yes, the accepted answer did state that. But both the question title and the text expressedly state the opposite, wanting to "modify the traceback".


how to build a function that holds some condition

Question: I'm not a mathematician but I have a question. I have some conditions that I want to create a function which holds that condition, Is there any way to build a mathematical function to satisfy this condition.The condition I need the function to hold is
$$
\frac{f(x + 2) + f(x)}2 \ge f(x + 1)
$$
I think I asked my question wrong,
I have a set of random and strickly increasing numbers, now I want to use some mathematical way to make them appear convex just like funxtion x^2, so I needed the function to satisfy the condition I noted above, but the real problem is that I want to make thease numbers to look convex, so is there anything I can use??
Thank you all
Comment: Um..... $f(x)=0$?
Comment: @John oh my god, I didn't even pay attention to equal to part of the $\ge$. This *feels* wrong though. :p
Comment: Take any convex function.
Comment: @TZakrevskiy OP says (s)he isn't a mathematician. That sentence isn't even borderline helpful.
Comment: great catch though. upvoting your comment
Comment: @Mahdi Since there are so many functions that satisfy your property; if you give us a little more context we might be able to help you pick a suitable one.
Comment: @DanielV Look, I have a set of positive integer values, something like {1, 3, 12, 13, 15, 18, 100, 120, ...}, there isn't any kind of relation between these numbers, they are completely random, now if you draw them on paper as values {(1, 1), (2, 3), (3, 12), (4, 13), (5, 15), ...} you see that the curve which passes through these points can be referred as a strictly increasing function, but it is somehow noisy like a rotated variation of sin function, I want to remove these noises and make it smooth, so I thought something like  y = x^2 might be good if I could make the points to fit it.
Comment: @DanielV I though of 2^x (x being elements in my number set) and it will do the job but the problem is that my number set ranges from 1 to near 20 billion and computing 2^20000000000 cannot be done easily, so I'm looking to another function that fits in my condition..
Answer: $f(x) = x^2$ will do the job.
\begin{align}
\frac{f(x+2)+f(x)}{2} &= \frac{(x+2)^2 + x^2}{2} \\
 &= \frac{x^2 + 4x + 4 + x^2}{2} \\
 &= x^2 + 2x + 2  \\
 &> x^2 + 2x + 1  \\
 &= (x+1)^2  \\
 &= f(x+1).  \\
\end{align}
Comment: Also any sum of suitable functions. So for instance $f_1(x)=c, f_2(x)=x^2, f_3(x)=exp(x)$ will all work, and so will, say $f_4(x) = c + x^2 + exp(x)$.
Comment: It is useful to note, as pointed out by John, that any $f(x) = c$ is *also* valid.
Comment: A sinusoidal wave with a period that is an integer also satisfies this.
Answer: This condition is satisfied by any convex function, i.e., a function satisfying
$$
f\big(tx+(1-t)y\big)\le tf(x)+(1-t)f(y),
$$
for all $t\in (0,1)$.
If $f$ is twice differentiable, then it is convex if and only if
$$
f''(x)\ge 0,
$$
for all $x$.
HENCE, try a function with non-negative 2nd derivative.
Answer: Your condition says that the function's value at $x+1$ is less than the average of its values at $x$ and $x+2$. In other words, at $x+1$, the function value must be below the "straight line"  values between $x$ and $x+2$.
Functions with this sort of property are called "convex". Basically, this just means that the graph of the function looks "hollow" when viewed from above.
Many functions have this property. The simplest interesting one I can think of is $f(x) = x^2$.
Answer: There are many functions for which this condition holds, in general for function $f(x)$, and $0\leq\theta\leq 1$,  if:
$$\theta f(z)+(1-\theta) f(y)\geq  f(\theta z+(1-\theta)y)$$ then the function is called convex.
In your case, $\theta=1/2$, $z=x+1$, $z=x$.
You can find a list of convex functions here.