Data with a lot of zeroes

Question: Please forgive a simple-minded question. I'm looking at a dataset now of a few thousand values, and trying to analyze it statistically. Most of the values, about 90%, are zeroes, and then the rest are positive integers from 1 to about 50, with most of them under 10 (it is number of parasites found on an animal). I'm just wondering whether someone can tell me some common techniques to use in a situation like this. I thought this might be "sparse data", but when I googled that I found mostly stuff about machine learning, and it didn't seem to be what I was looking for.
Thanks for any help,
Greg
Answer: The keyword you are after is zero-inflated models. You can find many questions concerning them under the zero-inflation tag. If your data is counts, a possible candidate would be zero-inflated Poisson model.
Comment: That's the thing, thank you!

Data with a lot of zeroes


How to use a private method from the super class in the sub class in Java?

Question: I was just wondering how I would use something to get or use a private method from the super class in the sub class in java. I know that is a handful, but basically I want to know if I create a private method in a parent or super class, then what would be the code to bring in that private method into the sub class.
All help is greatly appreciated from this question.
NOTE:
I know that this question is similar to the question:
How can a derived class invoke private method of base class?
On this site Stack Overflow
However, the question answer for the question seem complex and hard to read for a beginner as well as not being the correct answer to the exact way that I am asking this question.
Comment: Fix your design. If it's private you shouldn't be calling it.
Comment: @EJP I know that it is a stupid scenario and you could easily just make that method public or even protected, but I just want to know if there is a way to do it
Comment: You can use reflection.
Comment: Yes, it is a really bad idea, and yes, there is a way to do it. See http://stackoverflow.com/questions/11483647/how-do-i-access-private-methods-and-private-data-members-via-reflection
Comment: @shmosel what is reflection
Comment: See the link above and [this tutorial](https://docs.oracle.com/javase/tutorial/reflect/).
Comment: @AndyThomas thank you very much! This looks helpful, I don't mind going through that site; however, is there just an easier way of explaining so that I could try to figure it out myself without just getting the answer feed to me through the site with an example
Comment: @shmosel, sorry, I dodn't see the tutorial part was in blue based on my color blind issues. I thought that you were referencing the link above as a tutorial. That is why I edited the question and commented what I had earlier
Comment: @user7471732 - The short form is that 1) access control like `private` is there to prevent you from making mistakes in normal code, and 2) reflection allows you to inspect classes and objects without enforcing access control. To use reflection, you'll have to dive into the details, either through this site or a tutorial or a reference.
Comment: @AndyThomas Okay, so your basically ignoring the rules that make something private, public, or protected
Comment: @AndyThomas That should be enough. Thank you for all of your help
Comment: @AndThomas Also, I am sorry that I even made this question. If I had scene the link for the question that you linked about reflection. I wouldn't have posted that question. However, when I searched my question up and when I was typing the question. The question that you should be did not come up under the related or suggested questions.
Comment: Thank you everyone for all your help
Answer:
I want to know if I create a private method in a parent or super
  class, then what would be the code (in the form of an accessor or
  mutator method) to bring in that private method into the subclass.

You can't. That's what private means. Make it protected instead.
Comment: No, I know how you would do it for protected. But, my teacher must have mispoke then. Sorry
Comment: Are you sure you want to access a private *method* and not a private *variable*?
Comment: No, I know that there some way to access a private variable from reading other questions on this site. That is not what I am looking to do though.


Confusion on Parallelogram

Question: i know it's rude and pretentious and maybe stupid to ask such question but, i would like to know the reason why in geometry the area of a parallelogram follows this formula :
$ Base \times Height $
and not this one :
$ Base \times Side $
I saw this method which consists of transforming our figure into a rectangle by moving the black one to the right, and that seems logical to me, but why not adopt the second rule, all the horizontal points multiplied by the vertical ones ?

PS :  I found the same Visualizing the Area of a Parallelogram, but was unconvinced by the answers
Comment: In mathematics, there is nothing rude and pretentious about asking questions
Comment: @kkc, did you see the link ?
Comment: @Taladris thank you :)
Answer: Sometimes a figure is worth 1000 words:

Very long base and very long side and very small area.
Or...
...each of these parallelograms has the same base and side, but manifestly different areas:
Comment: *EVER*?  My goodness... thanks.
Comment: The best answer ever :)
Answer: You can't "adopt the second rule" because it gives the wrong answer. The parallelogram in your picture has all four sides of length $5$, There are lots of parallelograms like that, depending on the angle between adjacent sides. The largest is a square. If you make the acute angle smaller and smaller you find parallelograms that are nearly on a line, with tiny areas. But your formula would say they all have area $25$.
Answer: You have to have some notion of what area must satisfy (otherwise, you could just say that area of everything is 0 and be done with it:). I think a principle with which you'll agree is that if one figure is a subset of another, it cannot have greater area.
Well, in that case, imagine a world that looks like yours, where the area of any paralelogram is calculated according to formula you give---and look at the following picture:

As you see, by Bo's formula, the area of AECF would be 13*5=65, while the area of a containing rectangle (which is also a parallelogram) would be (13+3)*4=64<65. Contradiction.
Comment: +1: This is an *excellent* refutation.
Answer: As you point out, the first method is logical, as it uses a formula we already know to be true (the familiar area formula for a rectangle), and then transforms our figure without changing the area, so that we can apply the rule.
To see why we can't simply multiply $5$ and $5$ to get the answer, draw the $5\times 5$ square. Your parallelogram can't fill it by cut and paste. Alternatively, you can draw $25$ unit squares, and try to cut and paste them into the parallelogram. You'll only be able to make $20$ of them fit.
Answer: Hint:
Drop a $\perp$ to a point say $F$ from $C$, prove that $\Delta AED \cong \Delta CFB$ and now consider the $\text{ar}(\parallel \text{gm} \ ABCD)$ as the area of this rectangle because they're both equal and the area of the rectangle is very well known to be $\text{base}\cdot\text{height}$.
You may also want to see this fact as a consequence of the $2$-D analog of Cavalieri's Principle.

Confusion on Parallelogram


returning another class when instantiating a class in python

Question: I am trying to use logging's memory handler to buffer log messages to my actual logging handler. You use the memory handler by instantiating it with some arguments, like this:
import logging
buffered_handler = logging.handlers.MemoryHandler(capacity=5,target=myActualHandler)

However, I don't want my application to have to instantiate a handler from logging directly, or pass any of the arguments; I'd like this code to look like this:
import myhandlers
buffered_handler = myhandlers.BufferedRemoteHandler()

The question is: how do I do this? I'd like an attempt to instantiate my BufferedRemoteHandler to actually return logging's MemoryHandler with some specific arguments. I thought of just making BufferedRemoteHandler a function which returns the handler I want; is that the correct way? Is there a way to create a class which, when you instantiate it, actually returns a totally different class?
Answer: Maybe point 3 of PEP 8 is the answer:
Simple is better than complex.

I'd go the function way. Maybe call it something like get_handler() (or get_buffered_remote_handler()) though, so you realize it is something other than a real class at first glance.
Comment: Usually a function of this type is called a Factory Function. In this case you could refer to it as a Handler Factory
Answer: To answer your exact question, you may, if you like, override __new__() on your subclass to return an instance of a class other than yours.
import logging

class BufferedRemoteHandler(object):
   def __new__(cls):
       return logging.handlers.MemoryHandler(capacity=5,target=myActualHandler)

But I'd actually suggest the function.
Comment: thanks for answering the question! this looks pretty elegant; are there any other reasons besides simplicity for recommending the function route?
Comment: @Igor, how about the principle of least astonishment?
Comment: I'd agree. Returning an instance of some other class is a kind of surprising outcome for a class instantiation operation.
Answer: Yes just make it a function. Something like getMemoryHandler(). THat's the best way to do it. Also, if only one instance of MemoryHandler is going to be around you may want to make it a singleton.
Comment: the singleton in this case is already the `logging` module itself; you set it up once with your handlers and settings, and every subsequent instantiation/import uses those.
Answer: Well, to answer you directly, yes, there's __new__().  However, I think what would probably be an easier solution would be to either hard code or allow special handler definitions to be registered to myhandlers.  You'd define a member method for each handler you want in myhandlers that just instantiated the MemoryHandler as you want and returned it.


Is this goal allowed on steal from keeper?

Question: Scenario: A football keeper throws the ball in the air to kick it out, but the other team's striker kicks it away before the keeper can make contact. The striker scores on the play. Should the goal be disallowed?
Answer: This goal would not be allowed, as the ball is still considered in the goalie's possession.

While the ball is in the possession of the goalkeeper, it cannot be played by an opponent. Any attempt to do so may be punished by a direct free kick.  "In the possession of the goalkeeper" is defined as the goalkeeper having the ball trapped between one hand and a surface (which may include the other hand, the ground, a goalpost, or the keeper's own body).  International Board Decision Two of Law 12 emphasizes that the hand includes any part of the hand or arm.  However, as stated in the Advice to Referees on the Laws of the Game (Advice 12.16 and 12.17), the goalkeeper is also considered to be in possession of the ball while bouncing it on the ground or while throwing it into the air.  Possession is given up if, while throwing the ball into the air, it is allowed to strike the ground.
  ...

Additionally,

When is Possession Lost?
  The critical question is when the goalkeeper has released the ball into play and thus has allowed the ball to be played by an opponent.  Based on traditional interpretations of this issue and the International Board's Questions and Answers, the referee should consider the ball as having been released into play after leaving the goalkeeper's hands only if the goalkeeper has completed a throw or kick (punt) and the goalkeeper is not able directly to possess the ball again in his or her hands.  Thus, the ball is not playable by an opponent during the entire time it is being held by the goalkeeper (including when the ball is being bounced on the ground) or during the entire process of being released into play (including the action of throwing or kicking/punting the ball).  In short, opponents may play the ball only if the goalkeeper has clearly distributed the ball by kicking or throwing it.

http://www.ussoccer.com/stories/2014/03/17/12/02/playing-the-ball-in-the-goalkeepers-possession
Comment: @studro They're attempting to differentiate (perhaps poorly) between a keeper tossing the ball in the air for a kick, and a keeper "dribbling" the ball basketball-stype on the ground, as they often do.If they toss the ball in the air and miss the kick, it's a live ball.  This is in the directions to the referees, so things like that tend to be left a bit more open to interpretation.
Comment: @Studro, you do understand that a dropkick is referencing a punt, where the keeper drops the ball and kicks it while it is in the air.
Comment: `Possession is given up if, while throwing the ball into the air, it is allowed to strike the ground.` This is not correct.
Comment: Please elaborate on how this is incorrect. If the keeper attempts to kick the ball and misses, allowing it to bounce, it becomes a live ball. @studro
Comment: The ball is still in possession of the goalkeeper if it is allowed to bounce. See the [2015/16 FIFA Laws of the Game](http://www.fifa.com/development/education-and-technical/referees/laws-of-the-game.html), page 122.
Comment: However if the keeper throws the ball and allows it to bounce after they toss it, the ball becomes live. That is what the sentence is stating. @studro
Comment: But that's not true. If the ball is thrown, bounces once, and is then re-caught, the goalkeeper has not relinquished possession.
Comment: Joe is correct and I believe that is just what they are saying. Yes, bouncing it once and catching it again is still in possesion, attempting a kick and missing is surrendering possession of the ball. @studro
Comment: There is no difference between basketball-style bouncing the ball on the ground and catching it, and dropping the ball on the ground for a drop kick and then deciding to recatch it either deliberately or after a miskick when it has only bounced once. ATR may be followed in the US, but it is not applicable elsewhere in the world. According to a reading of the Laws of the Game (the only document that should be relied upon), it's clear that if the ball is recaught after one bounce, no matter how it was caused, possession was never relinquished.
Comment: @studro additionally, the FIFA Rules of the Game you keep pointing to does not outline when the keeper relinquishes the ball on a save other than after 6 seconds.
Comment: @studro I would also like you to note that in direct response to your comment about this is not applicable anywhere else in the world. This statement in provided at the top of the article I linked in my answer: This article is designed to help make referees and players aware of what constitutes goalkeeper possession and what opponents may and may not do when the goalkeeper has possession.

Watch an Application of This Law From a World Cup Qualifier Between Trinidad and Bahrain
Comment: A dropkick is **not** a punt. A punt involves the ball being dropped and kicked before the ball hits the ground. A dropkick involves the ball bouncing once and then being kicked. [See here](https://en.wikipedia.org/wiki/Drop_kick) for more detail. I'd respond to the other points you've made, but we're going in circles here and I feel the effort is wasted.
Comment: Thank for completely disregarding my points and abandoning the argument
Comment: I regarded your points, and disagreed. I stopped replying because [comments are not for extended discussion](https://meta.stackexchange.com/questions/95937/why-must-we-avoid-discussions-in-comments) and even after repeating the points I'm making, I see there being no change in your views. We should simply agree to disagree.
Answer: Yes, the goal should be disallowed. It also makes no difference as to whether the ball has hit the ground (ie. for a dropkick rather than a punt).
The restart of play is an indirect free kick for playing in a dangerous manner, awarded to the goalkeeper's team.
The relevant information from the 2015/16 FIFA Laws of the Game, pages 122 - 123:

A goalkeeper is considered to be in control of the ball:

while the ball is between his hands or between his hand and any surface
  (e.g. ground, own body)
while holding the ball in his outstretched open hand
while in the act of bouncing it on the ground or tossing it into the air

When a goalkeeper has gained possession of the ball with his hands, he cannot be challenged by an opponent.
...
A player must be penalised for playing in a dangerous manner if he kicks or
  attempts to kick the ball when the goalkeeper is in the process of releasing
  it.

and on page 38:

An indirect free kick is also awarded to the opposing team if, in the opinion of the referee, a player:

plays in a dangerous manner
Comment: Do you have a source released by FIFA to support this assertion?
Comment: There clearly has to be *some* point at which the goalkeeper is deemed to have given up possession - they can't roll the ball 20 metres downfield and claim "I'm drop kicking, I just didn't do it very well."
Comment: Rolling the ball along the ground would be relinquishing possession. As quoted, letting the ball bounce once is definitely not.
Comment: But it does make a difference whether it has hit the ground. If the keeper attempts a kick and flubs it, then the ball is live and he has given up the ball. It is the same if he misses the kick entirely.


Precision on the incompleteness of the field of clopen subsets of the Cantor space

Question: Let $F$ be the field of clopen subsets of the Cantor space $2^\omega$. Then $F$ is countable, atomless, and incomplete.
Question: What does incomplete mean precisely? Does that mean that not every subset of $F$ has a least upper bound (equivalently, a greatest lower bound), or does that mean that none of the subsets of $F$ have a least upper bound (or greatest lower bound)? It is the fact that $F$ is both countable and atomless which confuses me.
Answer: Suppose that $O$ is an open set of $2^\omega$ such that $\overline{O}$ is not clopen. (There are plenty of those as we have $\mathfrak{c}$ many open sets but only $\aleph_0$ many clopen ones.).
As the clopens form a base for $2^\omega$ we can write $O = \bigcup \mathcal{C}$ for some countable family of clopen subsets $\mathcal{C}$. Then $\mathcal{C}$ does not have a supremum in $\operatorname{Clop}(2^\omega)$:
Suppose  we have a clopen set $D$ that contains all members of $\mathcal{C}$(so an upper bound), then  $O  =\bigcup{C} \subset D$, and also $\overline{O} \subset D$, by how we chose $O$, $D \setminus \overline{O}$ is non-empty open and so contains some non-empty clopen set $D'$ and then $D \setminus D' $ is a strictly smaller clopen upperbound for $\mathcal{C}$, so no smallest upperbound exists.
This is what the incompleteness means, there are some (necessarily infinite) subsets of $\operatorname{Clop}(2^\omega)$ that do not have a supremum in it.
In $\operatorname{RO}(2^\omega)$ (the completion of $\operatorname{Clop}(2^\omega)$) the supremum of $\mathcal{C}$ is $\operatorname{int}\overline{O}$, of course.


Differentiability in two variables - directional derivative & gradient

Question: I have read a chapter about differentiability in two variables. I now have two questions:

Why do we need the constraint that $|\vec{u}|=1$ when we calculate the directional derivative?
Definition of gradient:  $\nabla f  = \frac{\partial f}{\partial x_1 }\mathbf{e}_1 + \cdots + \frac{\partial f}{\partial x_n }\mathbf{e}_n$
but why do we need f to be differetiable? Is it simply becuase we "take the partial derivatives"? I have learned the pure defn of differetiable, but maybe I don't have the "gut feeling" of what it really is, in simple language.
Answer: 1) You are free to choose $u$ not unitary. But you have to be careful. For example, if $|u|=2$ you get double the amount you get with $|u|=1$, as it means that you are "moving twice as fast".
For example, consider a function $f(x,y)$, and consider the "curve" $(x=t, y=0)$, which is a straight line along the $x$ axis.
How do we "see" $f$ from "inside" the curve? We get:
$$
f(x(t), y(t))  = f(t,0).
$$
The derivative of $f(t,0)$ with respect to $t$ is exactly the directional derivative in the direction of $x$.
Now pick the "curve" $(x=2t, y=0)$, which is a straight line like before, but now the "speed" is double. What happens now if you calculate:
$$
f(x(t), y(t))  = f(2t,0),
$$
and derive it with respect to $t$?
2) "Differentiable" intuitively means that "its partial derivatives exist and behave well". Which translates to: "if $f$ is not differentiable, it makes no sense to talk about its gradient."
Comment: can you elaborate on 1) ?
Comment: @jacob Edited the question, adding an example...Let me know if it is clear!


PHP unable to mail() in chroot though I can use sendmail inside chroot

Question: I'm building a php-fpm chroot, and am on one of my last steps before calling this a success.
The php-fpm chroot is working like a charm. Also, I have mini_sendmail installed into the chroot (in place of stock sendmail) and can confirm that it can send email:
[root@hostname site1.com]# ls bin/
bash  cat  sendmail  test.txt
[root@hostname site1.com]# chroot .
bash-4.2# cat /bin/test.txt | ./bin/sendmail -t -i -firstname.lastname@example.com email@example.com

I get the email when the above command is run.
However, when I access the following php script from a web browser, no email is sent:
<?php
    $message = "This is a test";
    $headers = 'From: email@example.com';
    mail("email@example.com", "Test", $message, $headers);
    echo "mail sent";
?>

Below is my php-fpm chroot pool config file:
[site1.com]
user = user1
group = user1
listen = 127.0.0.1:9001
listen.owner = user1
listen.group = user1
php_admin_value[disable_functions] = exec,passthru,shell_exec,system
php_admin_flag[allow_url_fopen] = on
php_flag[display_errors] = on
php_admin_value[short_open_tag] = On
php_admin_value[doc_root] = www
php_admin_value[error_log] = /logs/php-errors
php_admin_flag[log_errors] = on
php_admin_value[sendmail_path] = /bin/sendmail
php_admin_value[mail.log] = /logs/maillog
php_admin_value[error_reporting] = E_ALL
pm = ondemand
pm.max_children = 5
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chroot = /home/www/site1.com
chdir = /www
catch_workers_output = yes

When I access the php file from a web browser, I can confirm that there's a log entry in the maillog as defined by the php_admin_value[mail.log]:
mail() on [/www/mailer.php:4]: To: email@example.com -- Headers: From: firstname.lastname@example.com

However, nothing shows up on the server's maillog (outside of the chroot), and nothing shows up in the php error log.
How can I finish troubleshooting this last step of getting php's mail() function to work as desired in my php-fpm chroot? Or, how can I fix the actual problem?
Comment: can you change your test by
`if(mail("email@example.com", "Test", $message, $headers))
 {echo('OK');}
else {echo('ERROR');}`
Comment: I get an 'ERROR' all right. That's a step in the right direction, anyway. Thanks for the tip.
Comment: I turned up the error_reporting value in the php-fpm config file (php_admin_value[error_reporting] = E_ALL) and I'm still not getting anything in the logs.
Comment: i don't know php-fpm, so i can't help you much ... any log from normal php ? if sendmail works and php-fpm not, it look like php-fpm doesn't have the rights to use your default smtp server configured in your php.ini (if it work as php)
Comment: Did you manage to solve this? I got the exact same problem here. PHP-FPM with chroot, sendmail is reachable via php's stat(), so chroot seems to be configured correctly, sendmail itself is working from command line. I also only get those "non-saying" log-entries, like you. But mail() still returns FALSE and does not send any email. And: Running the script on command line also works.
Answer: I know this is quite an old question, but I found this as one of the hits while trying to solve the same issue and so in case anyone hits this in future there's another thing to check. In my case I was missing /bin/sh from the chroot environment.
php passes sendmail_path into popen. popen passes the command to /bin/sh and so if your chroot environment is missing /bin/sh you seem to get a failure with nothing logged


Karma closing browsers after gulp test

Question: I'm running basic jasmine tests using the Chrome and Firefox launchers in karma, from gulp. But my browsers are always being closed afterwards. Regardless of success or failure in tests, even after specifying single run as false in the task and the config.
Gulp task:

 karma = require('gulp-karma');

gulp.task('test', ['testsSetup'], function() {
  // Be sure to return the stream
  // NOTE: Using the fake './foobar' so as to run the files
  // listed in karma.conf.js INSTEAD of what was passed to
  // gulp.src !
 return gulp.src('./foobar')
  .pipe(karma({
   configFile: 'karma.conf.js',
   singleRun: false
}))
    .on('error', function(err) {
      // Make sure failed tests cause gulp to exit non-zero
      console.log(err);
      //this.emit('end'); //instead of erroring the stream, end it
    });
});

karma.conf.js:
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome','Firefox'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false

Last part of the gulp output from successful tests:
Chrome 43.0.2357 (Windows 7 0.0.0): Executed 3 of 3 SUCCESS (0.041 secs / 0.036 secs)
Firefox 38.0.0 (Windows 7 0.0.0): Executed 3 of 3 SUCCESS (0.001 secs / 0.013 secs)
TOTAL: 6 SUCCESS
Chrome 43.0.2357 (Windows 7 0.0.0): Executed 3 of 3 SUCCESS (0.041 secs / 0.036 secs)
Firefox 38.0.0 (Windows 7 0.0.0): Executed 3 of 3 SUCCESS (0.001 secs / 0.013 secs)
TOTAL: 6 SUCCESS
[11:09:27] Finished 'test' after 4.52 s
Process terminated with code 0.
Answer: When you use gulp-karma the arguments you pass in are different to the arguments you'd pass straight to karma.
The above singleRun parameter is ignored. I changed my task to the following (specifying an action instead) and it works as you'd expect:
gulp.task('test', ['testsSetup'], function() {
  // Be sure to return the stream
  // NOTE: Using the fake './foobar' so as to run the files
  // listed in karma.conf.js INSTEAD of what was passed to
  // gulp.src !
  return gulp.src('./foobar')
    .pipe(karma({
      configFile: 'karma.conf.js',
      action: 'watch',
      showStack: true
    }))
    .on('error', function(err) {
      // Make sure failed tests cause gulp to exit non-zero
      console.log(err);
      this.emit('end'); //instead of erroring the stream, end it
    });
});

Comment: I'm running my karma test exactly the same like this, I'm facing issue with my images load as files parameter is ignored from karma.conf file as it's ignoring singleRun command here, any help?

Karma closing browsers after gulp test


Memcache - Cached Data is always null

Question: Below is my try to use Memcache in a console application.
App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="enyim.com"/>

   </configSections>

 <startup>
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
 </startup>

<enyim.com>
  <memcached protocol="Binary">
    <severs>
      <add address="127.0.0.1" port="11211"/>
    </severs>

   </memcached>
  </enyim.com>
 </configuration>

C#
static void Main(string[] args)
    {
        DateTime dt = DateTime.Now;
        try
        {

            using (MemcachedClient memcache = new MemcachedClient())
            {
                string cachedTime = memcache.Get<string>("CachedTime");
                if (cachedTime == null)
                {
                    memcache.Store(Enyim.Caching.Memcached.StoreMode.Set, "CachedTime", DateTime.Now.ToString());
                 cachedTime = memcache.Get<string>("CachedTime");
                }

                Console.WriteLine(cachedTime);
                Console.WriteLine(dt);
            }
        }
        catch (Exception ex)
        {

        }
    }

Every time the value of cachedDate is NULL
Answer: Change App.Config to the following and it should work:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="enyim.com">

    </sectionGroup>
  </configSections>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>

  <enyim.com>
    <memcached>
      <servers>
        <add address="127.0.0.1" port="11211" />
      </servers>
      <socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:00:10" deadTimeout="00:02:00" />
    </memcached>
  </enyim.com>
</configuration>

Memcache - Cached Data is always null


Field structure of a given set

Question: Let $R$ be a ring. (Not necessarily commutative).
For every pair $(a,b)$ where $a , b \in R$ and $b \neq 0$, we define $S_{ab}$ as the set of pairs $(m,n) \in R \times R$ such that $an=bm$.
Let $F$ be the set of all distinct sets $S_{ab}$.
Further, operations $+$ and $*$ are defined on elements of $F$ as:
$$S_{ab}+S_{mn} = S_{xy}\;\; , \;\;\; x= an + mb, \;\;\; y=bn$$
$$S_{ab}*S_{mn} = S_{xy}\;\; ,\;\;\;\; x = am,\;\;\;\; y = bn.$$
Which of the following conditions is necessary and sufficient to make $F$ a field?
a) $R$ is a commutative ring but not an integral domain
b) $R$ is an integral domain but not a commutative ring
c) $R$ is a commutative integral domain
d) None of the above
This question was posed by a friend of mine. I guess it's from some entrance exam.
I believe it would be a field if $R$ is a commutative integral domain with $S_{0a}$ as the additive identity and $S_{aa}$ as the unity. The commutativity is needed for the unity to be well-defined and the integral domain structure for the additive identity. But I am still not very sure. The sets and elements mixture is confusing me.
Comment: Yes, you are right
Comment: @Vishesh Then you should add the above info to your question.
Comment: @DonAntonio. Done
Answer: Note that the way the question is posed, a) and b) are immediately wrong: If we obtain a field when $R$ is commutative, but not integral - how should the construction suddenly fail when $R$ is "accidentally" integral? Similar for b).
Assume $F$ is a field.
If $ab=0$ with $a\ne 0\ne b$,  then $S_{0,a}*S_{0,b}$ is not even defined. Hence $R$ is necessarily an integral domain.
Let $u,v\in R$. If $u=0$ or $v=0$ then trivially $uv=vu$. Hence we may assume $u\ne 0\ne v$. We have
$$S_{u,u}+S_{-v,v}=S_{uv-vu,uv} $$
and
$$S_{v,v}+S_{-v,v}=S_{0,v^2}.$$
Note that for $x\ne 0$, $S_{x,x}=\{\,(y,y)\mid y\in R\,\}$, hene $S_{u,u}=S_{v,v}$ and so $S_{0,v^2}=S_{uv-vu,v^2}$
Clearly $S_{0,v^2}=\{\,(x,0)\mid x\in R\,\}$.
Hence $(uv-vu)\cdot x = v^2\cdot 0=0$ for all $x\in R$. As $R$ is integral, we conclude $uv-vu=0$. Hence $R$ is necessarily commutative.
On the other hand, if $R$ is a commutative integral domain, one readily verifies the "usual suspects": $S_{0,a}=0$, $S_{a,a}=1$, $S_{-a,b}=-S_{a,b}$, $S_{b,a}=S_{a,b}^{-1}$. And of course we have associativity and distributivity exactly as we know it from fractions. Thus commutative integral domain is sufficient.
Comment: Thank you very much. I had covered the sufficiency part but was missing out on why commutativity was necessary. Cheers.

Field structure of a given set


Spring compatible scrypt password with python passlib

Question: How can I generate Spring compatible passwords from python?
I've got a spring application creating scrypt passwords that look like this in the db:

{scrypt}$e0801$QAqC0fvhY6iJPysiQsFnrcUg205njHo/6o+IDXDn33lxmZOCVBhb4NAqdafhuGmykCxQtMI5xP5zb7MYMUrU3Q==$sBeXCHOm6zQuGdSDKs+HeXnNQGg3bhRidmL+HU/ZTMM=

I'm trying to update the database directly with new passwords using python and passlib but cannot divine the correct setting_kwds for passlib from $e0801$:
>>> from passlib.hash import scrypt
>>> scrypt.verify('wBkfoBsxj9u3wLOZ', '{scrypt}$e0801$QAqC0fvhY6iJPysiQsFnrcUg205njHo/6o+IDXDn33lxmZOCVBhb4NAqdafhuGmykCxQtMI5xP5zb7MYMUrU3Q==$sBeXCHOm6zQuGdSDKs+HeXnNQGg3bhRidmL+HU/ZTMM=')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/gregn/.pyenv/versions/v2.7.16/lib/python2.7/site-packages/passlib/utils/handlers.py", line 789, in verify
    self = cls.from_string(hash, **context)
  File "/home/gregn/.pyenv/versions/v2.7.16/lib/python2.7/site-packages/passlib/handlers/scrypt.py", line 177, in from_string
    return cls(**cls.parse(hash))
  File "/home/gregn/.pyenv/versions/v2.7.16/lib/python2.7/site-packages/passlib/handlers/scrypt.py", line 181, in parse
    ident, suffix = cls._parse_ident(hash)
  File "/home/gregn/.pyenv/versions/v2.7.16/lib/python2.7/site-packages/passlib/utils/handlers.py", line 1207, in _parse_ident
    raise exc.InvalidHashError(cls)
ValueError: not a valid scrypt hash

Manually fiddling with the prefix format hasn't worked:
>>> scrypt.verify('wBkfoBsxj9u3wLOZ', '$scrypt$ln=1,r=8,p=1$QAqC0fvhY6iJPysiQsFnrcUg205njHo/6o+IDXDn33lxmZOCVBhb4NAqdafhuGmykCxQtMI5xP5zb7MYMUrU3Q==$sBeXCHOm6zQuGdSDKs+HeXnNQGg3bhRidmL+HU/ZTMM=')
False

I think ( but am not certain) Spring is using default SCryptPasswordEncoder settings because I found:
public static PasswordEncoder getPasswordEncoder() {
    final String encodingId = "scrypt";
    final Map<String, PasswordEncoder> encoders = new HashMap<>();
    encoders.put("bcrypt", new BCryptPasswordEncoder());
    encoders.put(encodingId, new SCryptPasswordEncoder());
    return new DelegatingPasswordEncoder(encodingId, encoders);
}

spring version:
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v1.5.18.RELEASE)

Thanks!
Answer: The one you provided is not a valid scrypt hash
{scrypt}$e0801$QAqC0fvhY....

This is the right format (just substitute {scrypt} with $s0)
$s0$e0801$QAqC0fvhY6iJPysiQsFnrcUg205njHo/6o+IDXDn33lxmZOCVBhb4NAqdafhuGmykCxQtMI5xP5zb7MYMUrU3Q==$sBeXCHOm6zQuGdSDKs+HeXnNQGg3bhRidmL+HU/ZTMM=

If you try to get the configurations with Password4j:
SCryptFunction.getInstanceFromHash("$s0$e0801$QAqC0...");

you get N=16384, r=8 and p=1. Use this configuration in your Python implementation.


devise - before filter in users controller and users scope in routes, correct implementation?, using rails

Question: I use devise for authentication.  In the users controller, I have:
before_filter :authenticate_user!

In the config/routes file, I have:
#DEVISE
devise_for :users
authenticated :user do
 resources :user
end

Do I really need the 'before_filter :authenticate_user!` in the users controller?  Isn't it duplicative?
Thanks for your feedback.
Comment: Yeah! You'll need that, but on application_controller
Answer: No, having that code in both the controller and routes file is redundant. It's totally up to you and your design philosophy whether you go with authenticating in the controller files or routes file, but choosing one path will help you stay organized when your app grows.
Here's a good explanation from the Devise wiki of the difference between using the before_filter in controllers and and using authenticate, authenticated, and unauthenticated with resources.
Comment: Thank you.  Good explanation!  I'm accepting your answer.


IntelliJ IDEA embeded terminal output encoding issue

Question: IDEA: IntelliJ IDEA 2018.2.3 x64
IDEA Embeded Terminal: "c:\cygwin64\bin\sh" -lic "cd ${OLDPWD-.}; bash"
I got build.gradle:
task info << {
    println "Привет, мир!"
}

When i run from embeded terminal gradle info i got output:
$ gradle info
Picked up JAVA_TOOL_OPTIONS: -Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8

\> Task :info
╨Я╤А╨╕╨▓╨╡╤В, ╨╝╨╕╤А!

But if i run cat ./build.gradle:
$ cat ./build.gradle
task info << {
    println "Привет, мир!"
}

I googled that problem and solution with additional Custom VM Options for IDEA not worked
-Dfile.encoding=UTF-8
-Dconsole.encoding=UTF-8

Answer: It depends on where VM options were set actually.
Please call export GRADLE_OPTS="-Dfile.encoding=UTF8" before gradle info - it should fix it.

In case of Windows Terminal please use CP866 encoding instead of UTF-8 for cyrillic letters, so first command will look like this:
set GRADLE_OPTS="-Dfile.encoding=CP866"
Comment: Please also find here other approaches on how to set `file.encoding`: https://stackoverflow.com/questions/21267234/show-utf-8-text-properly-in-gradle


In postfix how do you read (or get) virtual users email?

Question: This might seem like a dumb question, but... How do you read the mail for virtual users in postfix that have been created by virtual_mailbox_domain?
I've created a user named vuser that handles all virtual mailbox domain mail; I've even tested that my configuration works by sending a test email outside my network. But now I do not know how I'd check virtual users mail; and cant seem to find anything on Google about this.
Comment: Useful question, premature closure, 10 years later, I can understand what they are asking and it was exactly my question.  This is why ServerFault seems so hostile to users.
Answer: You need something that understands the maildir format. Dovecot and Courier are 2 common software services that provide pop/imap access. However there are a lot of applications that can read  maildir (see wikipedia for a good list).
Comment: Setting up a postfix virtual server is way beyond the scope of this site. There is an official guide that you can take a look at though, http://www.postfixvirtual.net/postfixconf.html
Comment: Postfix should be dropping all the mail for the virtual users in something like /var/spool/postfix/virtual/. You would then configure courier to look in that path for the mail. You would also need some sort of sasl authentication method for courier to authenticate the users against.


Kelley's proof that projection is an open map

Question: Why does Kelley (General Topology) go through the trouble of "making a copy" of the factor space in Theorem 2 of Chapter 3? The projection of an open basis set is clearly open by inspection, as Dugundji notes in his proof of the same theorem. This seems enough since the image of a union is the union of images... Thanks!
Comment: He's just being extremely careful about constructing a basis element whose image under $P_c$ will contain $x$.
Answer: It appears that Kelley constructs this map $f$ in order to have a right inverse for $P_c$. The inclusion $P_c[V]\subseteq U_c$ is obvious. The other inclusion
$$U_c\subseteq P_c[V]$$ is less trivial. For each $z\in U_c$ we have to find a point in $V$ wich projects to $z$. If we call this point $f(z)$, then this is almost equivalent to finding a right inverse $f$ to $P_c$. This $f(z)$ shall be the point $(f(z)_c)_c$ such that $f(z)_c=z$ and $f(z)_a=x_a$. These coordinates determine uniquely the point $f(z)$ (which is indeed in $V$ as $x_a\in U_a$ and $z\in U_z$) and it clearly projects to $z$, since $P_c\circ f=\text{Id}_{X_c}$.
After all, the basic idea is that an $x$ in $V$ can only exist if all $U_a$ for $a\in F$ and all $X_b$ for $b\notin F$ are non-empty. If he were less pedantic, he would just have written that for any $z\in U_a$ we can find a point in $V$ which projects to $z$, but he decided to make this point a function in $z$.
Note that $f$ is continuous and is a bijection onto its image. Since its inverse $P_c$ is also continuous when restricted to $f[X_c]$, it follows that $f$ is a homeomorphism of the factor $X_c$ to a subspace of the product space. This fact is useful, for example when you want to show that a property of the product space holds for every factor, e.g. $\prod X_a$ Hausdorff $\implies X_a$ Hausdorff, as you only need to show that it holds for subspaces.


Can a complex argument into this function ever yield a real result?

Question: I have a function defined as:
$f(z)=\frac{\Gamma{(z)}+1}{z}$
Are there any $z ∈ C$ (with nonzero imaginary part) such that $f(z)∈R$?
I tried substituting in $z=a+bi$ with $b≠0$ into the product and integral definitions of the Gamma function, but with little effect.
EDIT:
$f(z)=\frac{\Gamma{(z)}+1}{z}$
$f(a+bi)=\frac{\Gamma(a+bi)}{a+bi}+\frac{1}{a+bi}$
Introduce the variable $R$, denoting a real number. Then let $R=f(a+bi)$:
$R=\frac{\Gamma(a+bi)}{a+bi}+\frac{a-bi}{a^2+b^2}$
By definition $\Im(R)=0$. Re-arranging we get:
$R-\frac{a}{a^2+b^2}+\frac{b}{a^2+b^2}·i=\frac{\Gamma(a+bi)}{a+bi}$
Because $R$ can be any real number, the 'real' part of the equation may always be true for some R. Therefore, equating the $\Im$ parts of each side of the equation, we get:
$\frac{b}{b^2+a^2}=\Im(\frac{(a-bi)\Gamma(a+bi)}{a^2+b^2})$
Because $a,b$ are strictly real numbers, $a^2+b^2$ must be real and the same on both sides.
Therefore,
$b=\Im((a-bi)\Gamma(a+bi))$
$b=\Im((a\Gamma(a+bi)-bi\Gamma(a+bi))$
$b=a\Im(\Gamma(a+bi))-b\Re(\Gamma(a+bi))$
It follows that:
$\frac{b}{a}=\frac{\Im(\Gamma(a+bi))}{1+\Re(\Gamma(a+bi))}$
Adding 1 to both sides:
$\frac{b}{a}+1=\frac{\Im(\Gamma(a+bi))}{1+\Re(\Gamma(a+bi))}+\frac{1+\Re(\Gamma(a+bi))}{1+\Re(\Gamma(a+bi))}$
$\frac{b}{a}+1=\frac{\Gamma(a+bi)+1}{1+\Re(\Gamma(a+bi))}$
EDIT II
It turns out I may have proceeded incorrectly in the last step. You see, the last equation re-arranges to:
$\frac{z}{\Re(z)} = \frac{\Gamma(z)+1}{1+\Re(\Gamma(z))}$
And consequently:
$\frac{1+\Re(\Gamma(a+bi))}{\Re(z)} = \frac{\Gamma(z)+1}{z}$, which is the normal, real number solution. (i.e. $b=0$).
If we go back a few steps and instead eliminate the real part, we get the following:
$\frac{b}{a}=\frac{\Im(\Gamma(a+bi))}{1+\Re(\Gamma(a+bi))}$
$\frac{a}{b}=\frac{1+\Re(\Gamma(a+bi))}{\Im(\Gamma(a+bi))}$
Now, adding 1, we get:
$\frac{a}{b}+1=\frac{1+\Re(\Gamma(a+bi))+\Im(\Gamma(a+bi))}{\Im(\Gamma(a+bi))}$
$\frac{z}{\Im(z)}=\frac{1+\Gamma(z)}{\Im(\Gamma(z))}$
Therefore, if $z=a+bi$ with $b≠0$ then the only time when $f(z)$ can be real is when:
$f(z)=\frac{\Im(\Gamma(z))}{\Im(z)}$
Comment: Also, this post: http://math.stackexchange.com/questions/455306/real-and-imaginary-part-of-gamma-function seems to address the issue from here on out fairly rigorously.
Answer: The derivative of $f$ vanishes at many points on the real axis (at least once between every consecutive negative integers, just by looking at the limits there)
On some small enough complex neghbourhoods of those points, $f$ is then at least $2$-to-$1$, which means that there are complex inputs to $f$ that give real outputs.
Comment: Okay that makes sense. Thanks. I am hoping for a more general solution, if it exists at all. I'll edit the question with more of the work that I have done since.
Comment: @mercio: I've never seen this argument before, and I really like it :D
Answer: I will provide a heuristic method to conclude that yes, such values exist, using a domain coloring visual argument. A domain coloring applies a color to each point in the complex plane based solely on its polar angle --- i.e. write $a+bi=Re^{i\theta}$ and we assign the colors based on $\theta$ (the $R$ decides brightness, typically).
If I apply the (Python, mpmath) domain coloring algorithm to the identity function $f(z)=z$ I get the following image:
.
The important thing about this image is that you notice the positive $x$-axis is colored red --- clockwise from red we move towards yellow and counterclockwise from red we get magenta. If we were to continuously go from magenta towards yellow in a clockwise direction, we must pass through the reddish area (the center of which colors the positive real numbers).
Now I will apply a domain coloring to your function $f(z)=\dfrac{\Gamma(z)+1}{z}$:

Notice in this image there are many "fingerlike" structures on the right. As Joanpemo noted, many values where $z \in \mathbb{R}$ yield real values (and hence are colored red in the image). Where else could $f$ be real?
Since $f$ is the sum and quotient of functions continuous on $\mathbb{C} \setminus \{0,-1,-2,\ldots\}$, we know that the function $f$ is continuous near the fingerlike structures and our image shows magenta --> red --> yellow color transitions (i.e. argument transitions from negative to positive) of $f(z)$ near the fingerlike structures.
It also appears that there is a sequence of strange areas going left along the $x$-axis near each nonpositive integer. These structures come from the fact that $\Gamma$ has poles at such points. Here's some zoomed in images of those places:

To make these images just change XMIN, XMAX, et al to desired values:
<code>#!/usr/bin/python
import numpy as np
import matplotlib.pyplot as plt
from mpmath import *

cplot(lambda x: (gamma(x)+1)/x,[XMIN,XMAX],[YMIN,YMAX],points=50000,verbose=True)
plt.savefig('FILENAME.png')
</code>
Comment: Okay, that makes sense, logically, and with @mercio's reasoning makes a good case for the existence of such points. The next question, naturally, is what the pattern for the real outputs is, and if there is a regularity to it that which can be modeled algebraically. (Beyond just the negative integers, there also appear to be reddish areas for Re(z)>0, the "fingerlike" structures in your coloring chart).
Answer: $$\forall\,n\in\Bbb N\;,\;\;\Gamma(n)=(n-1)!\implies f(n)=\frac{(n-1)!+1}n\in\Bbb Q\subset\Bbb R$$
Comment: Right. I will amend my question. My original intention was that $z=a+bi$ with $b≠0$.
Comment: Well, then that seems to be a very tough problem, since $\;\frac{a+bi}{c+di}\in\Bbb R\iff ad-bc=0\;$ .


What is Stdev of WRK test, which is better?

Question: I ran a wrk test and result came as follows
<code>root@wrk:~# wrk -c100 -t12 -d30s http://104.x.x.190
Running 30s test @ http://104.x.x.190
  12 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    49.14ms  111.33ms   1.09s    97.09%
    Req/Sec   250.34     31.06   313.00     89.19%
  55509 requests in 30.06s, 25.05MB read
  Non-2xx or 3xx responses: 55509
Requests/sec:   1846.52
Transfer/sec:    853.23KB
</code>
What is Stdev here? Is higher better?
Answer: Stddev is Standard Deviation - a measure of how much the members of a set deviate from the mean value of the group. For latency I would say smaller is better as it means that $thing is taking the same time each time it is measured.


Recommended JS library for origami-like paper folding animation

Question: I would like to create an origami-like paper folding animation using WebGL or Canvas (no Flash!).
The effect I would like to reproduce is similar to the one in the video here.
A clear view of the final animation could be represented as follows for a cube:

I was trying to use three.js library, but I couldn't find a way to animate a single face of a THREE.Mesh. I also tried simple CSS3 animation, but it would make very difficult to animate solid with more than 6 faces - as it is not possibile to create relationships between 2 or more faces.
Anyone can recommend other JS libraries? Or is there a way to achieve this with three.js?
Of course, it would be great if there could be a way to make it work just using canvas2d - but I think is pretty unlikely!
Comment: Just a thought -- So it sounds like you're creating a cube and want to animate the faces. What if you create 6 rectangular prisms (just 6 cubes with 0 or near 0 thickness) and animate each face as a separate object? Perhaps then you can abstract the process to work for 3-d shapes with N faces?
Answer: I would recommend http://oridomi.com/ as an inspiration. It offers basic folding animations.
Answer: I'm not sure which framework is best, but I think it's best to use a framework that supports skinned meshes and animation playback. A quick search gave...
http://www.oak3d.com/
...but I have no idea if it's the way to go. Three have (or at least had) support for skinning but to get the data out of a 3D-program wasn't trivial and animation playback was/is limited.
Comment: And now it's a Japanese cemetery website
Comment: yes it could work...as soon as I can make a working demo I will post it here...still it would be better to implement the animation native in JS without using a 3D program first...
Comment: You're most probably able to grab the bones of a skinned mesh and do the animation in JS.
Comment: And now it's a Chinese Rubber Exchange Market
Comment: And now it's a swiss visualization company
Answer: if you use Maya as 3D-program then try www.inka3d.com. then you can animate it in maya simply by parenting the top face to the front face and all side faces to the floor (each being a plane object), and crating some keyframes. then add a camera, do "export all..." and you're done


IE SCRIPT5: Access is denied. being thrown by same-domain ajax request with jQuery

Question: When using jQuery $.post to submit a form, I'm getting the SCRIPT5: Access is denied. error in IE. Everything I have seen regarding this error says it is caused by cross-domain requests, but my request is not cross-domain. What else could be causing this? It works perfectly in all other browsers.
Comment: Are you 1000% sure your request is not cross-domain? Switching protocols (`http://` to `https://`) is regarded cross-domain. Using different subdomains (`www.domain.com` vs `domain.com`) is regarded cross-domain. Using different ports is regarded cross-domain.
Comment: @Pekka They're both https to the same domain (no subdomains). I even get the error with a relative URL.
Answer: I has the same problem, using jQuery 1.8.0.
After upgrading to version 1.8.3 the problem was solved.


Linux Vlans over Bridge

Question: I am trying to bridge a dot1q trunk and cannot seem to figure it out.   I am able to connect to hosts on the trunk with my eth0.2 interface but when I bridge the interface with br0 and try to connect I get nothing.  Am I missing something simple here?
auto lo
iface lo inet loopback

auto br0
iface br0 inet manual
bridge_ports eth0
bridge_stp off
bridge_fd 9
bridge_hello 2
bridge_maxwait 0

auto br0.100
iface br0.100 inet static
address 192.168.100.99
netmask 255.255.255.0

auto eth0.2
iface eth0.2 inet static
 address 10.1.2.225
 netmask 255.255.255.0
 network 10.1.2.1
 broadcast 10.2.1.255
 gateway 10.1.2.1
 mtu 1500

Comment: What operating system are you using?
Comment: is the only reason for br0 to send a trunked vlan out eth0.2?
Comment: No. That is there  to manage the machine until I get it figured out.
Comment: @imaiden you have several very good answers below.  However, each one of them is asking "why bridge"?  Please take the time to explain why you want to enable bridging on your interface(s) for sake of clarity.
Comment: Since the time this question was asked, Linux bridge got VLAN filtering support: it can handle and dispatch VLANs to bridge ports according to the configuration (using the bridge command, not the obsolete brctl command), without ever requiring a vlan sub interface.
Answer: If an interface (eth0 in your case) is added to a bridge, by default its VLAN subinterfaces (eth0.2) will no longer get the incoming traffic — all packets will be passed to the bridge. Before Linux 2.6.37 VLAN subinterfaces could sometimes work depending on your hardware (if the hardware and driver supported RX VLAN acceleration (NETIF_F_HW_VLAN_RX), VLANs were handled before bridging, and VLAN subinterfaces worked); since 2.6.37 the behavior is the same for all cards and drivers.
There are several solutions with different drawbacks:

Add VLAN subinterfaces to the bridge instead of the physical interface. But in this case all ports of the bridge will have access to all VLANs, which is probably not desired.
Use ebtables to pass 802.1Q tagged traffic to VLAN subinterfaces:
ebtables -t broute -A BROUTING -i eth0 -p 802_1Q -j DROP

(In the BROUTING chain ACCEPT means "bridge", and DROP means "route", or actually "process according to ethertype", which for the 802_1Q type means "pass to the appropriate VLAN subinterface".)
In this case the bridge will not get any tagged traffic, but there will be slightly more overhead due to ebtables processing.
Reconfigure the network to make all traffic on the interface tagged and avoid the need to bridge the untagged traffic at all.
Comment: Isn't this exactly what my config is doing?  "Add VLAN subinterfaces to the bridge instead of the physical interface. But in this case all ports of the bridge will have access to all VLANs, which is probably not desired." This is what I am trying to accomplish at this point and I cannot figure out what it is I am doing wrong.
Comment: What kernel version are you using? Bridging tagged packets works only since 2.6.37, or if you have a network card which does not have hardware support for 802.1Q. And now I don't understand why you need this bridge at all — what other interfaces will be added to the bridge?
Answer: Once you add an interface to a bridge, you should use the bridge interface and sub-interfaces for getting untagged and VLAN tagged packets.
So, in your example, you need to replace eth0.2 with br0.2.
You would have only one bridge (br0), but using the bridge sub-interfaces (e.g. br0.2), you can get traffic from any VLAN you like.
To pass all information from eth0 to br0, just add eth0 to br0 and call it a day.  It appears you've already done this.
You may also want to toggle the following:
sudo sysctl net.bridge.bridge-nf-filter-vlan-tagged=1

This is 1 on my Jaunty box, but 0 on Lucid.  I had to make it 1 for my bridge / VLAN setup to work again.
Comment: I tried the above mentioned configuration dint work on Ubuntu. is there any different concept for ubuntu.
Answer: There are few things being mixed together here.  Tagging generally takes place on the actual ethernet interface (i.e. eth0.2) while bridging doesn't usually require any kind of explicit tagging (although there are exceptions to this).
OK - I am going to assume that you want VLAN 2 and VLAN 100 to pass over ethernet 0.
1.) You want to create eth0.2 and eth0.100.  Don't put an IP address on either (inet manual).
2.) Create br2 and br100 (for convenience) and assign the IP's you'd like to use in these VLAN's (inet static).
3.) eth0.2 will be a bridge_port in br2.  eth0.100 will be a bridge_port in br100.
Comment: What is the purpose of the bridges? What are you trying to bridge? You say you're trying to bridge a .1q trunk, but I don't see you bridging it to anything. If you're trying to bridge, you need bridges. But it sounds like you just want a few interface in different VLANs. You don't need any bridging for that.
Comment: Thanks for the help but I am trying to avoid setting up individual bridges for each vlan. I am trying to pass all the information on my eth0 interface to my br0.  Right now it strips all the 8021.q information.
Comment: If you're just trying to put your host into a few VLAN's on a single physical interface then there's no need for bridging.  If you want to be able to bridge traffic from one interface to another then you'll need bridge interfaces.  The host needs to be made aware of the various VLAN tags in use regardless, however.
Answer: to make a long story short: tag your interfaces, and then add bridges. So, for vlan100 to be usable in a bridged mode, you will need

eth0 -> eth0.100 ->br100

To add another tag:

eth0 -> eth0.100 -> br100
  ........->eth0.101 -> br101

and so on
Comment: @DavidSchwartz: This is useful when you have multiple trunked ports, where you want all VLANs to go over the physical interfaces without consideration for VLAN micromanagement. Far simpler to put the VLANs on one bridge than onto multiple disparate bridges.
Comment: @imaiden: I don't get it. Pass over the bridge to what? Are you trying to bridge the two VLANs together? If so, that's kind of silly (just use one VLAN), but then add both interfaces to a single bridge.
Comment: @zaTricky Oh, thanks. I didn't quite get that the VLANs would be tagged on the bridge.
Comment: I am trying to avoid using multiply bridges and need to find a way to have all the 802.1q traffic passed over the bridge.

Linux Vlans over Bridge


Linux showing wrong disk space used, du -h -x / | sort -hr has different space

Question: If I type:
df -h

It shows me 12G used.
But If I use this command:
du -h -x / | sort -hr >> /home/log_size.txt

This will give me:

If I sum /usr + /var + /root, this won't give me about 12G used... So where can I find the other files that are used in the 12G?
Answer: I found the solution myself.
Firstly type this command:
lsof -n | grep deleted

Are you getting any output? If you are, then find what program uses those open files and restart the related services.
In fact find processes that have used "deleted files", then restart all processes, in my case it was nginx.


Vector addition magnitude

Question: Problem
Carrie tells you she has two vectors $\vec a, \vec b$ such that $$|\vec a| = 7, \\ |\vec b| = 2,\\ |\vec a - \vec b| = 4.$$
Why do you not believe her?
My thoughts
I went with the triangle inequality, even though it is defined for addition.
$|\vec a - \vec b| = \overbrace{|\vec a + -\vec b| \leq |\vec a| + |-\vec b|}^{\text{triangle inequality}} = |\vec a| + |\vec b| = 9$
Now, since $4\leq9$, I don't see the problem. Seems like Carrie's statements may well be true.
Question
Have I made some mistake in my calculation?
Any help appreciated!
Comment: $|a - b| \ge |a| - |b|$
Comment: @OpenBall - Interesting! Then my little calculation must contain a mistake somewhere, right?
Comment: Your conclusion seems right, but the thing that tell us she's wrong is $|a-b|+|b|\not\gt|a|$.
Comment: @Alec No your work is correct. It's just that you have used the triangle inequality, while that comment is about what is called the [reverse triangle inequality](https://en.wikipedia.org/wiki/Triangle_inequality#Reverse_triangle_inequality).
Comment: @Alec The condition you verified is necessary, but not sufficient, so just because it's satisfied it doesn't imply that the triangle is possible. You need to verify the other necessary condition as well $|a-b| \ge \big||a|-|b|\big|$ which, in this case, fails.
Comment: @dxiv - Ah. Then my problem is reduced to proving the reverse triangle inequality for vectors. So far I've only seen it for real numbers.
Answer: Let's begin by stating the other side of the triangle inequality wich is:
$$|\ |\vec{a}|\ -|\vec{b}|\ |\leq|\vec{a}-\vec{b}| $$
Thus, $$|7-2|\leq 4 $$ wich is absurd!
In case you look for the demonstration of this inequality for any normed vector space you can take a look at this link Reverse triangle inequality (the demonstration is very simple)

Vector addition magnitude


Por que chamar o System.gc() não garante execução do garbage collector?

Question: Por que o desenvolvedor não tem total controle sobre o garbage collector?
Entendo que o papel do GC é gerenciar automaticamente a memória. Mas por que mesmo usando algum método como o System.gc() não há garantia de que o GC será executado?
Comment: Arrisco dizer que boa parte do motivo da linguagem não obrigar a executar é porque senão os programadores novatos querendo resolver _memory leaks_ iriam ficar disparando a torto e a direito no código uma operação potencialmente custosa (e, conforme o caso, bloqueante) que é a coleta de lixo, e poderiam acabar sobrecarregando suas aplicações.
Answer: É possível ter controle sobre o coletor de lixo, isso apenas não ocorre com o Java na sua implementação padrão, até onde eu sei, também por força de especificação. Vou responder baseado no contexto da pergunta.
A especificação da linguagem não dá detalhes sobre o funcionamento do GC, não exige que ele funcione ou deixe de funcionar em determinado momento, que ele seja implementado com uma técnica específica, que seja concorrente ou não, síncrono ou não, não especifica como deve ser seu tempo de resposta, tão pouco quando ele deve ocorrer.
O GC atual na implementação mais conhecida do Java funciona da forma mostrada na documentação do GC. Isso pode ser mudado desde que não fira a especificação da linguagem. E o GC é uma das coisas que mais muda em Java. Os maldosos dizem que ela precisa ter uma GC cada vez melhor porque ela gera muito lixo (e é verdade). Quando ler isso o GC pode ser diferente e isso pode valer mais ou menos.
Gerações
O principal motivo para que o GC não garanta nada é que ele pode piorar uma situação. Na implementação atual há um sistema de gerações. Quando você chama o GC forçando uma coleta, pensa que vai diminuir possíveis latências no meio de um processamento. E pode estar fazer justamente o contrário, o sistema de gerações é bem complexo e foi criado justamente para diminuir as latências quando ele é invocado.
Se o usuário dele, o programador, força uma coleta, ele está apenas jogando dados "vivos" de uma geração para a outra e atualmente só existem 3 delas. Quando o objeto cai na última geração, a vantagem da latência baixa se perde. Coletar na última geração é algo que o GC deve evitar. Para isto o melhor a fazer é evitar que o dado chegue lá, ou que só ocorra quando realmente é necessário, quando o dado tem um tempo de vida realmente longo.
Chamar o GC antecipa sua chamada e pode jogar um objeto para a última geração sem necessidade, e aí coletas passarão custar mais caro com mais frequência.
Eu poderia entrar em mais detalhes, mas não é algo tão importante. O GC foi feito para que você não se preocupe como ele funciona internamente.
Diversas implementações
O fato de não ser garantido não significa que nada será feito, caso contrário não teria sentido haver uma chamada explícita para ele.
Note que existem GCs para o Java mais simples que isto. Eles podem executar sempre e podem ser efetivos, mas não conte com isto.
O problema é justamente no comportamento não padrão. Você não pode especificar um comportamento padrão para necessidades diferentes, sob pena de inviabilizar certas implementações. E você não pode especificar algo que vai funcionar às vezes. A especificação toma o caminho seguro de dizer que garante nada, assim ninguém programa pensando que pode se beneficiar de algum comportamento do GC.
Você pode até mesmo ter configurações que mudam o comportamento do GC.
Por isso é perigoso programar na base do "funcionou na minha máquina" ou o "eu testei e deu certo". Tem que programar baseado na especificação.
É um erro fazer isto, mas se tiver conhecimento que uma implementação de GC que você vai usar pode beneficiar seu código em alguma situação, a tal ponto que justifique ignorar isso, então pode usar. Aceite o risco e controle a aplicação para que não use outro tipo de GC. Em 99,999% dos casos, ou um pouco mais, você não deve fazer isso.
Obtendo controle total da memória
Se precisa controlar a memória mais do que isto, não use Java. Cada linguagem tem sua filosofia, seus pontos fortes e fracos. Java nunca se preocupou com o uso parcimonioso da memória, seu forte está em outro ponto, que é não ter que se preocupar com o gerenciamento de memória.
Coloquei no GitHub para referência futura.
Answer: Porque é assim que a linguagem foi projetada. Isso pode ser visto na documentação oficial:
https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#gc%28%29
Agora é claro que isso levanta a pergunta: por que a linguagem foi projetada assim?
Isso tem a ver a tanto com a filosofia da linguagem (não interessa ao programador Java o gerenciamento explícito de memória) quanto com razões práticas: catar o lixo é um processo caro. Veja isso:

When control returns from the method call, the Java Virtual Machine
  has made a best effort to reclaim space from all discarded objects.

Ou seja, quando o controle retorna ao código que chamou o método, a JVM fez tudo o que podia para catar o lixo que havia. Isso significa que a chamada é síncrona. Processo caro + chamada síncrona = sua aplicação esperar muito tempo para realmente continuar a rodar.
Isso pode ser problemático, então, em diferentes cenários, a JVM pode decidir que não fazer a coleta completa do lixo é a melhor escolha. A JVM também pode ser manualmente configurada para ignorar o System.gc().
É claro que existem situações nas quais pode ser uma boa ideia chamar o GC. Por exemplo, durante um jogo, pode ser que você queira chamar o GC durante a tela de carregamento, em vez de esperar ele rodar e pausar todo o sistema quando o usuário está realmente jogando. Por isso a chamada continua existindo. Apenas não confie a ela a corretude da sua aplicação.
Answer: TL;DR
Porque Garbage Collector (GC) é mais um conceito do que exatamente um algoritmo ou conjunto de classes ou API.
Toda garantia limita a forma como ele pode ser implementado.
Vamos por partes...

Por que chamar o System.gc não garante execução do garbage collector?

Existem muitas formas de implementar um GC: concorrente e paralelo, contínuo, etc. Em muitos casos não faz sentido algum chamar essa rotina explicitamente.
Se a especificação garantisse a execução na chamada, ela estaria limitando a forma como o GC pode ser implementado. E é exatamente isso que eles querem evitar.
Implementações mais simples e síncronas do GC executam quando se chama o System.gc(), mas note que este é um comportamento da implementação e não da especificação.

Por que o desenvolvedor não tem total controle sobre o garbage collector?

Você não pode ter total controle sobre o funcionamento interno de algo que funciona como uma caixa preta.
Na verdade, você pode sim ter o controle sobre certos aspectos do GC quando você sabe com antecedência qual é a implementação de uma certa JVM que está executando seu sistema. Existem vários artigos na internet que vão lhe ensinar a lidar com as configurações do GC de cada JVM.

Entendo que o papel do GC é gerenciar automaticamente a memória mas por que mesmo usando algum método como o System.gc não há garantia de que o GC será executado?

"Automaticamente" é a palavra chave. Não é feito para ser manualmente, pelos motivos já citados acima.
Uma analogia
Uma analogia talvez ilustre bem a situação. Imagine se a pergunta fosse assim:

Por que Set não garante a ordem dos elementos do conjunto?

Porque segundo o conceito de conjuntos não existe ordem, mas existem implementações da interface Set que mantém a ordem, as quais você pode usar quando tiver a necessidade.


Difference between Sensitivity analysis and Design of Experiments

Question: Reading on wikipedia about the methods for sensitivity analysis: different methods are stated.
At the end of the wikipedia page, a section called Related Concepts speaks about Design of experiments (DOE) as a related subject to sensitivity analysis.
Before I supposed that DOE is a method for doing a sensitivity analysis, but now I get lost. Even though they stated in the wikipedia page that both sensitivity analysis and DOE are used to detect the effect and influence of the parameters of a model.
Can someone help me to know the difference between these two concepts?
Answer: Design of experiment (DOE) is composed of a set of methods which determine how to best choose points in a space.
You can want to choose these points for sensitivity analysis purposes but also for many other purposes such as supervised regression, classification.
For example, factorial designs are well suited for linear regression.
Answer: sensitivity analysis explore the effect of small variation of the controlled variables around a set point/ polarization point, while DOE is exploring the full domain


C# Distance converter

Question: I'm working on a C# Forms app for a distance converter and this is the code I have right now,I need to declare toDistance but i'm not too sure how to declare it with the results of the distance conversion. Please help if you can, I'm pretty new at this
private void btnConvert_Click(object sender, EventArgs e)
{
    float fromDistance;
    float toDistance;

    fromDistance = int.Parse(distanceinput.Text);
    string measureInput = fromList.Items[fromList.SelectedIndex].ToString();
    string measureOutput = toList.Items[toList.SelectedIndex].ToString();
    distanceOutput.Text = toDistance.ToString();

    switch (measureInput)
    {
        case "Yard":
            switch (measureOutput)
            {
                case "Yard":
                    toDistance = fromDistance;
                    break;
                case "Foot":
                    toDistance = fromDistance * 3;
                    break;
                case "Inches":
                    toDistance = fromDistance * 3 * 12;
                    break;
            }
            break;
        case "Foot":
            switch (measureOutput)
            {
                case "Foot":
                    toDistance = fromDistance;
                    break;
                case "Yard":
                    toDistance = fromDistance / 3;
                    break;
                case "Inch":
                    toDistance = fromDistance * 12;
                    break;
            }
            break;
        case "Inch":
            switch (measureOutput)
            {
                case "Inch":
                    toDistance = fromDistance;
                    break;
                case "Foot":
                    toDistance = fromDistance / 12;
                    break;
                case "Yards":
                    toDistance = fromDistance / (3 * 12);
                    break;
            }
            break;
    }
}

Comment: I may have misunderstood what you're trying to do, but don't you want the line distanceOutput.Text = toDistance.ToString(); to be after your switch statement ?
Comment: First time I see nested switch!! Kind of eye hurt
Comment: How does the rest of your form look? Why do you have all that in the event function instead of moving it into separate functions and calling those functions on the click event?
Comment: Add a control to your form and call it `output` or `results` or `toDistTextBox`. Then after you set the value of `toDistance` then set the `Text` property of your `output` textbox.
Answer: Did you try move distanceOutput.Text = toDistance.ToString(); to the end of function?
 private void btnConvert_Click(object sender, EventArgs e)
        {
            float fromDistance;
            float toDistance;

            fromDistance = int.Parse(distanceinput.Text);
            string measureInput = fromList.Items[fromList.SelectedIndex].ToString();
            string measureOutput = toList.Items[toList.SelectedIndex].ToString();

            switch (measureInput)
            {
                case "Yard":
                    switch (measureOutput)
                    {
                        case "Yard":
                            toDistance = fromDistance;
                            break;
                        case "Foot":
                            toDistance = fromDistance * 3;
                            break;
                        case "Inches":
                            toDistance = fromDistance * 3 * 12;
                            break;
                    }
                    break;
                case "Foot":
                    switch (measureOutput)
                    {
                        case "Foot":
                            toDistance = fromDistance;
                            break;
                        case "Yard":
                            toDistance = fromDistance / 3;
                            break;
                        case "Inch":
                            toDistance = fromDistance * 12;
                            break;
                    }
                    break;
                case "Inch":
                    switch (measureOutput)
                    {
                        case "Inch":
                            toDistance = fromDistance;
                            break;
                        case "Foot":
                            toDistance = fromDistance / 12;
                            break;
                        case "Yards":
                            toDistance = fromDistance / (3 * 12);
                            break;
                    }
                    break;
            }
    distanceOutput.Text = toDistance.ToString();
        }

Comment: I did, there was still an issue with toDistance being recognized
Answer: This line:
distanceOutput.Text = toDistance.ToString();

does not mean: "the Text of control distanceOutput should always follow whatever is the "ToString" of toDistance".
Rather it means "do that right now" (as in: the moment that line is executed). It doesn't keep a relation.
So the solution is to move that line after the (outer) switch statement where you calculate that toDistance.
However, you probably need to initialize it (float toDistance = 0f;) else the compiler complains that you are trying to use an uninitialized variable. It cannot see that you have used all possible values in your switches.
Answer: You need to move your final assignment statement to after your switch.
Also, I would not use a nested switch. It's difficult to read and debug. I would convert the input to the smallest possible unit (in your case, inches). Then, I'd convert the smallest unit measurement to whatever output unit the user requested:
float inputInches = 0;

//Convert input to inches
switch(measureInput)
{
    case "Yard":
        inputInches = fromDistance * 3 * 12;
        break;
    case "Foot":
        inputInches = fromDistance * 12;
        break;
    default:
        inputInches = fromDistance;
        break;
}

//Convert output to desired format
switch(measureOutput)
{
    case "Yard":
        toDistance = inputInches / 3 / 12;
        break;
    case "Foot":
        toDistance = inputInches / 12;
        break;
    default:
        toDistance = inputInches;
        break;
}

distanceOutput.Text = toDistance.ToString();

A few additional things to consider:

Text comparisons are messy. Consider creating an enum with the input types (Inch, Foot, Yard, etc).
Coding in the Button event is also messy. Consider moving this conversion code to its own method.

C# Distance converter


Why don't all sprinters shave their heads clean?

Question: Hair may increase the air resistance and weight and hinder running; given this, why do some sprinters keep their hair?
Comment: Could you provide some evidence that hair *significantly* increases air resistance?
Answer: I'll assume you that you have competitive swimming in mind when thought of this.  The main difference between swimming and sprinting is that a swimmer's body is mostly horizontal throughout the race while a sprinter is running upright.  This makes a shaved head or a cap on a swimmer more valuable because they are leading with their head, cutting through the water resistance with it (well, their hands do a lot of the lead work but the head is important).
Also, think about how when you are swimming, you can feel the water flow down your entire body from head to toe.  In comparison, when you are running, the entire front of your body cuts into the air resistance, but only "flows" the few inches that are the width of your sides.  So basically, someone shaving their head or body for a sprint wouldn't hurt...but it would only help a very miniscule amount, not enough to warrant shaving your head (unless you need an excuse to try it out and see what it looks like).


Time Zone causing UILocalNotification to be set for incorrect time

Question: I know this is similar to some other questions, but I cannot seem to get an answer and apply it to my situation and get it to work. I am using an NSDateFormatter to try to schedule an alert for 8:00 AM in the morning, no matter the time zone. Here is my code:
[self scheduleNotificationAtTime:@"08:00 AM"];

and then my method
-(void)scheduleNotificationAtTime:(NSString *)time {

NSDateFormatter *format = [[NSDateFormatter alloc] init];
format.dateFormat = @"HH:mm a MM/dd/yy";
NSString *dateString = [NSString stringWithFormat:@"%@ %@",time,self.array[2]];
//self.array[2] = is today's date, so today it is 6/13/14
NSDate *date = [format dateFromString:dateString];
UILocalNotification *lnf = [[UILocalNotification alloc] init];
NSLog(@"Time zone %@",[NSTimeZone systemTimeZone]);
lnf.fireDate = date;
lnf.alertBody = [NSString stringWithFormat:@"%@ is today",self.navigationItem.title];
lnf.timeZone = [NSTimeZone localTimeZone];

[[UIApplication sharedApplication] scheduleLocalNotification:lnf];
NSLog(@"%@",lnf);

}
and the log statement at the end is reading
{fire date = Friday, June 13, 2014 at 12:00:00 AM Eastern Daylight Time,
time zone = America/New_York (EDT) offset -14400 (Daylight), repeat interval = 0,
repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = (null), user info = (null)}

so it is 8 hours off! its 12:00 AM instead of 8:00 AM
Answer: Try doing
format.dateFormat = @"HH:mm a MM/dd/yy zzz";
NSString *dateString = [NSString stringWithFormat:@"%@ %@ EDT",time,self.array[2]];

then also
lnf.timeZone = [UITimeZone timeZoneWithName:@"EDT"];

this should keep the time zones in sync.
Answer: please try making this change :
lnf.timeZone = [NSTimeZone localTimeZone];
to
lnf.timeZone  = [NSTimeZone timeZoneWithName:@"UTC"];
Comment: this does not work. I get 4 AM. It's closer, but still not right... This also seems like it is fudging it, not the correct way to fix it, right? @user3739364
Comment: why the downvote? was just trying to let you know of different timeZone setting. I don't know what time zone you're in, so I suggested it.
Comment: I didn't downvote you. It was someone else. (You need 125 rep to downvote, you can see i don't have that). I'm in EST or EDT. Any other ideas?


Importing multiple product variations in one product display

Question: I have this huge problem I cant understand.
I import products via feeds....i have mapped excel cvs file....
I can import one product variation to one product display...
But I have 4 product variations and I dont know hot to setup my excel file
because product display and product variation match connect with eachother withunique identifier like sku
but I have here four different skus for 4 variations like for example
22SKU_red
22SKU_orange
22SKU_blue
22SKU_black
Any idea how to set it up to import with excel?
Answer: I haven't tested this in the context of importing product displays, but in theory you should be able to accomplish this by choosing a character to separate the SKU's, putting all SKU's in single column, and by using the Feeds Tamper plugin "Explode".
The explode tamper plugin cares that your input data is handled as multiple values.
Example XLS file:

Product display title | SKU
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Lorem Ipsum           | 22SKU_red|22SKU_orange|22SKU_blue|22SKU_black
Dolor Sit Amet        | 23SKU_red|23SKU_orange
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

Steps

Separate the SKU's in your Excel file with a certain character, for example a pipe character: "|".
Install the module Feeds Tamper. Also enable the Feeds Tamper Admin UI module (included with Feeds Tamper).
Go the Tamper page of your feeds importer (/admin/structure/feeds/[importer_id]/tamper).
Click "Add plugin" for the "Product: SKU (field_product:sku)" mapper.
For the plugin to add, select "Explode". As string separator, choose the character that you used to separate your SKU's. If you followed the example, then this would be the pipe character: "|". See also the image:


React Select does not show the value when selected

Question: i'm new to react-redux and i'm having two issues. I'm using eract select plus like this:
<Select
          id="portf"
          options={opts}
          onChange={value => portfolioSelector(value)}
          placeholder="Select Portfolio"
        />

But when i select another value this value even though is triggered it is not shown it the field. Another issue is that i want to set initial value to my selector so in my container i write:
const initialValues = fromJS({
  market: { label: 'All', value: 'All' },
  prodType: { label: 'All', value: 'All' }
});

When i execute my project i can see that in the state these values do exist but the don't shown  in my select field. For the second case i use react-select in redux form and i have implement it with the following way:
<Select
    {...props}
    value={props.input.value}
    onChange={value => props.input.onChange(value)}
    onBlur={() => props.input.onBlur(props.input.value)}
    options={props.options}
    placeholder={props.placeholder}
  />

Comment: How is your `onChange` action dispatched? How does your reducer look like?
Comment: case SET_PORTFOLIO_ID:
      return userSettings
        .set('currentPortfolioId', action.payload.currentPortfolioId); This is the case for my reducer. In the first select in the onchange i dispatch the action portfolioSelector
Comment: You'll have to show us the complete code stack. Reducer, action, dispatching that action, injecting data from the store in this "form" component, the component itself. The code you provided looks correct.
Comment: With alll respect i dont think it has something to do with reducer. I may forget to declare some function in my select component
Comment: Well then you debug it yourself. How can we help if the code you're showing us is irrelevant? I asked for more code because obviously the problem is not here.
Answer: I just dealt with this problem, and I found it helpful to somewhat abstract the Select into its own component.  To do this, you can make a component (ReactReduxSelect.jsx) that looks like this:
import React from 'react';
import Select from 'react-select';
import style from 'react-select/dist/react-select.css';

// define portfolioSelector somehow
// or you could pass it as a property:
//     portfolioSelector: React.PropTypes.func

class ReactReduxSelect extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
    }
    render() {
        return (
            <Select
                name={this.props.name}
                value={this.state.selected}
                options={this.props.options}
                onChange={(value) => {
                    this.setState({ selected: value });
                    portfolioSelector(value);
                }}
                placeholder={this.props.placeholder}
            />
        );
    }
}

ReactReduxSelect.propTypes = {
    name: React.PropTypes.string,
    placeholder: React.PropTypes.string,
    options: React.PropTypes.array
};

export default ReactReduxSelect;

The cool thing about implementing it this way is that it then can be updated within the native Redux state tree.  So if you go back to your page where you want to embed this control (MyTotallySickReactReduxWebpage.jsx or whatever), you can import the component ...
import ReactReduxSelect from './ReactReduxSelect';

And then embed it in your code ...
const ArtifactGenerator = ({
    // my totally awesome props
}) => (
    // some react redux stuff w/ divs and { and js and all that jazz
    <ReactReduxSelect
        name="portf"
        options={[
             { label: 'Market', value: 'All' },
             { prodType: { label: 'ProdType', value: 'All' }
        ]}
        placeholder="Select Portfolio"
     />
     // whatever other groovy code you want in there
);

// the rest of your props and export code or whatever for the page

I'm not totally sure what you were trying to do with your initialValues there, that syntax doesn't look right to me, so I just kind of wrote something I think is more likely to work, but you can fairly easily adjust this to fit your needs.  Hope this helps!


Does standard deviation apply to any distribution?

Question: What books have told me that 'standard deviation' has a special relationship with normal distribution i.e. 68–95–99.7% rule. What they didn't tell me is the answer to "can I use standard deviation to calculate spread of any distribution?"
In that case I should be taking standard deviation of binomial or poisson etc. distribution or not?
Comment: What problem would you "use" the standard deviation to solve? What are you trying to do, and how does a standard deviation fit into it?
Comment: To find the spread, variability etc. like you would do with normal distribution because 'mean' is not enough e.g. to compare two sets.
Answer: Sort of.
It is possible to have a distribution for which the variance is undefined. Then it doesn't make sense to take the square root to get the standard deviation.
When the variance is defined, then it makes perfect sense to calculate it. The normal distribution has that nice 68/95/99.7 property, which other distributions do not, so do not get misled into thinking that 68% of the density is within 1 standard deviation in general.
The Chebyshev inequality is valid whenever the variance is defined, however.
$$
P(\vert X-\mu\vert >k\sigma)\le \dfrac{1}{k^2}
$$
$X$ is the random variable.
$\mu$ is the mean.
$\sigma$ is the standard deviation.
$k$ is a positive number.
So when variance is defined, there is some notion of higher standard deviation corresponds to being more spread out from the mean.
Comment: What would you check?
Comment: There is nothing to check and even if there were you would still need to calculate the SD to verify that the inequality is satisfied.
Comment: Do I need to check with this 'Chebyshev inequality' before proceeding to calculate the standard deviation? Maybe if I can do it directly in Python would be great.
Comment: In other words, do I need to calculate this 'Chebyshev inequality' before calculating the standard deviation?
Comment: The Chebyshev inequality is a more general/less strict version of the 68/95/99.7 rule that you mention in your question: it tells you the probability that an observation is more than $k$ standard deviations from the mean.
Comment: @user963241 No. in fact, you have to calculate the standard deviation before you can do anything with that inequality.
Comment: Say, my data is `[4, 5, 1, 3, 1, 5, 1, 1, 5, 5, 5, 5, 2]` and `mean = 3.307` and `std_dev = 1.843`. Now what do I need to see in  Chebyshev inequality. Example would be great since I don't really understand inequality formula.
Comment: @user963241 You don't check anything. Chebyshev's inequality is a fact about distributions that [Chebyshev proved in 1867](https://en.wikipedia.org/wiki/Chebyshev%27s_inequality#History).


Given that one can sample $X \sim f(x)$, is there an easy way to sample $Y \sim k \cdot f(g(y))$ (such as $k \cdot f(e^y)$)?

Question: Say I'm able to sample an RV $X$ from a PDF $f(x)$, can I exploit this to efficiently  sample another RV $Y \sim k \cdot f(g(y))$ (where $k$ is a normalizing constant)?
I'm interested in something for a Gibbs sampler that would be better than using Metropolis, slice, inverse transform sampling, etc.
Comment: I don't think there should be a reasonable way to do this in general with a single draw from $f$. You either need some special conditions on $g(x)$ and $f(x)$ or be willing to settle for an approximation, considering that if you could get exact samples like this in general then you could devise samplers for getting a sample from any distribution by choosing $g$ and $f$ appropriately. I'm also not hopeful for your related problem since it would imply that we could simulate from $f(\theta | x)$ if $\theta$ is real provided $f(\theta)$ is easy to sample from and $f(x|\theta)$ is symmetric.
Comment: Could you post the 'related question' as a different question?  (and then put that link here)
Comment: Is $f \circ g$ similar to $f$?  If so, this is easy.  I guess not though.  Can you tell us anything more?
Comment: @AaronMcDaid: Good idea, [done](http://stats.stackexchange.com/questions/56086/most-efficient-way-of-sampling-a-product-of-distributions-k-cdot-fx-cdot-g).
Answer: If the inverse of $g(y)$, i.e. $g^{-1}(x)$, is relatively linear for the most probable values drawn from $f(x)$, then the following method should have a reasonable acceptance rate.  I'm assuming $g(y)$ is strictly monotonic - in order that it have an inverse.
This is Metropolis-Hastings.  We make a proposal, and then accept or reject appropriately.
Make a draw from your sampler, $x \sim f(x)$, and feed that into the inverse to get a proposal $y_{proposal} = g^{-1}(x)$.  The probability of making that proposal is proportional to
$$\propto \frac{f(x)}{ \left| \frac{d}{dx} g^{-1}(x) \right| } $$
That expression uses the derivative of the inverse to account for the fact that it will overrepresent areas where g^{-1} is relatively constant.
We must calculate the proposal probabilty for both the proposed value, $y_{proposal}$, and the current value, $y_{current}$.  We can also use the definitions $x_{proposal} = g(y_{proposal})$ and $x_{current} = g(y_{current})$.
$$ Acceptance~probability = \operatorname{min} \left(1, \frac{ f(g(y_{proposal})) }{ f(g(y_{current})) } \frac{ \frac{f(x_{current})}{ \left| \frac{d}{dx} g^{-1}(x_{current}) \right| } }{ \frac{f(x_{proposal})}{ \left| \frac{d}{dx} g^{-1}(x_{proposal}) \right| } } \right) $$
Don't worry about the absolute value $|\cdot|$ in that equation. $g(y)$ is either increasing everywhere or decreasing everywhere and therefore the absolute values will cancel out.
We can do a lot of cancelling here, in particular remember that $x = g(y)$.
$$ Acceptance~probability = \operatorname{min} \left(1, \frac{ f(x_{proposal}) }{ f(x_{current}) } \frac{ \frac{f(x_{current})}{ \left| \frac{d}{dx} g^{-1}(x_{current}) \right| } }{ \frac{f(x_{proposal})}{ \left| \frac{d}{dx} g^{-1}(x_{proposal}) \right| } } \right) $$
$$ Acceptance~probability = \operatorname{min} \left(1,  \frac{ {  \frac{d}{dx} g^{-1}(x_{proposal}) } }{ { \frac{d}{dx} g^{-1}(x_{current}) } } \right) $$
Finally, I think you can rearrange a little more, and make use of the fact that the derivative of the inverse is the reciprocal of the derivative of the original function:
$$ Acceptance~probability = \operatorname{min} \left(1,  \frac{ {  \frac{d}{dy} g(y_{current}) } }{ { \frac{d}{dy} g(y_{proposal}) } } \right) $$


How to calculate categorical distribution?

Question: Suppose I have 150 records with continuous and categorical values.In which only one column has categorical values with three categories namely setosa, versicolor and virginica.
How to calculate categorical distribution for them?
Comment: The allusion is to the _Iris_ data (e.g. http://stats.stackexchange.com/questions/74776/what-aspects-of-the-iris-data-set-make-it-so-successful-as-an-example-teaching) As far as I can see, the categorical distribution is that there are 50 values of each category, so frequencies are (50, 50, 50) and probabilities 1/3 each. Any decent program will have ways to give you a table and/or to save the frequencies in a vector or variable. Is that what you want? If you want something else, you may have to add more detail. Note that questions on how to do this in particular software are off-topic here.
Comment: What does in your instance `How to calculate categorical distribution for them?` actually mean?
Comment: Want to find distance between clusters handling categorical data,  while searching i found about categorical distribution..i thought this would help me..If there is any way please help me
Comment: I don't think this will help you.  As @NickCox pointed out, the Iris data is uniform across the three types of plants. But that won't help you find the distance between clusters because that information doesn't go into the cluster analysis
Answer: The term categorical distribution describes probabilities of observing $k$ exclusive events that for convenience are denoted as numbers $x \in \{1,...,k\}$. A probability mass function assigns probability to each of the events
$$ \Pr(x = i) = p_i $$
with a constraint that $\sum_{i=1}^k p_i = 1$. If you want to calculate the probabilities from data, then you are possibly interested in an empirical distribution. Calculating empirical probabilities is very simple. If the number of times that $x=i$ was observed in the dataset is denoted $n_i$, then
$$ \hat p_i = \frac{n_i}{\sum_{i=1}^k n_i} $$
Notice however that such an estimate would be obviously incorrect if you did not observe some value in your dataset, which is possible in general. In such a case the estimate of probability from your data would be zero (i.e. impossibility). This is called the zero-frequency problem and a number of work-arounds for it are possible. The simplest correction is to add some value $\alpha$ to your counts
$$ \hat p_i = \frac{n_i + \alpha}{(\sum_i n_i) + k\alpha} $$
The common choice for $\alpha$ is $1$, i.e. applying uniform prior based on Laplace's rule of succession, $1/2$ for Krichevsky-Trofimov estimate, or $1/k$ for Schurmann-Grassberger (1996) estimator. Notice, however, that what you do here is apply out-of-data (prior) information in your model, so it gets a subjective, Bayesian flavor. With this approach you have to remember the  assumptions you made and take them into consideration.
Such an approach is equivalent to Bayesian estimation using Dirichlet prior (as described in Wikipedia) with equal parameters $\alpha = (1,...,1)$. You can use a Bayesian approach even if there is no zero-frequency problem, but when you want to include some out-of-data information in your statistical model. In this case the maximum a posteriori estimate for $p_i$ is
$$ E(p_i) = \frac{n_i + \alpha_i }{\sum_i n_i + \alpha_i} $$
where the $\alpha_i$ can be interpreted as assumed a priori "pseudocounts" for each event. In this case, the probabilities $p_i$ follow a Dirichlet distribution
$$ p_i \sim \mathrm{Dir}(n_1+\alpha_1,...,n_k+\alpha_k) $$
Of course, if your out-of-data knowledge suggests using some informative, non-uniform, prior you can use different values for the $\alpha_i$.

Schurmann, T., and P. Grassberger. (1996). Entropy estimation of symbol sequences. Chaos, 6, 41-427.


No control panel equivalent of exim /etc/mailips file for configuring IPs for each domain's outgoing mail?

Question: I have a problem with outgoing SMTP mail being sent with the wrong IP address.
I use exim for outgoing mail. I found a guide "How to manually configure Exim's outgoing IP addresses", which suggests modifying /etc/mailips. This file looks like exactly what I'm looking for.
Unfortunately the file doesn't exist on my server. On closer examination, I believe that file is not part of normal exim configuration but is created by a certain proprietary control panel package to ease configuring exim. I can't find any direct equivalent in exim.
How can I configure the IP address for outgoing mail for each domain in exim?
Answer: It appears that file is indeed something created by a certain proprietary control panel package.
The good news is, it's easy to roll your own. Exim config can fix an IP address with the interface property. In theory, it's one IP per server, but a little code can make it dynamic.
This is adapted from a loginroot article:

Find your exim config file, exim.conf. They suggest /etc/exim.conf, mine was in /etc/exim/exim.conf
Create a file to store domain - IP associations. I went with /etc/exim/domainips, they favoured /etc/virtual/domainips
Fill it with domains and IPs like this:

some-domain.com: 22.214.171.124
anotherdomain.org: 184.108.40.206

In the exim.conf file, find the section remote_smtp:
If there's an interface = some.ip.add.ress line below remote_smtp:, remove it.
Add a line using the file name from before:

  interface = "${lookup{$sender_address_domain}lsearch{/etc/exim/domainips}{$value}}

Restart exim. service exim restart worked for me (Centos), or an alternative is /etc/init.d/exim restart

This then grabs the IP from the file for each email as it's sent, based on the sender domain.

Note: as well as working in control-panel-free systems, this also appears to work with Vesta CP


COM error while reconnecting to UIA app using Pywinauto through RPyC

Question: I have connected to a windows app using pywinauto like below,
import subprocess
sp = subprocess.call("start shell:AppsFolder\myapp!App", shell=True)

from pywinauto import application
app = application.Application(backend="uia")
my_app = app.connect(title="myapp", class_name="ApplicationFrameWindow")

but this is through Python's RPyC connection.
For the first time, this code works fine but if I run my script again using same RPyC connection, I see the following error:
File "C:\Python27\lib\site-packages\pywinauto\application.py", line 944, in connect
self.process = findwindows.find_element(**kwargs).process_id
File "C:\Python27\lib\site-packages\pywinauto\findwindows.py", line 84, in find_element
elements = find_elements(**kwargs)
File "C:\Python27\lib\site-packages\pywinauto\findwindows.py", line 197, in find_elements
cache_enable=True)
File "C:\Python27\lib\site-packages\pywinauto\uia_element_info.py", line 272, in children
return self._get_elements(IUIA().tree_scope["children"], cond, cache_enable)
File "C:\Python27\lib\site-packages\pywinauto\uia_element_info.py", line 261, in _get_elements
ptrs_array = self._element.FindAll(tree_scope, cond)
COMError: (-2147024809, 'The parameter is incorrect.', (None, None, None, 0, None))

If I close existing RPyC connection and open another session then the above code works fine. I could not able to figure out why I see this error. Any ideas?
Comment: It looks like a known bug. Can you try the latest master branch?
Comment: @VasilyRyabov, I tried [pywinauto-0.6.3](https://github.com/pywinauto/pywinauto/releases/download/0.6.3/pywinauto-0.6.3.zip). I still see the same issue
Comment: 0.6.3 is not the same as latest master branch.
Comment: @VasilyRyabov, Awesome, it's working with master branch. Thanks. You can add it as an answer, I will upvote.
Answer: It's a known issue already fixed in master branch. Will be released soon as pywinauto==0.6.4.


Performance impact of new calculated column with Python (Pandas)

Question: I'm playing around with Python, numpy and more with the intention to get into tensorflow and machine learning and really understand everything, not just the "how to run" parts.
In many cases, I need to pre-process the data for visualisation with the matplotlib and I am not sure if there is a more performant way or even "on-the-fly" processing to efficiently get the same result as the code below returns (df is a pandas dataframe):
def calculate(s):
cl = 100 if s["income-class"] == "<=50K" else 300
return cl

df["incomeClassNum"] = df.apply(lambda row: calculate(row), axis=1)

plt.scatter(df[["age"]], df[["education-num"]], s=df["incomeClassNum"])
plt.show()

Thanks for any advice and feedback,
Martin
Answer: Use vectorized numpy.where:
df["incomeClassNum"] = np.where(df["income-class"] == "<=50K", 100, 300)

plt.scatter(df["age"], df["education-num"], s=df["incomeClassNum"])

Also it seems new column is not necessary:
incomeClassNum = np.where(df["income-class"] == "<=50K", 100, 300)

plt.scatter(df["age"], df["education-num"], s=incomeClassNum )