Find minimum singular value in a sorted array

Question: A sorted array is passed to my method and i have to find the minimum singular value. If no such value is found the method returns 0.
I have created two versions of this method. In the first version, I iterate trough the array twice which works fine but there has to be a way to find the value with one iteration.
In the second version, I iterate through it once but i need it fixed so, that it works if the last index of the array is my minimum singular value e.g {1, 1, 2, 2, 3}.
//First version with two iterations
public int findMinimumSingularValue(int[] array) {

    for (int i = 0; i < array.length; i++) {
        int countOccurence = 0;
        for (int j = 0; j < array.length; j++) {
            if (array[i] == array[j]) {
                countOccurence ++;
            }
        }
        if(countOccurence == 1) {
            return array[i];
        }
    }
    return 0;
}

I've tried to implement it with only one iteration, but couldn't get it to work. Only the first version is up for review, but I'll leave my attempt at improvement here to illustrate what I have in mind:

//Second version with one iteration which needs to be fixed
public int findMinimumSingularValue(int[] array) {
    if(array.length == 0) {
        return 0;
    }
    int isNotUnique = array[array.length - 1];
    for (int i = 0; i < array.length; i++) {
        if (array[i] != array[i + 1] && array[i] != isNotUnique) {
            return array[i];
        }
        isNotUnique = array[i];
    }
    return 0;
}

Comment: Welcome to Code Review! On this site we only review working code (which you admit your second code block is not). Have a look at the [help/on-topic] to learn about what is on/-off-topic here.
Comment: @Graipher True, but since they're both versions of the same program, one could argue we only review the first block and see the second as a pseudo-code example of what the author would prefer. IMO, this is reviewable.
Comment: @Graipher Fixed, kind-of. Fatso88, if you disagree with my edit, feel free to improve it ;-)
Comment: @Mast I see your point. Editing the question to make it explicit that only the first code is to be reviewed could help, though.
Comment: Thanks. I totally see your point there.
And thanks @Mast for your edit!
Answer:
    for (int i = 0; i < array.length; i++) {
        int countOccurence = 0;
        for (int j = 0; j < array.length; j++) {
            if (array[i] == array[j]) {
                countOccurence ++;
            }
        }
        if(countOccurence == 1) {
            return array[i];
        }
    }
    return 0;

When I look at this, the problem that I see is that you are scanning the entire array to look for duplicates.  The array is sorted!  Consider
    int i = 0;
    while (i + 1 < array.length) {
        // array[i] has a duplicate iff it is the same as array[i + 1]
        if (array[i] != array[i + 1]) {
            return array[i];
        }

        // skip to the next possible smallest value not a duplicate
        while (i + 1 < array.length && array[i] == array[++i]) ;
    }

    // figure out if the last element has no duplicate
    return (array.length == 0 || array[i] == array[i - 1]) ? 0 : array[i];

While it may look like it has nested loops, both iterate over the same variable.  So the number of comparisons is linear relative to the size of the array.
This works because the array is sorted.  All duplicates are adjacent to each other.
The ++i increments i and then returns the now incremented value.  i++ stores the value of i, then increments it, and finally returns it.  So i++ + 1 is the same thing as ++i.  Or vice versa.
class Incrementable {

    private int i = 0;

    // ++i
    public int preincrement() {
        i = i + 1;
        return i;
    }

    // i++
    public int postincrement() {
        int original = i;
        i = i + 1;
        return original;
    }

}

The two forms ++i and i++ are the equivalents of the preincrement and postincrement in this class.
So let's go through
        while (i + 1 < array.length && array[i] == array[++i]) ;

The form
while (isTrue()) ;

just keeps iterating until isTrue returns false.  It does nothing in the body of the loop, thus the empty ;.  We could also write it
while (isTrue()) {

}

But that just seems longer.
The i + 1 < array.length just keeps us from falling off the back of the array.  I.e. we never want to do array[array.length], as that's an error (attempt to access outside the array).
So the meat of the statement is the array[i] == array[++i].  On any particular iteration, this is just the same as array[i] == array[i + 1].  So long as that is true, we're still processing the same duplicate.  But replacing i + 1 with ++i has the same effect on an individual iteration and moves along.  So we have something like an array of

1, 1, 2, 2, 2, 2, 3

i = 0, array[i] = 1, array[++i] = 1, i = 1; equal so keep going
i = 1, array[i] = 1, array[++i] = 2, i = 2; not equal so stop and do the outer while
i = 2, array[i] = 2, array[++i] = 2, i = 3; equal so keep going
i = 3, array[i] = 2, array[++i] = 2, i = 4; equal so keep going
i = 4, array[i] = 2, array[++i] = 2, i = 5; equal so keep going
i = 5, array[i] = 2, array[++i] = 3, i = 6; not equal so stop and do the outer while
While i is 6, we'll drop out of the inner loop and the outer loop, because 6 + 1 is not less than array.length, which is 7.
Comment: wow! this works great. Thank you very much! I'm a little overwhelmed by this part:
while (i + 1 < array.length && array[i] == array[++i]) ;
I ran the debugger and it does exactly what you say, but why :-)
And in that case, how does i++ differ to ++i
Comment: this is great. thank you so much for your effort :-)
Comment: @fatso88 Look-up the terms pre-increment and post-increment ;-)
Answer: (NOTE: While I was posting this answer: @mdfst13 posted his answer, very nice!
I especially like that nested while loop bit. )
I'm not a java programmer, but here is something in Javascript
function minUnique(set) {
    for (var i = 0, last, next = set[1]; i < set.length; next = set[i + 2], i++) {
        if (last === undefined && set[i] !== next) {
            return set[i];
        } else if (last !== undefined && next !== undefined && next !== set[i] && last !== set[i]) {
            return set[i];
        } else if (set[i] > last && next === undefined) {
            return set[i];
        }
        last = set[i];
    }
    return 0; // nothing was found
}

This is essentially a problem with three phases

first value
mid values, those that are not the first and not the last.
and the last value.

We simply need to test, for each phase, and do our comparisons in each branch of the if else statements.
My solution rely on some variables setup in the for loop initialization.
"last" is the last value seen,
"next" is the next value in the set
and set[i] is the current value.
if "last" is undefined, it's our first time through the for loop, and if set[0] is not equal to "next", we have found the lowest unique value the first time through the loop, if true we return set[i];
if "last" is not undefined, and "next" is not undefined, we are midstream. Now we simply need to check if "last" is not the same as set[i] and not equal to "next", if true we return set[i];
if "next" is undefined, we are on our last iteration, we need to simply check if set[i] is not equal to "last", if true we return set[i]
At the tail end of every iteration of the loop, we update "last" to set[i], for use in the next iteration.
otherwise, when/if we complete the for loop without returning, there must have been no unique values, so we just return 0.
Comment: You've presented an alternative approach without reviewing the code presented by the author. On Code Review, all answers should contain a review.


How to select the principal investigator in a group?

Question: If a group of researchers collaborating on a grant proposal, how the principal investigator can be selected? The researcher with the idea, the one who invited other researchers, the most well-known researcher in the group, the researcher with highest academic rank (e.g., full professor), etc? Should the group decide? What if the first researcher would like to be the PI?
Comment: In my experience, the only one who is enough qualified but not fast enough to make up an excuse to avoid being the PI :-)
Comment: @MassimoOrtolano, or play a round of poker with the loser becoming the PI. Something like that.
Comment: @MassimoOrtolano. Brilliant.
Comment: @Buffy: There should at least be a punishment of some type for everyone trying to get out of it. Perhaps Russian Roulette with a toy cap pistol -- the "winner" (actually the loser) becomes PI, but "losers" (actually the winners) get a very loud bang in their ear.
Answer: I'm not sure why you are asking. But if it is because there are disputes within the group it might be best, overall, to find a different group. Clashes at that level don't portend success, but rather a lot of frustration.
But all of your suggestions are valid (as is that of user Massimo Ortolano). If it is obvious that one of you would give the work an advantage for publication, do that. If one of your junior members needs a boost in reputation, do that (sorry Massimo). Anything can work as long as there is buy in from the group. If someone has a strong inclination to do it and no one else objects, he or she would be a good choice as they will likely commit to getting things done and organized. If someone has a history of successful grant writing, another good choice, unless the granting institution has rules limiting repeat grants.
But the most important quality is agreement.
Comment: I was thinking if there is a common way of doing it. How much would being a PI help a junior member compare to being a Co-PI?
Comment: @ThomasLee, it's impossible to say. But you have to start somewhere and it is good to do it with mentorship.


Can someone keep objects bought with money not obtained honestly?

Question: If someone got money not honestly ex:he did surveys online for money but didn't answer the questions honestly and he doesn't know exactly whom he got the money from since each time the survey was from someone else so he has no way of knowing whom to repay is he allowed to keep the objects he got from using this money if he for sure doesn't know whom to pay it back to?
Comment: related: http://judaism.stackexchange.com/questions/30429/how-can-one-make-repentance-for-things-he-cant-remember
Comment: Half of this is a duplicate of http://judaism.stackexchange.com/q/36082
Answer: The Mishna states that if one stole a large beam and used it as the structure for a house, if we asked people to tear down the whole house to return the beam, no one would ever repent from theft. Instead, we say pay the original owners for the value.
If someone stole cash and used it to buy a ... let's say toaster; again, we allow the thief to use the toaster, just pay back its value. (Now some may feel better not staring at the toaster and having guilt trips everyday, that's your call. But the Gemara tells the story of the gangster who had thought about making amends when his wife said "even your clothes are ill-gotten gains!" -- that made him decide it was too hard, and he went back to being a gangster.)
If one can reasonably ascertain who the victim of theft/cheating was, the money should be paid back to them. If not, the goal is to give the money so that it's likely a victim could get some benefit from it. In Talmudic times you could work on a public water system that everyone -- not just the poor -- would benefit from. (Unless you were certain you only robbed the poor ...) A modern-day equivalent might be a public library or a volunteer fire department, though Rabbi Moshe Feinstein suggested mikvahs.


Non-linear first order ODE

Question: This is a two part question. On one hand, I am trying to find positive solutions of the following equation:
$$1-\frac{d}{dx}f=\frac{f\log(f)}{x}$$
for $x>1$.
If that is not possible, I would at least like to know their behavior as $x\to\infty$. I don't think the above has a simple closed form solution, but I think it would be very useful to have a set of arbitrarily close approximations that can be calculated in some systematic fashion. The only thing that I have managed to do so far is bring the equation in the following form:
$$e^ye^{-u}=u+\frac{du}{dy}$$
where $y=\log(x)$ and $u=\log(f)$, and then define recursively
$$e^ye^{-u_n}=u_{n+1}+\frac{du_{n+1}}{dy}$$
which is solved by $u_{n+1}=Ce^{-y} + e^{-y}\int_0^y e^{2y'}e^{-u_n}\,dy'$. The problem is that it is impossible to calculate the sequence $\{u_n\}$ past the first few elements. At least, this shows what I am trying to do--find a series (of the appropriate kind) approximation to the actual solution.
As to the asymptotic behavior, I feel it should be given by the solution of $$1=\frac{f_0\log(f_0)}{x}$$ (related to the inverse Lambert W function). My intuitive thinking is that $$\frac{df_0}{dx}=\frac{f_0\log(f_0)}{x}\frac{1}{\log(x)+1}\sim\frac{f_0}{x}=\frac{1}{\log(f_0)}\sim0$$
for large $x$, thus $f_0$ roughly satisfies the differential equation.
I have close to none experience with non-linear ODEs, so any help or pointers to the correct literature would be appreciated.
Comment: Maple can't solve it so I doubt there is a closed form solution but if you just want to know the behavior why don't you solve it numerically?
Comment: I would like to use the analytical approximation to the actual solution (if there is one), or at least justify the use of $f_0$. In general, since I know very little about the subject, I would like to know what could be done with equations of this form.
Answer: Setting $x:=z^{-1}$ and $f:=e^u$ your differential equations is transformed into
$$z^2\mathrm{d}u=(zu-e^{-u})\mathrm{d}z$$
The curves integrating the above differential relation define a regular foliation along the line $\{z=0\}$. This line is such a solution curve. Therefore $u(z)$ cannot be asymptotic to a finite value (if any) as $z\to0$. On the contrary the inverse solutions $u\mapsto z(u)$ define analytic solutions. Pluging $z(u):=\sum_{n=0}^{\infty}a_nu^n$ you can solve for $a_n$ and derive a convergent power series, which is well approximated by the truncated Taylor polynomials. For instance depending on the initial data $a_0=z(0)$ we find
$$a_1=-a_0^2  ~\mathrm{and}~  a_2=a_0^2(a_0-1)$$
PS: the curve $\{f_0(x)\log f_0(x)=x\}$ you mention is the locus of "horizontal" tangency of solution curves, so can't relate to the asymptotic behavior of solutions $x\mapsto f(x)$ as $x\to \infty$ since the more $x$ goes to $\infty$ the more "vertical" the solution curve becomes.

Non-linear first order ODE


Is there a function where if you modify a certain cell, the contents of another cell in the same column will be cleared?

Question: E.g. If the range of cells is A1:A20 and the independent variable is A5.
If A5 is modified then the content of A1 to A20 except for A5 will be cleared.
Comment: Have you googled anything.
Comment: Welcome to [Web Applications Stack Exchange](https://webapps.stackexchange.com/tour). See [How do I ask a good question?](https://webapps.stackexchange.com/help/how-to-ask)
Comment: Hi and welcome. _Is there a function_ A built-in function will not clear the contents of a cell/range. The answer by @doubleunary is a script, and that's your only option to physically delete the contents of cell. If that's not what you wanted/expected, then you need to provide more information in your question.
Comment: As the asker, you have a special privilege when a good answer is given to your question. You can [accept the answer](https://webapps.stackexchange.com/help/someone-answers) that you believe is the best solution to your problem. "Accepting" an answer is a way of acknowledging the work of the volunteer as well as helping others in the future who may have a similar question to yours.
Answer: If the value in A5 is the only value in the column A1:A20 that is manually entered, and the rest of the values are calculated with formulas, wrap those formulas in if(), like this:
=if(isblank(A5), iferror(1/0), "another value based on " & A5 & " and perhaps some other references")
If the values in A1:A20 are manually entered, you will need a script to clear them. Use an onEdit(e) simple trigger, like this:
/**
* Simple trigger that runs each time the user hand edits the spreadsheet.
*
* @param {Object} e The onEdit() event object.
*/
function onEdit(e) {
  if (!e) {
    throw new Error(
      'Please do not run the onEdit(e) function in the script editor window. '
      + 'It runs automatically when you hand edit the spreadsheet. '
      + 'See https://stackoverflow.com/a/63851123/13045193.'
    );
  }
  let sheet;
  if (!e.value
    || e.range.rowStart !== 5
    || e.range.columnStart !== 1 // column A
    || (sheet = e.range.getSheet()).getName().match(/^(Sheet1|Sheet2|Sheet3)$/i)) {
    return;
  }
  sheet.getRangeList(['A1:A4', 'A6:A10']).clearContent();
}


What would have to happen in order to force us to live in the ocean?

Question: What kind of a scenario would have to occur in order for human beings to seek survival on the sea floor? It could be man made or natural, ice age or heat apocalypse, sudden disaster or gradual collapse, I just want to know how it could get to that point. I'm talking about either living on the bottom of the ocean in built structures, or underneath it in tunnel systems.
Comment: Time frame?  I think we're a little off being able to colonize the ocean floor due to pressure reasons, but more shallow area's on the ocean floor would get around that.
Comment: Any time in the future. This isn't really a "what would happen" question it's more of a "how could this happen" question.
Comment: Are you looking for everyone going underwater? Simple overcrowding could drive large numbers to expand under the oceans just because there's nowhere else to go...
Comment: No, I'm looking for a case where life at the surface isn't possible (or at least not as viable), and being underwater is the easiest way to live. It's an apocalypse scenario where most of the earth's population doesn't survive.
Comment: Hello Ogre! One point for you -- if you want to catch someone's attention in comments, you can write their name in your comment, preceded by the @ symbol like this: @Kromey so that they know that you responded to their comment. Kromey, see above.
Answer: Radiation, either from the sun growing unstable or from some persistent cosmic event, sleeting down from space.
A few meters of sea water will block most of the radiation that would effectively sterilize the land. People could build shelters on land but what would be the point? There's not biosphere left on land. Also, without the land biosphere buffering heat and carbon, the climate would be massively erratic, likely with super storms and possibly rapid cycling mini-ice ages at random places. Everywhere would turn into a desert devoid of life but with the same rainfall. With no life to hold soil, huge swaths of land would simply turn to mobile mud.
The ocean would also have the advantage of easy, protected mobility. Trade and migration would be safe and easy. All hell can break loose on the surface but a hundred meters down, everything is smooth.
Likely, it would start with the radiation anomaly growing over a period of years, enough to make preparations. Nuclear submarines and static basis are built. Major land resources are moved to sea accessible locations, perhaps islands. Preferably the initial refugees would be away form major continents or at least rivers because a lot of crap is going to wash into the seas.  Only a few millions at most out of billions could be moved under the sea initially, but there would be survivors on land for years or decades. They could be rescued as capacity under the ocean increased.
Lots of room for story conflict there. The pioneers under the sea, likely the "best and brightest" having a life of mission but also material privilege while at the same time the survivors on land growing haggard, desperate and bitter.
Comment: If the sun's magnetic field grew very strong and it sun was ejecting enough plasma that could compress the earth's field tight enough to compromise it. Radiation is already funneled to the poles is significant amounts. If at that point the earth's field under went a pole shift and broke into numerous poles, each pole would funnel the plasma to the surface possibly accelerating it. The multiple poles would wander the surface sterilizing the earth as it went.
Comment: Thanks, this is just what I was looking for. Could the radiation event you're describing be a prolonged geomagnetic storm?
Comment: Don't think so. That is charged plasma thrown off the sun hitting the magnetosphere. This would be hard radiation like gamma rays. If plasma got accelerated somehow, on its way from the sun, it might do the damage. The most likely source would be a gamma ray burst from deep space, a neutron star raking the planet with it's polar beam etc. If the sun's magnet filed expand powerful enough to compress the earths almost ouf of the way, that  might qualify.
Answer: The first thing that comes to mind is an incredibly large volcanic eruption. And I mean a huge eruption. Something never before seen on Earth. One of the largest (if not the largest) eruptions we know to have happened was that of the Toba supervolcano. It released a staggering 2,800 cubic kilometers of ash, and covered most of South Asia with a layer of ash 15 centimeters thick. It may have killed off a substantial portion of the human population.
But we would need something even bigger to make all of Earth's land uninhabitable, possibly a series of large volcanic eruptions caused by some massive tectonic instability. The Ring of Fire could be a significant contributor, although most of the ash could fall in the ocean. Essentially, you would need all of the world's volcanoes spewing out all of their magma - and then some. Unlikely - probably impossible - but it could still drive humans off of land.
What about that ice age you mentioned? Well, once again, we'd need to cover all of Earth's land. Is that possible? Not by the effects of recent ice ages, but the snowball Earth hypothesis has some potential. It states that, at least 60 million years ago, Earth underwent some cooling, which formed more ice, which then led to more cooling and more ice. Wikipedia suggests (just as I was thinking!) that a supervolcano could have lowered Earth's temperature just enough to start this cataclysmic cooling. There are some other obvious causes (which it also lists - perturbations in Earth's orbit, asteroid impact and an impact winter, reduction in greenhouse gases, etc.) which are a little more mundane, but equally possible. So if you can trigger any of those, you can trigger a snowball Earth.
The one man-made cause I can think of is a large nuclear war. Radiation would have to be distributed just right so that while Earth's land would become overly toxic, its oceans would be fine. Controlled bombs could produce this desired effect, but there would have to be a lot of them - many more than we have today - and they would have to be detonated in very specific spots, so as to make sure the oceans were unharmed. This would, admittedly, be nearly impossible.
Comment: Fall out ends up in the oceans. It falls as ash on the surface and is easily washed away. If the war was so bad as to destroy the plant life, the land masses will loose all their surface soil and all that will wash into the oceans.
Comment: "many more than we have today"... You really have no idea just how many nukes are still left over from the cold war, do you? If you don't need to actually destroy things thoroughly, just make the areas uninhabitable for humans, there's plenty to do that to all the Earth's landmasses several times over.
Answer: Broadly speaking you need three things: (1) something that makes it infeasible to keep living on land (most people won't move unless pushed), (2) the inability to evacuate from the planet, and (3) enough time to build and move into those underwater habitats.
For (1), other answers have proposed radiation and volcanic eruptions.  These work if they can be forecast far-enough in advance to allow for (3); surprise global terrorist attacks with nukes probably wouldn't allow people to move into the oceans, but a decades-long climate change or major volcanos gradually "heating up" over decades could.  To radiation and volcanoes you could add massive air pollution; the logical response might be to move underground, but some will see that as just kicking the problem down the road a bit and move into the water sooner.  (You're going to need oxygen and nutrients, and I suspect they're easier to get from the ocean in the long term.)
You also need to keep people on earth; this could be accomplished several ways:

We don't have off-world colonies yet.
We do, but we can't get most people there.  (Possible story point: if we can get some there, who gets to go?)
We have capacity but it's much more expensive to ship people to Mars/Luna/wherever than to go into the sea (so maybe the "haves" go to space and the meek inherit the earth, so to speak).

Finally, you need to be able to move people into the sea.  You'll need a history of sizable underwater structures (labs, observatories, etc) already, so you're not just figuring out how to build underwater when a global war is heating up.  In other words, people will build settlements under water if they already have a foundation of knowledge and engineering to build on; otherwise they will probably dig underground instead, even knowing that that has problems of its own, because we know more about digging.  (And if this is set on near-future Earth, we have the established meme of underground bunkers already.)


V4L2 change default setting?

Question: I can successfully change the value of the setting I want with v4l2-ctl --set-ctrl=exposure_auto_priority=1 but I want to know how to make that the default setting, the default is 0, which leaves my webcam black, I need it to be default=1
Comment: We need a little more detail please. What are you using to make these settings? What OS are you running? What version of skype are you using? These details help us to provide more detailed answers for you... "Always try to give as much and many details as you can" thank you.
Comment: v4l2ucp (Video4Linux Control Panel) Ubuntu 13.04, latest deb of skype, acer aspire V3-571G. I already got my answer though but thank you for the tip
Answer: You can also use the udev subsystem to establish the settings when the device is plugged in or the machine boots.
For example, here is how I set the power line frequency on my Logitech HD Pro C920 Webcam, which lsusb says has the USB ID 046d:082d.
As root create a new world-readable file /etc/udev/rules.d/99-local-webcam.rules. It contains:
SUBSYSTEM=="video4linux", SUBSYSTEMS=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="082d", PROGRAM="/usr/bin/v4l2-ctl --set-ctrl power_line_frequency=1 --device /dev/%k"

You can follow the same recipe, modifying the USB ID and the v4l2-ctl parameters to suit your exact needs. You can test the v4l2-ctl parameters from the command line until you are comfortable that they will work, then put that text into the udev rules file.
The advantage of this approach is that it "just works". Every time the device is plugged in then the settings are applied.  If you are a systems administrator for a lot of machines then you can push out rules files for all your institution's equipment, they aren't used until that USB ID is plugged into the machine.
Comment: If you wish to set the line frequency on any and all cameras, you can edit the rule to:
`SUBSYSTEM=="video4linux", PROGRAM="/usr/bin/v4l2-ctl --set-ctrl power_line_frequency=1 --device /dev/%k"`
Answer: Since the settings will be lost after each boot, you should run a script at session startup to apply values you generate using the Video4Linux Panel.
To see the adjusted values type on terminal:
v4l2-ctl --all

After create your script, and add it to your startup session...
Here is my startup script:
#!/bin/bash
v4l2-ctl \
--set-ctrl=brightness=150 \
--set-ctrl=contrast=51 \
--set-ctrl=saturation=32 \
--set-ctrl=white_balance_temperature_auto=0 \
--set-ctrl=gain=90 \
--set-ctrl=power_line_frequency=1 \
--set-ctrl=white_balance_temperature=1140 \
--set-ctrl=sharpness=24 \
--set-ctrl=backlight_compensation=1 \
--set-ctrl=exposure_auto=1 \
--set-ctrl=exposure_absolute=870 \
--set-ctrl=exposure_auto_priority=1

I hope that this helps...
Answer: If you have Video4Linux Control Pannel, you might try un checking the Exposure_Auto_Priority check box at the bottom and see if that helps...

Hope it helps... Good Luck!
Answer: This not exactly what you ask for, but you can easily adapt ti to set your favored default values. This returns everything to factory default values.
device="/dev/video2"
function all_default() {
    while read this_train
        do
            parameter=$( sed -rn 's/^ *([^ ]*) .*/\1/p;'            <<< $this_train)
            default=$( sed -rn "s/^.* default=([^ ]*) ?.*/\1/p;"    <<< $this_train)
            echo v4l2-ctl -d $device --set-ctrl=$parameter=$default
            v4l2-ctl -d $device --set-ctrl=$parameter=$default
        done <<< $(v4l2-ctl -d $device --list-ctrls | sed -r "/:/!d;")
    echo "Chattanooga choo choo, won't you choo-choo me home..."
    echo "The setting does not seem to be permanent until you play:"
    echo "https://www.bitchute.com/video/fgvFDTeeXzsb/"
    echo "A strange bug... :-)"
}
all_default

V4L2 change default setting?


fft2 of interferometric image - how to interpret the result in term of dominant frequency

Question: I have an interferometric image which shows fringes at a certain frequency, basically a dominantly periodic signal overlaying the information that I want to extracthere are the fringes that I want to remove. The size of the image is 1024x4067 pixels. So using matlab I performed fft2(im,n) with n = size of image, giving me this fft-image, with maximum values given at (9,24) and it's symetric (1017,4045). I am totally confused now as of how to interprete this result. Does that mean I have a frequency of 9 in y and 24 in x direction making it some sort of Acos(2pi/9y+2pi/24x)+Bisin(2pi/9y+2pi/24x) wave!? I'm guessing this it totally wrong and stupid, but I'm really confused.. :-/
thanks for your help!

here is the shifted FFT image!
Comment: It doesn't look like you have used 'fftshift' on this spectrum (please see: http://uk.mathworks.com/help/matlab/ref/fftshift.html ). Can you please obtain the 2D FFT of a number of your fringe patterns (2-3) and post it along? From the attached image, it doesn't look like your fringe pattern is periodic but maybe you can still filter its effect.
Comment: I added the shiftet image to the original question. I dont understand what you mean with "Can you please obtain the 2D FFT of a number of your fringe patterns (2-3)"...
Comment: Thank you. What I am trying to say is, is the fringe pattern consistent across different acquisitions? If not, can you obtain 2-3 different fringe patterns and their spectra?
Comment: I just have this one acquisition unfortuntely... :-(
Answer:
Remove the mean from the image you linked before analysing it with
fft2.
Use fftshift to get a more readable image.
Use a logarithmic scale on the 2d spectrum if you don't see anything.
Please label the x and y axis with normalized frequency.
Using the insight on the noise spectrum you got from the fft2, design the filters you need to remove the periodic noise.
You noise isn't stationary withing the image, so your filters won't work awesome.

You could also try the following :
Consider your columns as realization of a random vector of size approx 1000 (number of rows). Take your first 100 columns, apply PCA with covariance matric proportional to V*V' with V of size [100*1000], the vertical periodic pattern will be your most powerfull eigen vector. Project your data on the 99 remaining vector. Repeat this process on others 100 columns batches, be carefull with energy normalization.


How can you change your hairstyle in Animal Crossing: Wild World?

Question: How can you change your hairstyle in Animal Crossing: Wild World?
Answer:
In Animal Crossing: Wild World, Animal Crossing: City Folk, and Animal Crossing: New Leaf the player has the option to change their hairstyle at Harriet's barber shop, Shampoodle. In Wild World, Shampoodle is available inside of Nookington's, meaning that players will first have to unlock Nookington's by spending 240,000 bells and having a friend visit their town and purchase an item from Nookway before being able to change their hairstyle.

Source: Hairstyle - Nookipedia
Once in Shampoodle you will have several options available. A hair style guide can be found here, and a hair color guide can be located here
Answer: According to Animal Crossing wiki,

In Animal Crossing: Wild World, Animal Crossing: City Folk and Animal Crossing: New Leaf, the player can change their character's hairstyle by visiting Harriet at Shampoodle. The style and color is determined through a series of questions. When getting a haircut or makeover, Harriet will push a button, and a large, hairdryer looking device will cover the player's entire head. After a few seconds, it pops off. The player will always have a shocked look on their face when the action is complete.

A hair guide can be found here
Answer: If you have a friend over via WIFI or DS to DS and they buy something from your shop when it is Nook Way, then Tom Nook will upgrade. When it gets upgraded then in his store he will have Shampoodle in it.


How to create admin tabs

Question: What I am trying to achieve is the following tab setup as in the "CoursePress" plugin for WordPress. My idea is to have different tabs for a custom post type, where the main setup tab also has the publish/schedule metabox.
Answer: These tabs don't come from WordPress - it's not part of WP GUI.
So if you want to achieve that look, you'll have to implement it by yourself using custom HTML, implementing most of the logic and using add_menu_page.
But... It isn't a good idea.
First of all, interface should be consistent. All WP users know how to use native WP editors, and no one is familiar with your idea - it will be inconsistent ;)
Another reason not to implement this design is... Gutenberg - it will be default editor in WP soon and it will cause some major changes in editor layout - so most probably your idea will cause many problems then.
Comment: What do you suggest? More metaboxes? For example in CoursePress, a course has units and students, that can be edited in one page. I do not want to navigate in 10 different pages to manage one course..
Comment: It depends... But I would definitely use native WP GUI...
Comment: Yeah but wp gui suggests nothing useful for this problem / topic...
Comment: You have different post types, taxonomies and meta boxes - use them to achieve what you want. Don't invent something different - it won't be easier... There's really nothing more annoying than authors of plugins who want to reinvent all the GUI and implement their ideas inside of WP... Such interfaces are always messy, inconsistent and (most of the time) very unsecure and causing many compatibility problems...
Comment: Yeah but I want to have a course which has lectures and students. I want to navigate and manage all of this as easy as possible in one page. I see 3 custom post types, but how do I connect them? I do not want to reinvent nothing....

How to create admin tabs


Mountain bike brake pistons not compressing when brake is pulled

Question: I have a Shimano BR-MT201 Hydraulic Disc Brake on my rear brake. I was replacing the brake pads and accidentally pressed the brake too many times and the piston popped out leaking brake fluid. Afterwards I pushed the pistons back in, retracted them all the way and pumped new brake fluid into my brake. But now, when I press the brake the pistons don't move at all and the brake easily compresses all of the way. I also noticed a little air bubble around the piston when I press the brake. What should I do to fix this? I have also cleaned the piston with isopropyl alcohol.
Comment: Brakes might need a bleed?
Comment: The bubbles indicate that the pistons are no longer tight. I'm not sure if they can be re-sealed. But i guess you learned by now that you should not operate the lever without pads or a spacer block.
Comment: I have fully bleed my brakes and still nothing happens when I pull the lever.
Answer: From your description, it seems that either there are air bubbles in the brake lines, or the cylinder assembly lost compression. What can - or should - be done about it, depends largely on the extent of the damage caused by the popped cylinder.
If you are lucky, proper bleeding should do the trick. However, the bubble of air forming near the piston suggests there is more to that. If the piston picked up dirt from the floor and you pushed it in, it's possible that the seal, piston, or the entire cylinder got damaged. A grain of sand could also explain why the piston is not moving at all.
You can try bleeding the brake according to the manual, but if that doesn't help, replace the pistons (if you could find them, Shimano does not list this item in the manual). Keep in mind, though, that Shimano hydraulic brakes use mineral oil as working fluid, not automotive DOT fluid. Using DOT 4 (the most widely used brake fluid) can irreversibly damage seals and hoses.
Comment: Thank you for the response. I can't get the pistons to move at all and there jammed all the way to the back, nothing happens when i press the brake and its full of brake fluid. Is there any way i can get them out?
Comment: By 'brake is full of brake fluid' you mean that the reservoir is full, or that the brake has been properly bled?
Comment: I added a funnel to the top of the hand brake and then inserted a syringe into the brake inself and pumped in fluid until fluid appeared into the funnel. (I followed this tutorial https://www.youtube.com/watch?v=DsqlEYJeLQU&t=108s&ab_channel=GlobalCyclingNetwork)
Answer: Here is the link to Shimano's Dealer Manual for BR-MT200.  There are a couple notable lines in the beginning cautions and recommendations. One states that if a piston were to completely come out, "consult a bicycle service center." The other, "Do not remove the pistons when disassembling the calipers (for cleaning)." This manual also has the proper bleed procedure laid out which should be followed. When doing this, note the caliper  should be at the low point. Remove it from the bike or fork so that one, the hose is a fairly straight shot up to the lever, and two, you can turn and tap the caliper to better get the air bubbles moved out of the caliper.
The pistons are held in place by the force of the rubber seals. The edge of the rubber seal will rest in a seat on the piston and form an air and oil tight seal. In addition to the sealing effect, the stretching of the rubber seals when the piston moves in toward the rotor creates the force that returns the piston back to it's "at rest" point a millimeter or so away from it's side of the rotor.  So, when you state, "the piston popped out leaking brake fluid," that infers the seal of the rubber to the piston was broken (not necessarily as in damaged but displaced from it's seat). You go on to describe pushing the piston back in. I wonder if the seal has not been seated properly on the piston allowing air in or not allowing appropriate pressure to build behind the piston upon lever actuation.
The fact that the pistons are not now moving indicates a situation where there is inadequate pressure build up to move the pistons. This could be air, which is compressible and any within the system steals the hydraulic pressure the fluid exerts, or an incompetent seal (damaged, unseated, or foreign object between seal and piston). There could also be a slight misalignment or something that causing a mechanical blockage that prevents piston movement even under normal hydraulic pressure build up.
I suggest determining what the issue is by examining the caliper   and it's piston area while actuating the lever. Is there any pressure build up? Determined by lever feel. Is it soft initially?  Does it firm up any with multiple lever actuations? Do you hear or see anything at the caliper? Air or oil leak or both? Feel anything at the caliper like vibrations or the movement of fluid or a sensation of air bubbles squishing through fluid?
Obviously we need to determine adequate piston to seal integrity but that will be tough to do if you can't get the retracted pistons to move out. A continued soft lever feel under multiple actuations and in the absence of any signs of leak (sight, sound, feel) is better evidence that there is air in the system. At any rate, if the pistons aren't moving at this point--if nothing is happening, like leaks--complete a proper bleed by following the "adding oil and bleeding air" section of the above dealers manual. Have the caliper off the bike and hose straight up to the lever which is    parallel to the ground (you want the port that accepts the funnel to be the high point of the system which is naturally achieved by it's design if it's  positioned like was sitting on a table.  The installed funnel will be pretty much straight up and down, the top of the mineral oil in it forms a level, horizontal line).  When adding the mineral oil with the syringe, move the caliper in different positions keeping pressure on the syringe so oil continues to flow. Use your other hand (or a helper) to tap the caliper and hose with the handle of a screw driver. Vary your pressure on the syringe a few times, soft then firm.  Always keep a little positive pressure or you can stop completely but don't suck the plunger back.  All of this helps to get air moving out of the caliper. Obviously, a leak or bubbling anywhere as you do this needs to be evaluated. Both the syringe and funnel need to be connected air tight. There should be an o-ring for the funnel and the plastic tubing off the syringe should fit tightly on both syringe and bleed nipple.
At #5 of the bleed procedure in the dealer manual where the syringe is replaced with a collection bag, note the upright position of the bleed nipple and initial aspect of hose. Keep these in a generally up position as you manipulate and tap the caliper body and brake hose.
With bleed complete, check for piston movement and leaks etc.  One thing to note, the BR-MT200 is a fairly inexpensive item. A whole new system for front or back brake can be had for $25-40 USD. That's pre-bled, one can install and go pretty much.  Thus, if your time is more valuable than your willingness  to jack around with all this perhaps it's best to buy new and have a spare lever and a caliper to dissect for understanding.
Here's one link of several options for ordering a new BR/BL-MT200 set, chosen for the sale price and multiple positive experiences with the seller. Call that what you want except a "recommendation" which is frowned upon here on SE.
Universal Cycles. Sale on BR/BL-MT200 and others


In a opel zafira 2008 oil leaking into the coolant bottle

Question: I have a opel zafira 2008 it has oil leaking into the coolant bottle but I had a compression test done and it came back fine so what else could it be
Answer: Oil cooler leak. There is oil cooler behind catalyc converter,where oil is cooled by coolant in little box. Seals needs change.
Type zafira b oil cooler on ebay.
https://youtu.be/2bCllbBcRcY
Answer: If you have oil leaking into the coolant, then the head gasket has gone bad.
You can confirm this by driving down the road when your engine has cooled down, turn the heat on low and listen for a gurgling sound, like there's air in the water somewhere. It's a clear indication that air is leaking into your coolant from the chamber and going through your heater core. It may be why your hot air isn't so hot anymore
It may be too small to notice with a compression test, or it could of just been a complacent mechanic that seen 1-3 cylinders good and one was off by just a hair, but it'll be alright, it may only happen once you drive down the road when the vehicle isn't at idle RPMs.
Changing a head gasket is fairly easy, but it's around a 10 hour job, sometimes it may even require removing the motor from the engine. Here's a rough outlook that may not be specific to your type of car, but it gives you a general idea:

Disconnect the negative battery cable

Drain the cooling system (coolant)

Remove the Intake manifold

Remove the throttle body

Remove the PCV valve

Remove the air filter

Remove the alternator

Remove the spark plug wires

Remove the spark Plugs

Remove the Distributor cap ( or coil pack )

Remove the radiator fan

Remove the coolant pump

Relieve the fuel pressure ( pull the relay in the junction box and start the car 3 times )

Remove the fuel line

Remove the fuel injectors

Remove the exhaust manifolds

Remove the head cover

Remove the timing chain ( Mark chain to sprocket with a ink pen )

Remove the timing chain Tensioner

Remove the head bolts In a random order when the engine Is cold ( Failure to do so when the engine is cold may result in a warped head )

Remove each head bolt by 1/4 of a turn before removing ( New head bolts required on Installation )

Use a pry bar at the corners of the Cylinder head-to-engine block ( Do not pry between the cylinder head and the engine )

When Installing place the engine at Top Dead center, by aligning the notch in the crankshaft pulley with the TDC Indicator

When Installing - Inspect all hoses and replace all gaskets

When Installing - tighten head bolts in s specific sequence such as this

Other symptoms of a blow head gasket

(source: gobdp.com)

(source: gobdp.com)

I don't mean to scare you, but since it has gotten cold the seal has contracted a bit making an opening for a passage way into your coolant, (it may only happen when you step on the gas) If you stick it out until summer the seal may expand and fill the gap... a leak such as these can cause a engine block to crack because water (coolant) is getting into the combustion where it uses oil to dissipate the heat and lubricate the parts, water and coolant cause corrosion.
But before you go spending 1000 dollars on a mechanic or 50-300 dollars on a bunch of new gaskets, keep in mind that they also make stop leak formulas for the oil for small head gasket leaks.
It's a head gasket, but make sure the heads get cleaned up from all of the carbon when it's changed, no reason for that to go undone. It gets rid of any knocking noise and makes your engine happy overall.


Independence of random variables.

Question: For two random variables $X, Y$, if their joint distribution can be written as product of two functions $f(x),g(y)$ for all $x,y$ ( need not be marginals), I am trying to prove that they are independent. However, I am unable to intuitively imagine this through examples. If I try to find the marginals of $X,Y$, aren't they nothing but $f(x), g(y)$ in this case? Is there something I am missing?
Comment: $f$ and $g$ needn't integrate to $1$.
Answer: Below is a counterexample. Let the joint PDF of $X$ and $Y$ be
 $$f_{X, Y}(x, y) = 4xy$$
where $0 \leq x, y \leq 1$ and let $f(x) = x$ and $g(y) = 4y$.
In this case, both $f(x)$ and $g(y)$ are not valid PDF however.

Independence of random variables.


Sharing a project between Eclipse and Netbeans

Question: Is there a way to share the same *.java files between Netbeans and Eclipse?
Answer:
You can import an eclipse project into netbeans,
or you can create an eclipse project from existing sources.
Comment: I took the liberty to add some links illustrating your answer (+1 btw)
Answer: Sharing the Java source files is not the problem - just put them into some source control system, and then import them in both IDEs. Usually the configuration, especially the build process, is the main problem.
In practice, the solution is likely that you maintain separate project configuration files for both IDEs, but use a common build script (e.g. ant) that is supported by both. The project configuration allows you to use IDE-specific features, while the build script makes sure that both environments produce the same output.
Answer: Of course. eclipse supports linked source folders. The sources files don't have to be located in an eclipse project folder.
Inside an eclipse java project, select New -> Folder, then select "Advanced" and check "Link to alternate location" (eclipse 3.6, may be slightly different on other eclipse versions). "Browse" to choose the source folder from the netbeans project, press Finish.
Now you have linked (standard) folder to the Java files inside the netbeans project and modifying those files will modify them at the remote location.
Finally - right-click on this linked folder and choose Build Path -> Use as source folder.
(I leave the other way round to the netbeans experts)
Answer: In the ideal case you have your code stored in a version controlled repository (SVN, CVS, etc.).  Then it is not as big of a factor whether you are using Eclipse or Netbeans.
Answer: This article, taken from a NetBeans 6.2 version of documentation, explains how you can import an Eclipse project into NetBeans and work with both together. NetBeans will create new project files but will link to the Eclipse source files, allowing sharing between the two. I have not tried this yet myself, but may be going down this path soon. After switching to NetBeans just this week, noticed that a significant feature in Eclipse is not in NetBeans - that of being able to create different run configurations that are not incorporated and stored into the POM. At this point in time, I do not have a solution to the run configuration issue, but if you do, please update the SO question here.


Outdoor Outlet Non-GFCI Downstream of GFCI

Question: Can I run a non-gfci outlet outside if it is downstream from a GFCI outlet on the same circuit?
Comment: Where is this GFCI located?
Answer: Yes, you can do that, using the LOAD side of the GFCI.
But not only can you do it, it is actually a very good idea. That is because GFCI includes sensitive electronics not in a regular receptacle. Keeping a GFCI clean and dry and temperature controlled will likely make it last much longer than it would outside.
Answer: Sure you can.
If the downstream outlet is fed from the GFCI receptacle's LINE terminals, it will not have GFCI protection.
If it's fed from the GFCI recep's LOAD terminals, it will have GFCI protection.
Intending to protect downline loads is the only valid purpose of the LOAD terminals. They should not be used for any other purpose.
Comment: @Dylan you misunderstand.  There is no requirement for GFCI *receptacles* anywhere in Code.  They are not needed at all.  What is needed is GFCI protection, and that can be on the load lines of a GFCI breaker, deadfront, switch, recep, whatever that is upstream.
Comment: And this is still the case even if the non-gfci is outdoors?
Comment: @Dylan The GFCI requirement is satisfied by being downstream, whether you mean outside or next to a sink
Answer: "And this is still the case even if the non-gfci is outdoors?"
Yes, anything that's downstream on that circuit will be GFCI protected regardless of whether its located indoors or outdoors. As long as you continue the circuit from the LOAD side, just like what the last person said.


Local post assets with Jekyll

Question: I was wondering how other people are organising their assets for individual posts when using Jekyll. For example, if a post has an image, do you just dump it in a shared images folder? I don't really like the idea of doing this - it means that an image is completely separated from a post, when I think they should be paired.
Answer: I wrote a plugin to let me organise assets in subdirectories easily:
https://github.com/samrayner/jekyll-asset-path-plugin
{% asset_path my-image.png %}

in post 2013-01-01-post-title would output:
/assets/posts/post-title/my-image.png

in page my-first-page would output:
/assets/my-first-page/my-image.png

Answer: I prefer to think of images as stand alone assets that are included in zero or more pages. Most of the time, my images show up in a single page. There are times when I want to have them in multiple pages and in other cases I don't link an image at all. If your workflow is to put each image in a directory with a post, finding them starts to require a significant amount of searching and you have to come up with something different for images that don't belong to a specific post.
The approach I use is on the opposite side of the spectrum. I have a single image directory (served from "/images") and 100% of my images are housed there. Benefits of this are:

When I'm adding an image to a post it's easy to know what path to use. It's always:
/images/{image-name}

For example: http://alanwsmith.com/i/aws-20111017--0906-02. This makes it possible to write a plug-in so all you have to enter is the image name and the rest of the known path is filled out automatically.
With an application like Photo Mechanic, it's incredibly easy to browse the single directory locally and see every image. If I want to include an image on another page, this drastically reduces the time to find it.
There isn't a separate location/process if I want to send an image to someone without actually including it in a page (i.e. send them a direct link to the image file). I just throw the image in the standard directory and send the direct link.

If you want to get a little more advanced, keeping all your images in a single directory makes some nice tweaks possible as well. For example, even though the URLs for my images start with "/images", the images are actually stored in a directory outside of the ones jekyll uses. In my case, the top of my source tree looks like this:
./html
./source-files
./image-files

All of my images are stored in the "./image-files" directory. In my apache config, I've setup an alias so that the URL "/images" points to the "./image-files" directory. For example:
Alias /images /webroot/image-files

When I run jekyll, it process everything in "./source-files" and drops it in "./html". Because all of the images are outside those two directories, jekyll never sees/touches them. As your image library grows this will help speed things up and will prevent a tremendous amount of unnecessary file copying.
Another tweak I like in Apache is turning on:
Options +MultiViews

This lets you call your images without having to use the file extension (e.g. no '.jpg', '.png', etc...). You can see that in the example link I provided above. It doesn't really matter for performance. I just like the way it looks and it saves me from having to type the extension every time I'm calling an image.
MultiViews also makes it possible to replace an image of one format with another without having to recode anything else. For example, if you remove "some-image.gif" and replace it with "some-image.png", you wouldn't have to touch any HTML. It would still be served form "/images/some-image". Needing to make changes like that is probably exceedingly rare. I just think it's an interesting thing to be able to do.
Finally, you can make a single decision about allowing or disallowing your image directory to be browsed. Personally, I only want my images to show up where I place them. So, I've set the .htaccess file in my images directory to:
Options -Indexes

If you are going to be working on a site with many thousands or tens of thousands of pages and images, this might not scale. For a normal sized, personal site, I find that this approach makes maintaining images easier.
Comment: why is this the accepted answer? this does not offer technical guidance on how to co-locate. I agree with the use case for this answer, but there are also images that I have no intention of sharing generically outside a blog post—and in those cases I _don't_ want to clutter my images folder with them.
Comment: @ianstarz - I was simply answering the first part of the question asking how folks handle images. While the person asking the question initially stated they didn't like the idea of putting images in a single folder, they apparently changed their mind. I've found the separation of concerns afforded by maintaining images in their own directory tree (e.g. you can have sub-directories too), and knowing there is only one place images are stored to be helpful. But that's all personal preference and options like SamRayner's https://stackoverflow.com/a/19635916/102401 answer are perfectly legitimate.
Answer: I have now managed to develop a Jekyll plugin that helps keep posts assets alongside the Markdown file:
https://nhoizey.github.io/jekyll-postfiles/
Answer: Just like you, I really hate having all images in one single shared folder.
Most, if not all, of my images are useful in one single post, and keeping them alongside the Markdown file is really better for posts management:

I can drop a new post as one single sub-folder of /_posts/ in one step, without having to put the Markdown at one place and the image(s) at another
When I want to edit the image(s) of an existing post, I don't have to find the right image in a huge /assets/ folder, it is located just near the Markdown file
In my Markdown, I can use the image file name directly, without any path
If I want to use any Markdown editor with live preview, it works, no need for a specific assets folder configuration

I tried to have this for my blog (example post here).
For responsive images, I used the Jekyll Picture Tag plugin, but I had to fork it, because the Pull Request to deal with such paths was not accepted.
Now that Jekyll 3 is there, I wish it could let us use images both in a post folder AND in the /assets/ one, looking for an image marked with ![alt](image-file-without-path.jpg) in both, in that order.
Comment: It's not entirely clear to me whether you managed to solve the issue or not? Are you now putting images into the same folder as posts, and how?
Comment: Nevermind,I see you have another answer on this question with your plugin. Nice work :) (hit the 5 min limit so can't edit previous comment).
Answer: For JavaScript and CSS, you may want to consider an asset pipeline.  You can get a good performance improvement through bundling and compression.  I also use CoffeeScript and Sass, so I needed a preprocessor to convert my assets.  I use Jekyll Asset Pipeline to manage this whole process automatically when I run the jekyll command.
For images/video, I recommend you develop a convention for naming folders in your project.  I generally have an "assets" folder then subfolders with the date of each post that holds the images related to those posts.  If you have multiple posts per day, you might consider including the name of the post.
Answer: This answer:

Does not use plugins (works with GitHub Pages)
Allows you to keep images directly next to their relevant posts
Allows you to edit using Typora locally and see the images WYSIWYG

Just name your folders like _posts/2020-10-10-My-Title/ and include files like index.md and hero.svg or other images.
Then set your permalink: key in _config.yaml to :path.
Caveats:

Your folder names must be sluggified
Your images must all be SVG
Comment: And if you are interested in changing Jekyll so the workflow is better, @parkr would accept a PR as described at https://github.com/jekyll/jekyll/issues/5181
Comment: If you are looking into this very hardcore for a GitHub Pages usable solution, there may be some thing undocumented/magic to put in _config.yaml default key where it will somehow trick your other images to skip rendering (avoid "Error: could not read file... invalid byte sequence in UTF-8").

Local post assets with Jekyll


Workflow not firing off

Question: I have a workflow that sends an email when a field is set to "yes" in an infopath form. The workflow itself just says if fieldx=yes then send email. But workflow did not fire. The field has "yes", so it ahould have fired off but I cant find a logical reason why. Any way to check all the instances for a particular workflow or anything else i can investigate?  Thanks.
Comment: Can you attach screenshot of workflow actions you used? That will help us to answer your question.
Comment: Are you testing with an admin account? Workflows will not auto fire for those.
Comment: Are you trying to do a manual workflow trigger? Or are you trying to have the workflow trigger on item creation? If so, make sure your workflow is set to automatically start on new items.
Answer: You need to trigger wf start when item is modified or created. Then as first action check the condition if the email is yes then send whatever comms you need if not just terminate the wf.

Workflow not firing off


Would dividing a random number by a constant "ruin" it?

Question: If I get a random number from a cryptographically secure random number generator then divide it by a number, say 2, is it still cryptographically secure?
Answer: It does not lower the security at all - at most, it changes the output space. If your output space is, say, the integers between $-100$ and $100$, then computing PRG$(s)/2$ for a random seed $s$ gives a value indistinguishable from a random value in the set $\{-50, -49.5, \cdots, 49.5,50\}$. Depending on which output space you consider and what you exactly mean by "dividing by 2", it can even remain a cryptographically strong PRG with the same output space: if your output space is, say, the field $\mathbb{F}_p$ with $p$ prime, then computing PRG$(s)$ and multiplying the output by $2^{-1} \bmod p$ gives a value indistinguishable from random in $\mathbb{F}_p$.
This follows immediatly from the security of the original PRG: since division by 2 is a reversible operation, any distinguishing attack on the new PRG trivially translates into a distinguishing attack against the original PRG.
Comment: @dkimot 's random example was 2.  What if he'd picked 3 instead?  I know that it doesn't divide cleanly.  So what then?
Comment: Note that your answer implicitly assumes that the OP keeps the exact rational number resulting from the division, and can somehow use this rational number in their cryptographic scheme without rounding / truncating it to an integer or otherwise mangling it in any irreversible way. Off the top of my head, I can't think of many cryptographic schemes that would accept e.g. $37\frac23$ as a key. If, as I suspect, the OP is instead thinking of using truncating integer division, then the truncation *does* lose some entropy.
Answer: I would argue that if your key was cryptographically-secure and derived from a large enough space such as ${2^{128}}$, and the constant that was being used to divide was also sufficiently large, such as factorial 33!, then an attacker who knew that you were using that divisor could help speed their search and thus reduce the security of your key by a few bits (not sure how many, perhaps ${2^{125}}$ in the above example, which is the length in bits of factorial 33).
Otherwise, dividing such a large number by such a tiny integer such as 2 would have a negligible effect and likely still remain secure, compared to dividing by a non-negligible number, depending on how large the constant is.
P.S. I didn't argue indistinguishability given that the question assumes a CSPRNG is used, but instead whether the constant used is reducing the security in bits of the random number.


Happiness and Karma

Question: I suddenly thought of a question...
If one often feels unhappy, stress, uncontented, negativity, does it mean this person has bad karma?
Is there a way to improve the situation so that the person can be calmer, and happy?
TIA!
Comment: yes. but no. all experiences are a construct of karma. but not just from this life: you have zillions of previous personalities to blame
Comment: also, the karma necessary to be born as a human, let alone a human with access to the dharma, is very good indeed. the idea of blaming yourself for bad karma is just meant to help you practice!
Answer: The word "kamma" means "intentional action".
If one often feels unhappy, stress, uncontented, negativity, this does mean this person has unskillful ('bad') karma.
In summary, the unskillful karma is not practicing the Buddhist path.
To improve the situation, i.e., to do good karma, one can practice the Buddhist path, which on the most basic level means:

To avoid killing, stealing, lying, drugs, alcohol, gambling, borrowing money for transient things.
To avoid unskilful careless non-committed sexual activity that leads to unhappiness.
To practice generosity, unselfishness, kindness & non-harming towards others.
To avoid bad dangerous friends and associate with good safe friends.
To develop being inspired by the virtues of the Buddha & Good Monks, Nuns & Buddhists.
Train the mind to abandon anger and cruelty.
Answer: These are just feelings and metal states. They come and go. They belong to noone. Just be mindful of them until they pass away.
You can follow the Noble Eightfold Path, meditate and do good deeds.

Happiness and Karma


Can browse internet but can't update Ubuntu 14.04

Question: Using wifi connection or 3G connection I can access Internet but when I'm trying to install updates through the software updater it says no Internet connection. When I try ping google.com it also failed.
But using browser I can surf Internet without any problem, I'm bored with this problem already, can any one please help me to solve this?
Comment: See my post here: http://askubuntu.com/a/707754/476968
Answer: That sounds a lot like a proxy issue. Check if you are using a proxy to browse the internet (firefox or whatever browser you are using) and replicate the setting to your network proxy sttings of the system. You can also use thr /etc/environment file to setup the proxy by adding a line http_proxy entry . This will equally for for https_proxy and ftp_proxy. Or, if no proxy exist on browser, verify that system isn't using one as well. After changing this do a network restart.


combinatorics & probability problem

Question: There are numbered  cards 1 to 13  each of colour red, green, yellow and white.   And four players have been distributed 4 each of these cards randomly.  What is the probability that each player gets at least one card from each colour?
My answer is this:
$$
\frac{13^412^411^410^4}{{52\choose 16}4!}
$$
Am I right?
Comment: Effectively the same question was [asked and answered](http://math.stackexchange.com/questions/852450/52-card-deck-probability) here.
Answer: There are $\dfrac{52!}{(36!)(24)^4}$ ways to give out the cards, since the order in which they are given to one particular person does not matter.
How many ways are there in which each person gets cards of different color? there are $13^4$ ways to select the first players cards, $12^4$ the second player $11^4$ the third and $10^4$. So the final answer is
$$\frac{13^4\cdot12^4\cdot11^4\cdot10^4}{\frac{52!}{(36!)(24)^4}}=\frac{(13^4\cdot12^4\cdot11^4\cdot10^4)(36!)(24)^4}{52!}\approx .0011\%$$
Comment: @Andre Nicolas @ Bananarama.  I saw both your answers and thank you.  Is my answer correct and your answers are just different forms of the same answer?  Or am I wrong?   My reasoning is that we can distribute 16 cards (4 X 4) from 52 in 52C16 ways.
Comment: Most of the expression is right, just a problem with the $4!$.
Comment: @AndréNicolas Thanks Andre.  I realise the mistake of 4!.  It should simply be (188.8.131.52)^4/52C16.  Am I right this time?  I have not understood the reasoning of Bananarama.  If my answer is right, the denominator should 52C16 or 52!/36!16!.  Which is different from 52!/(36! 24^4) as given by Bananarama
Comment: My answer and the one by Bananarama are the same, though derived omewhat differently. Maybe you can see another way by imagining the ards are dealt frt to A, then B, then C, then D. The probability A gets $4$ different colours is $39/51)(26/50)(13/49)$. I do not see a reason for a denominator of $\binom{52}{16}$. Indeed we are choosing $16$ cards, but order matters.

combinatorics & probability problem


Show index of tabs in the tabline

Question: I want when i type :tabnew , that it automatically create numbered (indexed) tabs according to which tab in order it is.
if it's 3rd tab that will be opened, than to show number 3 before tab name ( 3 [tab name] )
I can create tab with some name, like :tabnew hello
but number is still staying 1
( 1 [tab name1]  | 1 [tab name2]  | 1 [tab name3] )
I want it to show like index, so I can quickly jump to it with <n>gt
( 1 [tab name1]  | 2 [tab name2]  | 3 [tab name3] )
so i can just jump without counting which tab it is, to 3rd from 1st, with 3gt
If I disable vim airline, then with this function I get that functionality, but airline is overshadowing it, so it's useless with airline enabled.
screen shot:

environment:
vim: 9.0
vim-airline: 0.11
OS: Manjaro latest
airline configuration:
let g:airline_powerline_fonts = 1
let g:airline_extensions = ['tabline']
let g:airline_highlighting_cache = 1
let g:airline_theme='wombat'
let g:airline#extensions#tabline#enabled = 1           " enable airline tabline
let g:airline#extensions#tabline#show_close_button = 0 " remove 'X' at the end of the tabline
let g:airline#extensions#tabline#tab_min_count = 2     " minimum of 2 tabs needed to display the tabline
let g:airline#extensions#tabline#show_splits = 0       " disables the buffer name that displays on the right of the tabline
let g:airline#extensions#tabline#enabled = 1

terminal: xfce terminal 1.0.4
$TERM variable: xterm-256color
color configuration (:set t_Co?): t_Co=256
Comment: I suspect the number you are seeing is the number of splits.
Answer: So, the solution is to include this in vimrc
let g:airline#extensions#tabline#tab_nr_type = 1 " tab number

Show index of tabs in the tabline


Industrial Engineering Program

Question: I am a senior in high school and have been accepted into multiple engineering schools, and the top engineering school I'm looking at is OSU(industrial and systems engineering). I have noticed that there is no Calculus 2 and the only programming class required is an intro to Java. I understand that OSU has an impressive engineering program, but I am unsure what courses will be necessary. Could someone please help me understand what mathematics and programming skills are needed in industrial engineering?
Comment: You can always check [these](https://collegegrad.com/careers/industrial-engineers) kind of informative sites. Also you should keep in mind that it is better to focus your career plans and then decide to improve your skillset accordingly.
And one more think, remember, you are going to be an engineer, maybe you don't need to get calculus (calculator can do that too) but you need to get a way of thinking of engineering.

*eg: I myself as a mechanical engineer, I decided to work in defence industry, so I need to use MATLAB and SOLIDWORKS very efficently due to our analysis needs in sector.
Comment: If you want I can write this as an answer. Good luck!
Comment: I'm voting to close this question as off-topic because [our policy is not to give out academic guidance on the main site](http://meta.engineering.stackexchange.com/q/261/368). Try speaking with academic counselors at your current and prospective institutions, asking in our [chat], or looking for an internet discussion forum like [College Confidential](http://talk.collegeconfidential.com/).
Comment: The clue is in the words *industrial and systems* engineering. You won't be taught anything much about the "big four" of Mech, Electrical, Chemical, and Civil, and you certainly won't need to use Matlab or Solidworks. To quote the OSU website, you get courses on stuff like "engineering economics ... quality control, supply chain management and logistics, project management ... workplace and facility design, ergonomics..." etc. If you want to be a project manager, that's fine. If you think "project management" is not quite as exciting as "watching paint dry", pick a different degree!
Answer: I am a senior mechanical engineering student at Wilkes University in Pennsylvania, so I know what you mean about trying to understand the mathematics and programming courses required for your degree, i'm still dealing with it now as it is.
When you are looking at a program, different schools have different names for different things, so for example at my school you have calc 1, calc 2, differential equations (practical applications of both calc 1 and 2), and then multi-variable calculus. OSU might however have my differential equations class as an engineering specific math course such as applications of differential equations in engineering.
this is the same case with the programming class, it might not say programming in insert language here, but it might be like our schools linear systems class, which sounds like a math course, but was a MATLAB programming class on specifically how to solve calculus problems using a program that you design yourself.
mathematics skills are important and if you feel that it's even more important for you to focus in something because you wan to go into a specific industry, you can take a minor in something, or just take a class because it never hurts. The most important thing that i have learned at my internship that I've been working at for the past 2 years is that you need to adapt and learn whatever material is relevant to your current problem. if there's a formula or a concept you don't know or don't understand, don't be afraid to ask your peers, supervisor or even someone on the internet (hi there). also you might be able to find a research study or a book dealing with that specific topic that could help you understand what your trying to do, and who knows you might even learn something else in the long run, which could help you in the future.
It's good that your thinking about this now because you've got your entire college career ahead of you, that way if you wan to deviate and possibly explore something you might be interested in, you can do it. I say good on you and good luck with everything you do, and just make sure to read up on the classes so you can understand the main premise of it before you go into it.
Comment: Also its impossible for the university to teach you all you need to know. Their puroose is to teach you enough so you can find out yourself later.

Industrial Engineering Program


Using dd to back up only contents an image on an SD card

Question: I have a Raspberry Pi (RPi) with a 128 GB SD card. This SD card contains the full OS and settings for the RPi and I would like to back it up. The total size of all files on the SD card are around 350 MB.
I put the SD card into my laptop which runs a Linux distro and used dd to make a copy of the contents of the SD card:
sudo dd if=/dev/sdb of=RPi4Image.img

This command was taking a long time and I checked the file size being generated on my laptop and it was in the 44 GB size and not finished being created. I assume I would end up with a 128 GB file size, to only backup 350 MB of content, which is not useful to me.
I stopped the process.
It seems to me that this dd command makes an image of the whole SD card, all 128GB of it, even when I only need to backup the 350 MB of contents / files on it.

Am I correct in assuming that the dd command backs up the whole device and so makes a file size that is equal to the whole SD card size?
If so, are there any ways to backup, and be able to restore to an SD card, if needed, only the 350 MB of contents of the SD card?
Comment: 1. Do not, under any circumstances, backup the SD card with live partitions (i.e. one that's running your OS at the at moment)
Comment: 2. No need to use `dd`, just use `cat`, especially as you're not using any sensible flags for `dd`. For example, `sudo sh -c 'cat /dev/sdb >RPi4Image.img'`
Comment: 3. If you're using `cat` you can also use `gzip` (or `bzip2` or `xz`). For example, `sudo sh -c 'gzip RPi4Image.img.gz'`
Comment: @ChrisDavies thanks for taking the time to help me out :)
Comment: FYI I've only commented rather than providing an answer because I didn't answer the question you asked
Answer:
Am I correct in assuming that the dd command backs up the whole device and so makes a file size that is equal to the whole SD card size?

Yes, dd does a block-by-block copy

If so, are there any ways to backup, and be able to restore to an SD card, if needed, only the 350 MB of contents of the SD card?

You can use Partclone to achieve that
Answer: dd without arguments copies from source to destination until reaching the end of one or the other, but it is not the only way of using the tool, or even the usual.
If, for example you know that the filesystem on the card was limited to the first 2GB of space you could specify to only dump that much. You do this using the bs blocksize option and the count option.
dd if=/dev/sdb1 of=new.img bs=1M count=2048

If necessary you could maybe use resize2fs to resize a linux filesystem to make it occupy only the beginning of the drive.
If however, the filesystem was not limited to part of the disk, and isn't a filesystem you can resize from Linux like ext2/3/4 then your only option is to take an image of the entire disk/partition.
Fortunately, if your system was put on a fresh card and you weren't using it read-write for a long time this system will usually have a LOT or zeros and will compress down to almost exactly the used space. So gzip or zip the image file as soon as you have it.
You can even do this on the fly so that you never need the whole file on the disk:
dd if=/dev/sdb1 | gzip | dd of=new.img.gz

This is because if if or of aren't specified they default to stdin or stdout. It won't save on copy time but will save on disk space needed to store the image.


Is Tomcat vulnerable to the Apache DoS vulnerability in CVE-2011-3192?

Question: Is Tomcat affected by this vulnerability?  Here is the advisory announcement.
Answer: Essentially, this vulnerability gets the Apache server to build a massive response to a request for a single file, far larger than the file itself.  While the RFC (2616) tells web services to accept multiple ranges, there's nothing saying that you can't have the ranges overlap.  Bad implementation on Apache's part, but there's a good chance that other web servers are vulnerable.
Most Tomcat servlets don't allow Range requests, since it's a custom implementation of a filter to spew the right chunks of content.  However, the default servlet (which handles static content) is another story.
Current Tomcat code (here) accepts multiple range sets, validates each one individually that it's within the bounds of the file's size, and plops it in a list of ranges to serve.  However, the ranges are streamed out in sequence from the servlet's internal cache, and the process should be stopped immediately if the client requesting the data disconnects; in most cases, this should make the overlapping range request roughly equivalent to the performance impact of serving a large file.

And, to confirm, a quick test..
We'll send a quick request against / to get the size..
request:
HEAD / HTTP/1.1
Host: 192.168.100.200
Accept-Encoding: gzip
Connection: close

response:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Accept-Ranges: bytes
ETag: W/"1887-1314245401000"
Last-Modified: Thu, 25 Aug 2011 04:10:01 GMT
Content-Type: text/html
Content-Length: 1887
Date: Thu, 25 Aug 2011 04:18:05 GMT
Connection: close

Verdict is, 1887 bytes for the cute little "It works!" page.  That tells us the range we can use without Tomcat throwing away the range as out of bounds.
Ok, so let's check for whether it allows a quick overlap, bytes 0 to 10 then 5 to 15:
request:
GET / HTTP/1.1
Host: 192.168.100.200
Range: bytes=0-10,5-15
Accept-Encoding: gzip
Connection: close

response:
HTTP/1.1 206 Partial Content
Server: Apache-Coyote/1.1
Accept-Ranges: bytes
ETag: W/"1887-1314245401000"
Last-Modified: Thu, 25 Aug 2011 04:10:01 GMT
Content-Type: multipart/byteranges; boundary=CATALINA_MIME_BOUNDARY
Content-Length: 224
Date: Thu, 25 Aug 2011 04:17:11 GMT
Connection: close

--CATALINA_MIME_BOUNDARY
Content-Type: text/html
Content-Range: bytes 0-10/1887

<?xml versi
--CATALINA_MIME_BOUNDARY
Content-Type: text/html
Content-Range: bytes 5-15/1887

 version="1
--CATALINA_MIME_BOUNDARY--

Yup, sure enough - <?xml versi and version="1.  So overlapping works.
And, whether it'll allow a request for more data than is actually in the file being served:
request:
GET / HTTP/1.1
Host: 192.168.100.200
Range: bytes=0-1800,1-1886
Accept-Encoding: gzip
Connection: close

response:
HTTP/1.1 206 Partial Content
Server: Apache-Coyote/1.1
Accept-Ranges: bytes
ETag: W/"1887-1314245401000"
Last-Modified: Thu, 25 Aug 2011 04:10:01 GMT
Content-Type: multipart/byteranges; boundary=CATALINA_MIME_BOUNDARY
Content-Length: 3893
Date: Thu, 25 Aug 2011 04:19:51 GMT
Connection: close

--CATALINA_MIME_BOUNDARY
Content-Type: text/html
Content-Range: bytes 0-1800/1887

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <title>Apache Tomcat</title>

...(lots more data)...

Yup - nearly 4KB served of a sub-2KB file.
Amplify this approach to include an enormous number of ranges, and this is the basic structure of the attack.  In Tomcat's case, the real impact seems to be that it allows an attacker to get a large amount of data served in response to a request for a relatively small resource, which may prove helpful in targeting bandwidth for a denial of service.  I'd also be suspicious of the impacts in other edge cases; with a reverse proxy attempting to cache 206 responses, or when the requested resource is a file larger than would fit in the Tomcat cache.
Comment: Kudos for actually digging into the code...
Comment: Do you think that max heap size or tomcat's lower thread defaults might help tomcat in this case (or at least prevent swapping from occurring on the physical server)?
Comment: @mahnsc Tough to say without really hitting it and seeing how it responds - my gut feeling is to say that the java sandbox, heap size especially, will prevent it from completely exhausting a server's resource the way Apache does when hit with this, but that's just speculation.
Comment: Nevertheless, that sounds like enough to launch a DOS attack on Tomcat, if not the entire server.
Answer: Its not a vulnerability. read the Default servlet code. It loads the resource once. It also reads all the range offsets. Then it iterates through all the offsets serving the content bases on the original resource. Which is DIFFERENT as to how apache httpd did it. So it will not trigger an OOM exception.
You could argue that you could send a LARGE AMOUNT of Range headers to make an exhaustive list or ranges to return. But that is a specific example of a DOS attack on sending too many headers. In which case tomcat and httpd have ways to limit too many request headers as well as their size.
--update Oct 4, 2011--
Tomcat could be open to an attack where a connection can be held open longer than normal. But this type of attack is no different than your standard DOS attack. It just allows the attacker to be "more efficient" by making a request serve more bytes than it normally would serve.
The only extra resources consumed by such an attack is bandwidth and open socket connections. So it is no different than a standard DOS attack. The only difference is the attacker can be slightly more efficient. But you haven't gained any extra protection by having Tomcat try to perform extra validations on the range.
Comment: The crux of the "vulnerability" is the acceptance of overlapping ranges in strict compliance with an RFC; it's behaving correctly, and that opens it to attack; whether to call that a "vulnerability" is a semantic discussion.  The default servlet will gladly serve a large number overlapping ranges (all in one header), generating a response much larger than the actual resource being requested.  It doesn't seem to do that in a way that's as cripplingly resource intensive as it is with Apache, but, [less susceptible still means susceptible](http://serverfault.com/q/317226).
Comment: Hmm.  Just saw that the reason you posted this here was because of a bug being filed against Tomcat based solely on my answer - sorry about that.  As I tried to make clear in my post, it serves overlapping ranges happily, but that doesn't mean that it'll bring a Tomcat server to its knees any more quickly than a normal request would - and that I hadn't tested the real performance impact.  Though, regardless, I'd still have some concerns about allowing unlimited overlapping ranges (a setup with a proxy that didn't RST its backend connection when the client dropped would crumple, for instance).
Comment: (re: edit) That's a fair assessment. I'd still argue for validation code stopping overlapping ranges, as I'd be concerned for deployments that include proxy servers that try to cache 206 responses.. but, I'll edit my answer to make the actual impact more clear.
Answer: tl;dr: Probably not.
Given that Apache httpd and Tomcat are different products, and I can't find mention of an equivalent vulnerability announcement in Tomcat, I'd lean towards "no".  There's no details in the announcement as to what the exact bug is, so it's hard to say if it's likely that this could be a common programming bug, or something really quite specific to Apache httpd.


How would a language of whistles work

Question: The language consists of 3 different tones: high, medium, and low. There are trills (~), chords(=), neutral tones (-), rising tones (<), falling tones (>), and rising/falling tones (^). Would the combinations of the whistles make words, or would the collection of tones limit it to a 6 letter alphabet?
Comment: There's a literature on this which I have not read. As well as drum speech in West Africa, I various whistle languages around the world can operate *at least* like a shorthand for a shared spoken language. Suppose you *could* only whistle the vowels, tones, and prosody. Still you could make "Hello," "Come back," "Run," "Help" clear even for the novice. Perhaps extant whistle languages do even more!

If your speakers have or can learn perfect pitch, you can multiply a number of pitches, length, length of pause, etc. I am sure musical conlangers have worked up more inspiration :)
Comment: @Vir, Thanks, I hadn't thought of pauses or length of tones/pause. The species I was going to make communicate (in a sci-fi book) would definitely have perfect pitch.
Comment: Yea! About lengths, even novice musicians can hear several fractions of a note, eh? If for instance everybody knew that any "letter" was going to be at least a half note, then quarter note combinations of your other elements could multiply your possible combinations once again, eh? So you could not just have 12 notes of the chromatic scale possible for each "letter", but 12*12=144 before you get into the "tone" you put on it, the variable spacing, etc: combinations overmatching combinations of English's ~26 letters. Give flavor by limiting this excess with "phonotactics."
Comment: Actually, with these elements discussed, you have so very much more "material" than you need just to make words, some others can indicate grammatical information: tense, case, part of speech, plurality...
Answer: Real-world "whistled languages" are generally adaptations of spoken languages, taking some aspect of the phonology (tone, prosody, sometimes formants) and conveying it through whistling. A lot of information is lost, but there's enough redundancy that native speakers can still understand—much like how English-speakers can understand whispering, which discards most information about voicing, or styles of singing that discard some formant information.
It sounds like that's not what you're looking for, though. The rest of the answer is built on the assumption that you're trying to make a language which is only whistled, rather than using whistling as a lossy way of conveying a spoken language.
Languages with very few phonemes exist in real life, so an inventory like that is plausible enough. If you want to figure out what the words would look like, I think this is a place where some basic information theory could be useful.
The core idea behind information theory is that you can consider a lot of different things (including a spoken language) as a series of discrete signals, transmitted one at a time from a source to a receiver, and then use some mathematical structures to analyze that. If you've got three tones and six contours, and each phoneme consists of exactly one tone and one contour, then you've got eighteen possible signals. Not knowing anything else about your language, this means you can transmit a bit over two bits of information per phoneme. Each English word generally conveys about eight bits of information (given context and such)—so completely ignoring phonotactics, syntax, and various other aspects of your language, you could theoretically encode the same amount of information as an English word with four phonemes.
Once you add those aspects in, the information load per phoneme will probably decrease somewhat (since all the signals won't be equally probable in all contexts), so I'd expect it to take about six of your tone-plus-contour phonemes to convey the equivalent of one English word. That sounds like a plausible word size to me.

How would a language of whistles work


Do you require deep packet inspection on a server-only firewall?

Question: I have a server behind a firewall. It runs a web application (Java servlets under Apache Tomcat) and responds only to port 443 (HTTPS). There is no scripting code in the pages served - the forms use HTTP POST to receive the form, process the data (with appropriate input filtering) and then output an HTTP result page.
I am currently using an appliance firewall, but it is 'hardware-flakey'. I have been looking at upgrading to a more 'industrial strength' solution, but the vendor is quite insistant that I purchase a subscription to their "deep packet inspection" software. He claims that even web servers need this kind of protection.
I am not convinced, but do not have the security background to be certain. The firewall would sit between the "world" and my server, and use "port forwarding" to allow only ports 443 and 22 (for maintenance) to reach the server.
So - do I really need this deep packet inspection, or not?
Answer: Given that the only protocols that you're interested in (ssh and https) are "negotiate encryption on connect" there's little that a standard firewall will be able to inspect after that point. Once the SSL/SSH session is established the firewall will only see encrypted packets. Ask your vendor what their product examines in this context.
Alternatively, it is possible that the device acts more like a proxy -- that it acts as the server-side end-point for the connection before relaying on to your real server -- in which case it is possible that the product does something deeper, although this isn't the case if the firewall really is "port forwarding" as you say. Again, your vendor should be able to explain how their device operates.
Also you may want to ask what vulnerabilities/risks the inspection system is intended to protect against. For example: Does it look out for SQL injection? Is it targetted to a particular platform? (If your web server runs on a SPARC CPU, for example, then there's little point inspecting URLs for x86 shellcode).
Answer: Update on several fronts...
First - I now have reason to believe that part of the flakiness of the OTS hardware product is a combination of low-powered CPU and insufficient buffer memory. In weeks of logging and a few crashes, there are no entries in the logs before the crash, yet I'm logging everything according to the log control. Talking with another firewall vendor, it was indicated that may suggest the buffer is filling faster than it can empty during heavy use. This corresponds with findings - the most used IP is the one crashing the most often.
So I checked, and the firewall did have some deep packet inspection stuff turned on. I've turned it off to see if things improve.
The firewall's main purpose in my network scenario is "gate keeper". That is, I want the firewall to prevent all traffic EXCEPT http, https and some ssh from ever getting beyond the WAN port. Since there are no users inside the firewall, any traffic generated from the inside comes from my application and can be allowed out.
Further talks with the one vendor indicated that they no longer thing deep packet inspection is necessary - the other fellow was just trying to "upsell" me on the unit in question. I also found out their hardware won't really do all that I want without spending a ton of money.
I'm now seriously exploring the use of OpenBSD and a PF firewall to do what I reauire in a cost-effective manner.
Answer: As a network security professional, this sounds like overkill to me.
Martin Carpenter's answer is 100% on target.  Anytime you're considering security, you need to understand

What you're securing,
What you're securing it against,
The likelihood of an attack, and
Your risk if an attack succeeds.

For your application, which allows only encrypted, authenticated communication on only 2 ports, I can see only a few vulnerabilities:

Denial-of-service (DOS) is always a threat unless your firewall blocks those attacks.
You might have other applications listening on other ports, but you can detect them with any simple port scanning program.
You may want to restrict outbound communication to prevent a user or rogue application from initiating communication to an unauthorized server.

I also agree that it's a good idea to ask the vendor what "deep packet inspection" means to him and why your particular situation requires it.  Unless you get a specific, knowledgeable answer, in layman's terms, that makes sense to you, I'd go elsewhere.  There's nothing about network security that can't be explained simply, without buzzwords.


Why is Max Date not working?

Question: I have a simple query that I just want to return the most recent date for.
I can't figure out why I can't do this:
Comment: Please don't use screenshots for code snippets: http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question
Comment: Your screenshot shows invalid standard SQL. Which DBMS are you using?
Comment: Remove `pc.recalc_date` from the `Group by` since you want the `Max` of that column.
Comment: @a_horse_with_no_name with invalid you mean the single quotes aliases, I guess?
Answer: It looks to me like you don't quite understand how to use GROUP BY.
A query with GROUP BY will identify the unique sets of values for the grouped-by columns, and then will allow you to use aggregate functions on any other rows in the data set.
So, first you've said, give me the unique values for the four columns in your query.
Then, you say, give me the maximum pc.recalc_date for all the rows identified by each of the unique value sets.
Since pc.recalc_date is one of the values you're grouping by, all the records in each group will have the same pc.recalc_date.
I'll assume that, for each part # and description, you want the date of the most recent change in cost, and what that cost was.
Without more information, it's difficult to give you a specific solution and guarantee it will work. We don't know what database you're using, not to mention what version of that database. Similarly, we don't know the data types and lengths of your columns.
I believe the most generic answer would be a two-step process. First, identify the date of the most recent price change for each part; then, get the corresponding price. I'll be assuming your part numbers are up to 20 characters long, your description up to 250 characters long, and that the type of your pc.recalc_date column is datetime; replace with valid values for your system.
That would look something like this (assuming you have access to temporary tables in your language):
    CREATE TABLE #latest_price_change
           (part_no varchar(20), part_desc varchar(250), recalc_date datetime)
INSERT INTO #latest_price_change (part_no, part_desc, recalc_date)
SELECT pvp.part_no,
       pvp.name,
       MAX(pc.recalc_date)
  FROM part_v_part as pvp
  JOIN part_v_part_cost as pc ON pvp.part_key = pc.part_key
 WHERE pvp.part_status <> 'inactive'
   AND pvp.part_status <> 'obsolete'
   AND pvp.part_source_key = '373'
   AND pvp.part_no = '90-0018'
 GROUP BY pvp.part_no, pvp.name

SELECT lpc.part_no as 'Part No.',
       lpc.part_desc as 'Description',
       lpc.recalc_date as 'Previous Update',
       pc.cost as 'Previous Std. Cost'
  FROM #latest_price_change as lpc
  JOIN part_v_part as pvp ON lpc.part_no = pvp.part_no
                             AND lpc.part_desc = pvp.name
  JOIN part_v_part_cost as pc ON pvp.part_key = pc.part_key
                                 AND lpc.recalc_date = pc.recalc_date

After setting up a part_v_part and a part_v_part_cost table that returned the same three lines as yours did when using your query, I just got back the last line with my query.
FYI - I tested this with MS SQL Server 2012.
Hope this helps.
Answer: You have added pc.cost as a group by column.  This means your query will pull all (distinct) values of pc.cost and all records associated with them.
You either need to remove pc.cost from your SELECT and GROUP BY, or you need to put a function (MAX, MIN, etc) on pc.cost as well (and remove pc.cost from the GROUP BY anyway).

Why is Max Date not working?