Validating against duplicate user entries when using sets

Question: I am currently studying Java and have being using normal arrays so far. Next semester we will be using data structures like ArrayList etc, but i decided to read ahead. I have read that for storing data that can not be a duplicate, Sets were the data structure of choice, but in the code below the user can still enter a duplicate entry? Can any body explain the process to me and perhaps a solution to my problem?
public class Lotto {

private static final int INPUT_SIZE = 6;

private static final int MIN_NUMBER_POSSIBLE = 0;

private static final int MAX_NUMBER_POSSIBLE = 25;

private Set<Integer> userNumbers = new HashSet<Integer>();

private Set<Integer> randomNumbers = new HashSet<Integer>();

public static void main(String[] args) {
    Lotto c = new Lotto();
    c.generateRandomNumbers();
    System.out.println("Pick " + INPUT_SIZE + " numbers from "
            + MIN_NUMBER_POSSIBLE + " to " + MAX_NUMBER_POSSIBLE + ".");
    c.readUserNumbers();
    if (c.doUserNumbersMatchRandomNumbers()) {
        System.out.println("You win :) !");
    } else {
        System.out.println("Sorry you failed :( !");
        c.showRandomNumbersToUser();
    }
}

private void generateRandomNumbers() {
    Random random = new Random();
    for (int i = 0; i < INPUT_SIZE; i++) {
        randomNumbers.add(random.nextInt(MAX_NUMBER_POSSIBLE));
    }
}

private void showRandomNumbersToUser() {
    System.out.println("\nRandom numbers where : ");
    for (Integer randomNumber : randomNumbers) {
        System.out.println(randomNumber + "\t");
    }
}

private void readUserNumbers() {
    Scanner input = new Scanner(System.in);
    int inputSize = 1;
    while (input.hasNextInt() && inputSize < INPUT_SIZE) {
        int numberChoosen = input.nextInt();
        if (numberChoosen < MIN_NUMBER_POSSIBLE
                || numberChoosen > MAX_NUMBER_POSSIBLE) {
            System.out.println("Your number must be in "
                    + MIN_NUMBER_POSSIBLE + " - " + MAX_NUMBER_POSSIBLE
                    + " range.");
        } else {
            userNumbers.add(numberChoosen);
            inputSize++;
        }
    }
}

private boolean doUserNumbersMatchRandomNumbers() {
    for (Integer userNumber : userNumbers) {
        if (!randomNumbers.contains(userNumber)) {
            return false;
        }
        printMatchingNumber(userNumber);
    }
    return true;
}

private void printMatchingNumber(int num) {
    System.out.println("Your number, " + num + ", has been called.");
}

}
Comment: OK. So you haven't read the javadoc. Read it. That's the best way to know what a class/method does: http://docs.oracle.com/javase/7/docs/api/java/util/Set.html#add%28E%29. *If this set already contains the element, the call leaves the set unchanged and returns false.* See? No exception thrown.
Comment: What do you expect to happen, and what happens instead? Have you read the javadoc of Set?
Comment: I thought it would throw an exception if I attempted to store a duplicate number. I want to avoid the user entering storing duplicates in the HashSet.
Answer: Set#add(Object) returns true when the object was added successfully and false otherwise. It will not throw an exception, so you need to add a conditional to check whether the operation was successful:
if (userNumbers.add(numberChoosen)) {
    System.out.println("Number added successfully");
} else {
    System.out.println("Duplicate number detected");
}

Answer: Sets do not prohibit entering a unique value more than once. It is on you to check preconditions, see e.g Set.add.
So instead of just calling:
userNumbers.add(numberChoosen);

try
if (!userNumbers.contains(numberChoosen)) {
    userNumbers.add(numberChoosen);
} else {
    // do stuff...
}


PowerBI creating calculated measure for 1 product to be used with actual value of another product

Question: Problem: I have data from a pizza production plant containing product name, number of units produced and the time in hours. The product variable includes the final pizza and the raw material required for it. I am not able to calculate a weighted UPH measure, which would be dynamic based on the time frame selected and able to roll up the hierarchy explained below.
+-----------+----------------+----------------+
|   Pizza   | Units produced | Hours required |
+-----------+----------------+----------------+
| Pizza 1   | 23,156         | 12,154         |
| Pizza 2   | 25,145         | 21,154         |
| Pizza 3   | 2,055          | 2,015          |
| Pepperoni | 50,356         | 13,051         |
| Bacon     | 35,465         | 9,004          |
| Pineapple | 6,254          | 504            |
| Pizza 4   | 26,413         | 15,014         |
+-----------+----------------+----------------+

Explanation: I need to calculate the Units per hour (UPH) performance of each Pizza which is Units/Hours.
However, I want to factor in the time in took to produce the raw materials for the Pizza so a simple calculation using the above hours is not useful for me. To get the weighted hours required to create a pizza, I have to calculate the hours required per unit (Hours per unit) = hours/unit, for the raw material and multiply it by the # of units for the final product (1 unit of raw material is used in 1 final product)
+-----------+----------------+----------------+----------------+
|   Pizza   | Units produced | Hours required | Hours per unit |
+-----------+----------------+----------------+----------------+
| Pizza 1   |  23,156        |  12,154        | 0.524874762    |
| Pizza 2   |  25,145        |  21,154        | 0.841280573    |
| Pizza 3   |  2,055         |  2,015         | 0.98053528     |
| Pepperoni |  50,356        |  13,051        | 0.259174676    |
| Bacon     |  35,465        |  9,004         | 0.253884111    |
| Pineapple |  6,254         |  504           | 0.080588423    |
| Pizza 4   |  26,413        |  15,014        | 0.568432211    |
+-----------+----------------+----------------+----------------+

Eg, for Pizza 1, Pepperoni and Pineapple are the raw materials used.
So I take the HPU of Pepperoni and Pineapple, multiple it by units of pizza 1 and add it to the hours required for pizza 1.
Weighted hours Pizza 1 = 12,154 + (0.259174676 * 23,156) + (0.080588423 * 23,156)
I use this calculated Weighted hours to get the UPH.
+---------+--------------+----------+----------------+-------------+
| Product | Ingredients  |  Units   | Weighted hours |     UPH     |
+---------+--------------+----------+----------------+-------------+
| Pizza 1 |              |  23,156  |  20,021.55     | 1.156553563 |
| Pizza 1 | Pepperoni    |          |                |             |
| Pizza 1 | Pineapple    |          |                |             |
| Pizza 2 |              |  25,145  |  33,020.50     | 0.761496713 |
| Pizza 2 | Pepperoni    |          |                |             |
| Pizza 2 | Bacon        |          |                |             |
| Pizza 3 |              |  2,055   |  3,234.95      | 0.635250364 |
| Pizza 3 | Pepperoni    |          |                |             |
| Pizza 3 | Bacon        |          |                |             |
| Pizza 3 | Pineapple    |          |                |             |
| Pizza 4 |              |  26,413  |  15,014        | 1.759224724 |
+---------+--------------+----------+----------------+-------------+

I further want to roll up the UPH calculations to Pizza combos where Combo 1 = Pizza 1 + Pizza 2
And its weighted UPH = (Units of Pizza 1 + Pizza 2) / (Weighted Hours of Pizza 1 + Pizza 2)
+---------+---------+--------+-----------+-------------+
|  Combo  |         | Units  |   Hours   |     UPH     |
+---------+---------+--------+-----------+-------------+
| Combo 1 |         | 48,301 | 53,042    | 0.910617118 |
| Combo 1 | Pizza 1 | 23,156 | 20,021.55 |             |
| Combo 1 | Pizza 2 | 25,145 | 33,020.50 |             |
| Combo 2 |         | 27,200 | 36,255    | 0.750232198 |
| Combo 2 | Pizza 2 | 25,145 | 33,020.50 |             |
| Combo 2 | Pizza 3 | 2,055  | 3,234.95  |             |
+---------+---------+--------+-----------+-------------+

Further, this is how I plan to manage and bring in the pizza/ingredients/combo combination via excel into the model
+---------+---------+-------------+
|  Combo  |  Pizza  | Ingredients |
+---------+---------+-------------+
| Combo 1 | Pizza 1 |             |
| Combo 1 | Pizza 1 | Pepperoni   |
| Combo 1 | Pizza 1 | Pineapple   |
| Combo 1 | Pizza 2 |             |
| Combo 1 | Pizza 2 | Pepperoni   |
| Combo 1 | Pizza 2 | Bacon       |
| Combo 2 | Pizza 2 |             |
| Combo 2 | Pizza 2 | Pepperoni   |
| Combo 2 | Pizza 2 | Bacon       |
| Combo 2 | Pizza 3 |             |
| Combo 2 | Pizza 3 | Pepperoni   |
| Combo 2 | Pizza 3 | Bacon       |
| Combo 2 | Pizza 3 | Pineapple   |
| NA      | Pizza 4 |             |
+---------+---------+-------------+

I need help calculating the measure and/or suggestions of an approach I should take to get the Weighted UPH which can be used over time and be able to roll up as well.
Comment: I could not create a single measure to work through the formula so I ended up creating an extra table by crossjoining the Combination table with the calendar table on week granularity and calculating HPU and weighted hours on weekly basis, and using if condition to calculate weighted UPH and using that for my calculations. Not an ideal solution since if I am producing support units to be used in next week, they will get account for in the current week and not next week. My production and usage varies.
Answer: I have an approach suggestion for you.
If I was going to do this in PBI, I would have an ingredients table, a pizza table and a combo table.
(PBI calls a table a query)
Ingredients:
IngredientName   HourlyCost_PerUnit
Pepperoni        0.259174676

Pizza:
PizzaName  HPU           HPU_Extended               Ingredient1  Ingredient2   Units_Sold
Pizza1     0.524874762   (sum ingredients HPU)      Pepperoni    Bacon         25793

Combo:
ComboName   CombinedItem1   CombinedItem2   Units_Sold   HPU              HPU_Extended
Combo1      Pizza1          Pizza2          15268        (sum Pizza HPU)  (sum pizza HPU extended)

You would need to expand the count of columns in Pizza and Combo to suit your needs. As I happen to work in the Pizza industry as a second job, I am making the assumption these should be a manageable count of columns based on what we do.
I would then ensure I specify the relationships to work from Combo to Pizza to Ingredient. I would specify 'both' for the direction of filtering. In this approach, I envisage extended reporting limitations when using the 'single' setting. For instance, if you wanted to look at pizzas that only contain Pepperoni, when you try to filter it down by clicking pepperoni it wouldn't work.
You should then find it a lot easier to do calculated queries/columns.
Ref your intended excel input file. If you could break it down to how I have specified (table = sheet), it would work better, however, if you have to use that format, PBI can handle it by using 'Transform Data' where you could create tables by using the built-in tools.

A very strong recommendation to have a read on creating tables from
your data in PBI as there are many pitfalls.

A perfect example of how it can be done is here.
Now your data should be granular enough to be dynamic within PBI.
Many Thanks
POC
Comment: This is not working in my case because I am trying to calculate 1 measure which would work for the Combo as well as the Pizza. I got the UPH for the Pizza but when I try to add it for the measure, it messes up


How to monitor SQL statements that are doing hard delete

Question: I have an application that interacts with SQL Server 2008. I want to write a tool that help me identifying the SQL statements that causes hard delete in the table. Is it possible to find out using the SQL Profiler? or should i write triggers in all the stored procedures to find out that? how to achieve it. any directions would be helpful.
Comment: what is exactly hard delete ? Do you have some sort of IsDeleted flag in the table ?
Comment: Yes we have flag that will do soft delete but at times we completely remove the row from the table that is what we need to identify
Answer: First, take a look to Monitoring the progress of an SQL query in SQL SERVER. To monitor progress for some sql query see example.


Beginning with SharePoint 2013

Question: Hi I am new to sharepoint, and i wanted to know which website provides few tutorials to learn the Sharepoint from the very basic.
I went through few sites all of them try to "beating around the bush" rather than explaining with a hands on.
Please suggest some websites which have hands on to start with.
Thanks.
Comment: First of all, what are you planning to do with sharepoint? (programming, administration, client-side access, ...)
Comment: I am trying to learn programing.
I have to develop a blog site with lot of UI modification, and we are planning to host it on cloud and hence we are not planning to do programming in c#.

I just wanted to see some hands on i have experience in php, javascript, html. But don't have any knowledge on c# or .net i hope they are needed much for Sharepoint.

Thanks.
Comment: If you don't want to program (customizations in sharepoint are written in C#, ASP.NET), then  you should use an application called "Sharepoint Designer". It is sort of an administration tool of sharepoint and allows you to do a lot of different stuff like editing html of templates and such things.
Comment: Thanks for the response RononDex
Answer: I would suggest start with SharePoint 2013 SDK
http://www.microsoft.com/en-in/download/details.aspx?id=30722

Beginning with SharePoint 2013


Matlab Data Import

Question: I have data of the type in a text file:
<code>object ID: 1114
class label: 1
sign meaning: 15-fr

trajectory:
   -0.802268        0.585080
   -0.802268        0.567350
   -0.802268        0.549620
   -0.802268        0.523026
   -0.802268        0.496431
   -0.802268        0.478702
   -0.802268        0.469837
   -0.788971        0.438810
   -0.788971        0.438810
   -0.788971        0.438810
   -0.788971        0.438810
   -0.788971        0.438810
   -0.788971        0.447675
   -0.793404        0.505296
   -0.793404        0.527458
   -0.793404        0.527458
   -0.784539        0.527458
   -0.775674        0.514161
   -0.780106        0.491999
   -0.771241        0.483134
   -0.762377        0.469837
   -0.753512        0.469837
   -0.753512        0.478702
   -0.753512        0.487566
   -0.753512        0.505296
   -0.753512        0.549620
   -0.757944        0.598377
   -0.757944        0.598377
   -0.757944        0.580647
   -0.757944        0.558485
   -0.757944        0.540755
   -0.757944        0.531891
   -0.744647        0.527458
   -0.744647        0.527458
   -0.744647        0.527458
   -0.744647        0.536323
   -0.744647        0.571782
   -0.744647        0.607242
   -0.744647        0.642701
   -0.744647        0.655998
   -0.744647        0.638269
   -0.740214        0.607242
   -0.735782        0.585080
   -0.735782        0.567350
   -0.731350        0.558485
   -0.731350        0.558485
   -0.731350        0.558485
   -0.731350        0.558485
   -0.731350        0.580647
   -0.731350        0.607242
   -0.744647        0.647134
   -0.753512        0.678161
   -0.753512        0.678161
   -0.753512        0.651566
   -0.744647        0.633836
   -0.744647        0.607242
   -0.744647        0.598377
   -0.744647        0.589512
   -0.735782        0.589512
   -0.735782        0.589512
   -0.735782        0.589512
   -0.735782        0.589512
   -0.735782        0.589512
   -0.735782        0.598377
   -0.735782        0.616107
   -0.735782        0.655998
   -0.740214        0.673728
   -0.731350        0.673728
   -0.731350        0.655998
   -0.731350        0.629404
   -0.731350        0.602809
   -0.718052        0.580647
   -0.709188        0.571782
   -0.709188        0.571782
   -0.700323        0.571782
   -0.700323        0.571782
   -0.700323        0.571782
   -0.700323        0.571782
   -0.709188        0.629404
   -0.709188        0.655998
   -0.722485        0.687025
   -0.726917        0.700323
   -0.726917        0.700323
</code>
How do I import this into Matlab. I want to store all of the data, not just the numerical. I have tried importdata in Matlab but am losing the data from object id and class label. The data above is just one object and I have about 2000 such objects. I want to store all these in sequential order.
Comment: What do you mean "I want to store all these in sequential order"? You may store the data in a cell array of strings. Data structure looks like: `A{1} = 'object ID: 1114';` `A{2} = 'class label: 1';` `A{3} = sign meaning: 15-fr;`... Is it sufficient storing each line in a string, or do you expect something more meaningful, (e.g pairs of name, and value)?
Answer: This script opens your file and reads the header and the data.
<code>%Open file as text
fid=fopen('filename.txt','rt');

%First read the header information
l='';
header=struct;
l=fgetl(fid);
while ~strcmp(l,'trajectory:')
    s=regexp(l,':','split');
    s{1}=regexprep(s{1},' |-','_'); %remove spaces from header names
    if length(s)==2
        header.(s{1})=s{2};
    end
    l=fgetl(fid);
end

%then read data
data=[];
l=fgetl(fid);
while ~isnumeric(l)
    data(end+1,:)=str2num(l);
    l=fgetl(fid);
end
fclose(fid);
clear s l fid
</code>

Matlab Data Import


having issues with pyqtgraph in pyqt4

Question: I have tried to boil down my program to be as simple as possible and still be functional.  First is my UI file with the tabs that I want.  It has a graph in the Control tab and I want the play button to start the plot.
When I start it I can't get the graph to show up. any help would be appreciated.
from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(800, 600)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.tabWidget = QtGui.QTabWidget(self.centralwidget)
        self.tabWidget.setGeometry(QtCore.QRect(0, 0, 801, 421))
        self.tabWidget.setStyleSheet(_fromUtf8(""))
        self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
        self.tab_4 = QtGui.QWidget()
        self.tab_4.setObjectName(_fromUtf8("tab_4"))
        self.tabWidget.addTab(self.tab_4, _fromUtf8(""))
        self.tab_2 = QtGui.QWidget()
        self.tab_2.setObjectName(_fromUtf8("tab_2"))
        self.tabWidget.addTab(self.tab_2, _fromUtf8(""))
        self.tab = QtGui.QWidget()
        self.tab.setObjectName(_fromUtf8("tab"))
        self.pushButton = QtGui.QPushButton(self.tab)
        self.pushButton.setGeometry(QtCore.QRect(290, 340, 75, 31))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8("play_button.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton.setIcon(icon)
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.pushButton_2 = QtGui.QPushButton(self.tab)
        self.pushButton_2.setGeometry(QtCore.QRect(460, 340, 75, 31))
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(_fromUtf8("pause_button.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton_2.setIcon(icon1)
        self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
        self.pushButton_3 = QtGui.QPushButton(self.tab)
        self.pushButton_3.setGeometry(QtCore.QRect(630, 340, 75, 31))
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap(_fromUtf8("resume_button.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton_3.setIcon(icon2)
        self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
        self.graphicsView = QtGui.QGraphicsView(self.tab)
        self.graphicsView.setGeometry(QtCore.QRect(205, 1, 591, 341))
        self.graphicsView.setObjectName(_fromUtf8("graphicsView"))
        self.tabWidget.addTab(self.tab, _fromUtf8(""))
        self.tab_3 = QtGui.QWidget()
        self.tab_3.setObjectName(_fromUtf8("tab_3"))
        self.tabWidget.addTab(self.tab_3, _fromUtf8(""))
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(2)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_4), _translate("MainWindow", "Calibration", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "Material", None))
        self.pushButton.setText(_translate("MainWindow", "Start Plot", None))
        self.pushButton_2.setText(_translate("MainWindow", "Pause", None))
        self.pushButton_3.setText(_translate("MainWindow", "Resume", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Control", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), _translate("MainWindow", "Operator", None))

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
sys.exit(app.exec_())

The second is my graphing class which does work when I make a gui with code, but I would like to be able to plug it into a program with a ui file.
import sys
import time
import datetime
from PyQt4 import QtCore, QtGui, uic
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import pyqtgraph as pg
import random
from workingraspitab2 import Ui_MainWindow

class Main(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(Main, self).__init__(parent)
        self.setupUi(self)
        self.graphicsView = QtGui.QStackedWidget()
        self.login_widget = LoginWidget(self)
        self.graphicsView.addWidget(self.login_widget)
        self.pushButton.clicked.connect(self.plotter)#the play button
        self.curve = self.login_widget.it1
        self.curve2 =self.login_widget.it2

    def plotter(self):
        self.data =[0]
        self.data2 = [0]
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.updater)
        self.timer.start(0)
        print self.data

    def updater(self):
        self.data.append(self.data[-1]+10*(0.5-random.random()))
        self.curve.setData(self.data, pen=pg.mkPen('b', width=1))
        self.data2.append(self.data2[-1]+0.1*(0.5-random.random()))
        self.curve2.setData(self.data2, pen=pg.mkPen('r', width=1))
        print self.data

class LoginWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        super(LoginWidget, self).__init__(parent)
        pg.setConfigOption('background', 'w')
        pg.setConfigOption('foreground', 'k')
        self.plot = pg.PlotWidget(title='Force and Extension vs. Time')
        p1 = self.plot.plotItem
        p2 = pg.ViewBox()
        p1.showAxis('right')
        p1.scene().addItem(p2)
        p1.getAxis('right').linkToView(p2)
        p2.setXLink(p1)

        self.plot.getAxis('bottom').setLabel('Time', units='s')
        self.plot.getAxis('left').setLabel('Force', units='lbf', color="#0000ff")
        p1.getAxis('right').setLabel('Extension', units='in.', color="#ff0000")

        def updateViews():
            p2.setGeometry(p1.vb.sceneBoundingRect())
            p2.linkedViewChanged(p1.vb, p2.XAxis)

        updateViews()
        p1.vb.sigResized.connect(updateViews)

        self.it1 = p1.plot()
        self.it2 = pg.PlotCurveItem()
        p2.addItem(self.it2)

if __name__ == '__main__':

    import sys
    app = QtGui.QApplication(sys.argv)
    window = Main()
    window.show()
    sys.exit(app.exec_())

Answer: Had to put everything in the Main class to get it to work. I was hoping for a more elegant solution. I still cant get the background or foreground to change, but it is working and here is the code:
class Main(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(Main, self).__init__(parent)
        self.setupUi(self)
        pv = self.graphicsView
        pv.setTitle('Force and Extension vs. Time')
        pg.setConfigOption('background', 'w')
        pg.setConfigOption('foreground', 'k')
        p1 = pv.plotItem
        p2 = pg.ViewBox()
        p1.showAxis('right')
        p1.scene().addItem(p2)
        p1.getAxis('right').linkToView(p2)
        p2.setXLink(p1)
        pv.getAxis('bottom').setLabel('Time', units='s')
        pv.getAxis('left').setLabel('Force', units='lbf', color="#0000ff")
        p1.getAxis('right').setLabel('Extension', units='in.', color="#ff0000")
        def updateViews():
            p2.setGeometry(p1.vb.sceneBoundingRect())
            p2.linkedViewChanged(p1.vb, p2.XAxis)
        updateViews()
        p1.vb.sigResized.connect(updateViews)
        self.it1 = p1.plot()
        self.it2 = pg.PlotCurveItem()
        p2.addItem(self.it2)

        self.pushButton.clicked.connect(self.plotter)
        self.pushButton_2.clicked.connect(lambda: self.timer.stop())
        self.pushButton_3.clicked.connect(self.timer_start)
        self.curve = self.it1
        self.curve2 = self.it2

having issues with pyqtgraph in pyqt4


Possible permissions error with drush make

Question: I am trying to run drush make distro.make but getting the following error. The only thing I can see I did different was ran sudo drush make distro.make once. Any ideas?

copy(/http---updates.drupal.org-release-history-drupal-7.x): failed to open stream: Permission denied drush.inc:840                                                                                [warning]
Could not download project status information from http://updates.drupal.org/release-history/drupal/7.x                                                                                [error]
Non-existent project type  on project drupal

previously I was running without sudo and it was working fine.
Answer: Problem was that running sudo drush had probably added some unwanted permissions to the cache folder. Deleting the folder solved the problem.


Gigabit port mirroring to a maximum throughput 150 Mbps IDS

Question: I maybe installing an IDS that has a maximum throughput of 150 Mbps. Instead of putting it inline on my main gigabit port to the rest of the network, I would like to just mirror that port and install the IDS on that. The question I have is will I still see performance hit on the port that I am mirroring when the mirrored port is connected to such a slow device?
Answer: No.  I suppose that your IDS could "drop" mirrored traffic in excess of its capacity, but it would not affect anything upstream.
One thing to consider is that your switch may allow only one mirroring configuration, to a single port; is there a chance that you would ever need to mirror anything else on the same switch?
Comment: We had your scenario on a VoIP network once. They port-mirrored and then attached a 10Mb hub, problem solved ;) (if you can find a hub and if 10Mb is enough throughput)
Comment: We have some BayStack 253s (24-port 100M hubs) for this purpose.  You should be able to get them at prices in the neighborhood of $50-70 each from resellers that specialize in refurbished equipment. I like CXtec for this sort of thing because they slap a lifetime warranty on every used item they sell, but I'm sure there are other good options too.


Change datetime format

Question: I have below code :-
1) String str = DateTime.Now.ToString("M/d/yyyy")

Output :
str gives "2/3/2014"

2) DateTime dt = Convert.ToDateTime(DateTime.Now.ToString("M/d/yyyy"));

Output :
dt.ToString() gives "2014/02/03 12:00:00 "

But I'm not able to understand why it is not giving "2014/2/3 12:00:00 " ,i.e, without leading zeroes in day and month?
Comment: Because you are now formatting a DateTime value with no format specified, using dt.ToString().
Comment: I want to convert datetime format in dt as 2014/2/3. Is it possible ?
Comment: I want to convert it finally into a datetime and when i convert, it applies leading zeroes in dt.
Comment: Is it possible to get the value in dt as 2014/2/3 ?
Answer: DateTime values have no format, it is the DateTime.ToString() method that outputs your datetime value in a  particular format.
If you don't specify any parameter in the ToString() then the output is formatted using the general date and time format specifier ('G').  (Usually is the one set up in you control panel international settings)
Console.WriteLine(dt.ToString("M/d/yyyy"));

Comment: Is it possible to get the value in dt as 2014/2/3 ?
Comment: Why not: `dt.ToString("yyyy/M/d")`  Well assuming 2 is the month
Answer: The default format string for System.DateTime is "G" as in System.DateTime.ToString("G") where G is one of the presets. from source
Edit 1:
    Globalization.CultureInfo customCulture = new Globalization.CultureInfo("en-US");

    customCulture.DateTimeFormat.ShortDatePattern = "yyyy/M/d";

    System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
    System.Threading.Thread.CurrentThread.CurrentUICulture = customCulture;

    DateTime dt = Convert.ToDateTime(DateTime.Now.ToString("M/d/yyyy"));
    Console.WriteLine(dt.ToString())

Comment: Is it possible to get the value in dt as 2014/2/3 ?
Answer: When using ToString() without any format, it simply uses the default ToString() method.
Use the format you specified again to get the wanted result.
Answer: you can use the Format function for displaying the way you want
string.Format("{0:yyyy/M/d}",dateValue);

regards
Comment: When i convert it into datetime then it agains applies leading zeroes.

Change datetime format


Proof of more general strong law of large numbers for dependent random variables

Question: I want to show the following version of the strong law of large numbers. This is the longest proof I've ever attempted, and I feel a bit overwhelmed.
Let $X_i$ be a sequence of real-valued
random variables with $E(X_i^2)<\infty$ for all $i$. If there is a sequence $c_k\subseteq[0,\infty)$ such that $C=\sum_{k=0}^\infty c_k <\infty$ and $\operatorname{Cov}(X_i,X_j)\le c_{|i-j|}$, then
$$\lim_{n\rightarrow\infty}\frac1n\sum_{i=1}^n(X_i-E(X_i))=0$$
I have the following proof outline provided to me:

Show $V(\sum_{a+1}^bX_i)\le 2(b-a)C$ (Done)

Subsequence: Show
$$\lim_{k\rightarrow\infty}\frac1{k^2}\sum_{i=1}^{k^2}(X_i-E(X_i))=0\text { a.s.}$$

Fluctuation: Show
$$\lim_{k\rightarrow\infty}\frac1{k^2}\max\left\{\left\lvert\sum_{i=k^2+1}^m(X_i-E(X_i))\right\rvert:m\in\{k^2,...,k^2+2k\}\right\} = 0\text{ a.s.}$$

Deduce the claim

I have successfully shown (1). I'm not sure it's correct, but I think I've shown (2) like so: For sufficiently small $\delta$ we have
$$\begin{aligned}P\left(\left\lvert\lim_{k\rightarrow\infty}\frac1{k^2}\sum_{i=1}^{k^2}(X_i-E(X_i))\right\rvert > 0\right)
&= P\left(\left\lvert\lim_{k\rightarrow\infty}\frac1{k^2}\sum_{i=1}^{k^2}(X_i-E(X_i))\right\rvert \ge \delta\right)\\
&\le \lim_{k\rightarrow\infty}\frac1{k^4}\frac{V(\sum_{i=1}^{k^2}(X_i-E(X_i))}{\delta^2} = 0
\end{aligned}$$
Is this valid? I'm not sure about the way I rewrote the inequality and pulled the limit out of the variance.
I have no ideas for how to show (3), I don't know how to "break" that maximum. Also, the final step is not obvious to me, again because the max-statement confuses me.
How can I close out this proof? Does someone know a reference for a proof of this law?
Answer: First of all, let us make a simplification. Set $Y_i=X_i-EX_i$ and note that $EY_i=0$ and $Cov(Y_i, Y_j)=Cov(X_i, X_j).$ The conclusion of your theorem can be recasted as $\frac{1}{n}\sum_i^n Y_i\to 0$ almost surely.
The first step in such proofs is to show a weaker result, namely, we establish that $S_n:=\frac{1}{n}\sum_i^n Y_i\to 0$ in probability. The usual tool for showing the convergence in probability is Chebyshev's inequality. In fact, once you have a quantitative estimate coming from Chebyshev's inequality, one can write an explicit sequence $k_n$ such that $S_{k_n}\to 0$ almost surely (this argument usually requires Borel-Cantelli). In your case (we will see), suffices to take $k_n=n^2.$
Once you have got the a.s. convergence along subsequence $k_n,$ you want to strengthen it along the full sequence. The argument for this part usually goes as follows. For any $m,$ let $k_{n_m}$ be such that $k_{n_m}\le m\le K_{n_{m+1}}.$ Now, you know that $|S_m|\le |S_m-S_{k_m}|+|S_{k_m}|.$ We already know that $S_{k_m}\to 0$ a.s., therefore, suffices to show that $|S_m-S_{k_m}|\to 0$ almost surely. This is the fluctuation. In simple cases, like the present, it is often handled by using Chebyshev's inequality and applying Borel-Cantelli.
Let us now see the above principles in action. You already have $V(\sum_{i=m+1}^{n}Y_i)\le 2(n-m)C.$ Use the Chebyshev's inequality to obtain $$P\left(\frac{1}{n}|\sum_{i=1}^{n}Y_i|\ge \delta\right)=\frac{2nC}{n^2\epsilon^2}=\frac{2C}{n\epsilon^2}.$$
This already tells us that $S_n\to 0$ in probability. It also tells us that if we take $k_n=n^2,$ then $P(S_{k_n}\ge \epsilon)\le \frac{2C}{n^2\epsilon^2}.$ Applying Borel-Cantelli, we obtain therefore that $S_{k_n}\to 0$ almost surely. (Note that any sequence $k_n$ such that $\sum k_n^{-1}<\infty$ would work.) This corresponds to Step 2 in your outline.
Before going to the third step, first note that $$|S_m|\le |S_m-S_{k^2}|+|S_{k^2}|$$ where $k$ is such that $k^2\le m<(k+1)^2.$
The second term namely $S_{k^2}\to 0$ almost surely. So we are concerned about the first term. Let us look at it more closely. Observe that
$$|S_m-S_{k^2}|\le |\sum_{i=1}^{k^2}Y_i(\frac{1}{k^2}-\frac{1}{m})|+\frac{1}{m}|\sum_{i=k^2+1}^{m}Y_i|\le |S_{k^2}|+\frac{1}{m}|\sum_{i=k^2+1}^{m}Y_i|.$$
Once again $S_{k^2}\to 0$ almost surely. Therefore, we now focus on the 'fluctuation' $\frac{1}{m}|\sum_{i=k^2+1}^{m}Y_i.$ Apply Chebushev's inequality to obtain $$P(\frac{1}{m}|\sum_{i=k^2+1}^{m}Y_i|>\epsilon)\le \frac{Var(\sum_{i=k^2+1}^{m}Y_i)}{m^2\epsilon^2}\le \frac{2C(m-k^2)}{m^2\epsilon^2}\le \frac{4Ck}{k^4\epsilon^2}\le \frac{C_{\epsilon}}{k^3}.$$
Now Borel-Cantelli lemma gives you that $\frac{1}{m}|\sum_{i=k^2+1}^{m}Y_i|\to 0$ almost surely. Thus completing the proof.
Comment: I appreciate you pointing out the general scheme, it was insightful!


A simple c++11 macro

Question: I'm trying to construct a simple c++ macro and I cannot even get started.  Google hasn't helped so far.
#define blow (...) __VA_ARGS__
int main () {
    blow();
    }

Produces these errors:
g++ -fpermissive -std=gnu++11 -g3 -I/eclipse/workspace/shared /eclipse/workspace/shared/amanda.c++ -o /binaries/amanda
[g++ shared/amanda took 0.0 seconds]
 1. /eclipse/workspace/shared/amanda.c++:7:20: warning: __VA_ARGS__ can only appear in the expansion of a C99 variadic macro [enabled by default]
 2.  #define blow (...) __VA_ARGS__
 3.                     ^
 4. /eclipse/workspace/shared/amanda.c++: In function 'int main()':
 5. /eclipse/workspace/shared/amanda.c++:7:15: error: expected primary-expression before '...' token
 6.  #define blow (...) __VA_ARGS__
 7.                ^
 8. /eclipse/workspace/shared/amanda.c++:9:2: note: in expansion of macro 'blow'
 9.   blow();
10.   ^
11. /eclipse/workspace/shared/amanda.c++:7:15: error: expected ')' before '...' token
12.  #define blow (...) __VA_ARGS__
13.                ^
14. /eclipse/workspace/shared/amanda.c++:9:2: note: in expansion of macro 'blow'
15.   blow();
16.   ^

Comment: https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
Comment: I've been through the Variadic-Macros document.  The difference is that I want to allow for no values rather that requiring an initial "format" field.
Comment: If your goal is to construct a simple macro, then don't try to create a variadic macro, since those are less simple than non-variadic.
Comment: It will be a simple macro that feeds a variadic macro.
Comment: What I am hoping for is an understanding of the error messages.
Answer: The macro definition should be without spaces between the macro name and (:
#define blow(...) __VA_ARGS__
int main () {
    blow();
}

With space, you define the normal non-variadic macro blow which expands to (...) __VA_ARGS__, which causes your error messages.

A simple c++11 macro


Logstash: Kafka Output Plugin - Issues with Bootstrap_Server

Question: I am trying to use the logstash-output-kafka in logstash:
Logstash Configuration File
input {
  stdin {}
}

output {
  kafka {
  topic_id => "mytopic"
  bootstrap_server => "[Kafka Hostname]:9092"
  }
}

However, when executing this configuration, I am getting this error:
[ERROR][logstash.agent ] Failed to execute action
{:action=>LogStash::PipelineAction::Create/pipeline_id:main,
:exception=>"LogStash::ConfigurationError", :message=>"Something is wrong
with your configuration."

I tried to change "[Kafka Hostname]:9092" to "localhost:9092", but that also fails to connect to kafka. Only when I remove the bootstrap_server configuration (which then defaults to localhost:9092) then the kafka connection seems to be established.
Is there something wrong with the bootstrap_server configuration of the kafka output plugin? i am using logstash v6.4.1, logstash-output-kafka v7.1.3
Answer: I think there is a typo in your configuration. Instead of bootstrap_server you need to define bootstrap_servers.
input {
  stdin {}
}

output {
  kafka {
  topic_id => "mytopic"
  bootstrap_servers => "your_Kafka_host:9092"
  }
}

According to Logstash Docs,

bootstrap_servers
  Value type is string
  Default value is "localhost:9092"
  This is for bootstrapping and the producer will only
  use it for getting metadata (topics, partitions and replicas). The
  socket connections for sending the actual data will be established
  based on the broker information returned in the metadata. The format
  is host1:port1,host2:port2, and the list can be a subset of brokers or
  a VIP pointing to a subset of brokers.


Overriding views default templates

Question: I'm trying to override default views templates using _theme_process_registry() function.
It's ok, but i've got some trouble when administrator trying to redefine output via views_ui interface. When he creates a new template, he obviously starts from default views templates (views/theme folder), so my templates is lost.
I'm trying to do so:
<code>$theme_path = drupal_get_path('module', 'mymodule') . '/theme/default_templates';

/**
 * List all plugins trying to find overriden in our work directory
 */
foreach($plugins as $group_name => $plugins_group) {
    foreach ($plugins_group as $plugin_name => $plugin) {
        if (isset($plugin['theme']) && file_exists($theme_path . '/' .  strtr($plugin['theme'], '_', '-') . '.tpl.php')) {
            $plugins[$group_name][$plugin_name]['theme path'] = $theme_path;
        }
    }
}
</code>
but single field template doesn't work, coz its hardcoded in view_plugin_display.inc
<code>// Field templates aren't registered the normal way...and they're always
// this one, anyhow.
$output .= '<pre>' . check_plain(file_get_contents(drupal_get_path('module', 'views') . '/theme/views-view-field.tpl.php')) . '</pre>';
</code>
Is anybody know how to fully override views templates to my own module directory?
And the second. I need to create more semantic markup like on  dev.twitter.com.
How to redefine classes_array to get rid of extra classes and div elements?
I'm using drupal 7 and views 3.
Answer: Are the templates that are overriding your templates included in a Theme? Themes always take precedence over modules, so any template in a theme will always override the corresponding template from a module. You may want to consider re-phrasing your question to reference the original issue you are solving with your template files.
If you are referring specifically to Views output with your desire to create semantic markup, I would suggest the Semantic Views module.
Comment: I think semantic views is perfectly okay, thx a lot :)

Overriding views default templates


problem in $z$ transform

Question: Im having a hard time trying to solve this...
if $   (x_{k})_{k=0}^\infty $ is  a  causal succession such  as
$$ Z(x_{k}) = X(z)   \parallel z \parallel > R $$
prove that $$  Z( {{x_{k+2}}})  = Z^{2}X(z)-z^{2}x_{0}-zx_{1}, \parallel z \parallel > R$$
Can anybody help me?
Answer: The problem essential states that
\begin{align}
\sum_{k=0}^{\infty} x_{k} \ z^{-k} = X(z)
\end{align}
and asks to find a similar result for $x_{k+2}$. It can be seen that
\begin{align}
\sum_{k=0}^{\infty} x_{k+2} \ z^{-k} &= \sum_{k=2}^{\infty} x_{k} \ z^{-k+2} \\
&= z^{2} \left( \sum_{k=0}^{\infty} x_{k} \ z^{-k} - x_{0} z^{o} - x_{1} z^{-1} \right) \\
&= z^{2} X(z) - x_{0} z^{2} - x_{1} z.
\end{align}
Hence
\begin{align}
Z(x_{k+2}) = z^{2} X(z) - x_{0} z^{2} - x_{1} z.
\end{align}
In a similar manor it can be shown that
\begin{align}
Z(x_{k+1}) = z X(z) - x_{0} z.
\end{align}

problem in $z$ transform


Let $(\alpha_\xi\mid\xi<\kappa)$ be a sequence such that $\{\alpha_\xi\mid\xi<\kappa\}=\alpha$. Find an increasing subsequence that has limit $\alpha$

Question: Let $\alpha$ be a limit ordinal which is not a cardinal, and $\kappa=|\alpha|$. Then there exists a bijection from $\kappa$ to $\alpha$, or equivalently, a one-to-one sequence  $\langle \alpha_\xi \mid \xi< \kappa \rangle$ of ordinals such that $\{\alpha_\xi \mid \xi< \kappa\}=\alpha$.
My textbook states:

Now we can find (by transfinite recursion) a subsequence which is strictly increasing and has limit $\alpha$.

I have tried but to no avail in constructing such subsequence, please shed me some lights.
Thank you so much!
Comment: Pick one, then continue picking the least indexed ordinal which is strictly larger.
Comment: @William: Yes, and? Your answer is different how?
Comment: @LeAnhDung: Why wouldn't it be?
Comment: @AsafKaragila.  He means ordinal sequence.
Comment: Hi @AsafKaragila, is it correct that this subsequence is *cofinal* in $\alpha$?
Answer: Let K = { a$_t$ : t < $\kappa$ }.
Define, using strong transfinite induction
s$_u$ = min{ a$_t$ in K : for all j < u, s$_j$ < a$_t$ }.


How to check if a data set can be modelled by a normal distribution?

Question: I have a set of velocity data (37 data points) and I want to know how to check if the data can be modelled with a normal distribution.
From a guide on youtube I have calculated the CDF, expected values and Z-values and produced a plot of the expected values and real data against the z-values.
From here I'm lost as what to do next, how do I determine how well the data is modelled by a normal distribution from this plot? Some of the real data points lie above the line and some below and it seems to fit reasonably well but
I would like to be more quantitative about it.
Please bear in mind I know only basic statistics and this has already gone way beyond my knowledge.
Comment: I'm curious how you calculated a CDF and z-values, because if your data are in anything more than one dimension, then velocities are vectors, by definition. Are you sure you don't have *speeds*?
Comment: sorry yes they are speeds.
Comment: not clear what is the dimensions of normal distribution. is it spatial? 3D?
Comment: The set of data is essentially the magnitudes of a set of velocities (speeds) so the normal distribution would be 2d I guess.
Comment: No, the distribution would have to be one-dimensional, since a speed is just a number. In many circumstances a normal distribution would be a poor choice of model for a distribution of speeds. What kind of thing do your speeds measure?
Answer: Here is a Wikipedia article on it.
In summary:
You can look at a histogram of the data, does the shape look similar to a normal distribution? You can look at quantile-quantile plots (Q-Q plots), do the sample quantiles of your data match up to the theoretical quantiles of a normal distribution?
You can do a hypothesis test to formally test this (Shapiro-Wilk test, etc)
What software do you use? I can show you specific examples of how to do the above mentioned techniques.
Here is a nice excel video for QQ plots
Comment: I think the Q-Q plot is likely to be more relevant than doing a formal hypothesis test.
Comment: I concur with @Glen_b.  Q-Q plots are easy to create in Excel, too.
Comment: QQ plots certainly are the go-to method.
Answer: This began as a comment but it has grown much too long, and it is coming closer to being a kind of answer. This doesn't take anything away from bdeonovic's answer which is fine as a direct answer to the question asked. I'm going to focus more on the premises of the question.

I'd agree with whuber that in many situations speeds are unlikely to be particularly close to normally distributed. They're positive, generally right skew, and often have variability that's related to the mean (when mean speeds are low, there's not much "room" for values to vary away from the mean, since they can't be negative).
In some situations Rayleigh distributions can be useful for lengths of 2D vectors (speeds of things moving in 2D), and the Maxwell-Boltzmann is sometimes useful for lengths of 3D vectors. Both these distributions have variance proportional to mean-squared. In other situations I've seed adequate approximations from Weibull, gamma, or lognormal distributions (and one or two cases where it was "none of the above"). Used in the way these would usually be used for modelling speeds, all of these have variance proportional to mean squared as well. In some cases (depending on what you're doing), several of these may lead to very similar conclusions. In general terms they fit what qualitative things we know about speeds.
If for some reason you really needed to have a variable close to normality, you might consider transformation (e.g. see here in the case of the Rayleigh), but I would not usually recommend this approach as a first choice (e.g. it would not be my first choice if you're considering some kind of regression model); in some situations it may work well enough.
It may not be very important to have a normal distribution in any case. Why do you need your data to be normal? What kinds of things do you want to do with it? For example, if you're trying to model speed as a function of predictors, it will be important to get the form of the relationship of the mean speed to the predictors correct, and the mean-variance relationship close to correct. There are good alternatives to normal models that may work better.


Java - serializable and sending object via socket

Question: I receive an error:
IOException on socket listen: java.io.NotSerializableException: java.net.Socket

i try to send an object via socket with this code :
ObjectOutputStream outObjects = new  ObjectOutputStream(socket.getOutputStream());
outObjects.writeObject(currentPlayer);

output.flush();

second line gives error....   but i have serialized  ( implements Serializable) the class Player (the class of the currentPlayer object)
 but one of the member of Player class is a Socket object.....
i try to redefine and serializeble the socket object but no way to solve the problem....
where am i  wrong ?
Comment: show the code of `currentPlayer`
Answer: You can not serialize Socket object, therefore you should make socket field transient. If you need some of socket properties, you can put extra fields to Player to represent these fields.
Comment: thx! i was thinking to that :(
 but i hoped it was possible in some way :)  since it is said almost all the classes implements serializable
so i ll take out addr, localport and port
THX!
Answer: It means that the Socket class is not serializable.
You have to set the Socket member as transient, then it will not be serialized.
Just be sure to recreate the Socket object in a private readObject(ObjectInputStream) method, otherwise you can encounter null pointer exceptions.
Answer: (Edited to answer the comment)
Try declaring the socket member as transient like in
private transient Socket socket;

This will inhibit the serialization machinery from trying to send the value of socket. Note, that you cannot meaningfully send objects holding values, which represent OS resources like socket handles, over to another process. In the best case, any attempt to use such an object on the receiving side will cause an exception to be thrown. In the worst case, such an attempt might introduce subtle bugs (data being sent to the wrong user). For this reason, such objects are never serializable (except if someone made a mistake).
Consider the following (simplified) example: on UNIX, a socket is represented by an integer number (the so-called file descriptor), which is returned by the OS when the socket is created. If this value is send to another process, there are no guarantees, that this number actually refers to a valid file handle open in the receiving process. Worse, if there is a file handle with the same numeric value in the receiving process, it is almost impossible to refer to the same socket open in the sending process. So, if the number is actually used as file descriptor in the receiving process when sending data, it will almost certainly go anywhere but the intended destination.
If sending and receiving processes are on the same machine, there are ways to transfer a "socket" over from one process to the other. But I doubt, that there are easy ways to access these OS calls from Java.
Comment: but  i need to send it with the Player  object
Answer: implements Serializable does not in itself make an object serializable. Any and all serialized fields in the object itself must in turn be serializable (and any and all fields that they contain).
As a socket is not serializable you should not try to send it over the line. You can exclude it from serializing by declaring it as transient. The deserialized object then of course does not have a socket, so you also might want to check out the optional readObject and writeObject methods in your object which will be used for serialization and deserialization.
Check out this article on serialization.
Answer: A socket is not serializable because it's tied to the machine, OS, etc. it's executing onto. To be serializable, an object 's class must implement Serializable, and must contain objects that are all serializable, recursively.
So, to serialize your player, you must exclude its socket attribute from the serialization. You do this by declaring the attribute transient :
private transient Socket mySocket;

When the player will be deserialized, its socket will thus be null, and there's a good chance it won't work correctly. You should probably review your design, because serializing an object which needs a socket to work probably doesn't make sense.
Answer: There are several ways to solve this problem, the fastest would be marking your Socket member transient. This ensures that javas default serialisation will ignore the Socket and your copy should contain null.
private transient Socket sock;

Alternatively you can provide your own serialisation methods, this requires that you write and read all members yourself. You can use the methods defined in Serializable (See below) or implement Externalizable instead.
 private void writeObject(java.io.ObjectOutputStream out)
     throws IOException
 private void readObject(java.io.ObjectInputStream in)
     throws IOException, ClassNotFoundException;

The cleanest would be separating your Players state from your network code, resulting in a class with only Serializable members. As a bonus the send class no longer contains invalid member fields.


OLS Assumption-No correlation should be there between error term and independent variable and error term and dependent variable

Question: My question is that does endogeneity exists if there is correlation between dependent variable and error term, but not in between error term and independent variable. So for Ex, we know there should be a positive correlation between x1 and y because of previous studies, but because, we didn't take a critical variable x2 into our regression model, the correlation between x1 and y is coming negative, this could be there because x2 is overpowering the effect of x1 to a great extent and hence the coefficients of x1 in our simple regression model would be biased but this doesn't imply that there is a correlation between x1 and x2, our 2 independent variables. This is a grave threat. So does this claim endogeneity?I have read that if the OLS Assumptions are satisfied, then it is the best estimator(both unbaised and minimum variance) of the coefficient of the independent variable. But then if you say this is not endogeneity, then all assumptions are satisfied for this regression model, and then too i have a biased coefficient in my regression model.
Comment: By definition, no. Endogeneity occurs when an explanatory variable is correlated with the error term.
Comment: I have read that if the OLS Assumptions are satisfied, then it is the best estimator(both unbaised and minimum variance) of the coefficient of the independent variable. But then if you say this is not endogeneity, then all assumptions are satisfied for this regression model, and then too i have a biased coefficient in my regression model.
Comment: Not necessarily. From a causal analysis viewpoint, you might not have a problem at all. Here are a couple of relevant answers: https://stats.stackexchange.com/questions/462513/does-confounding-always-imply-endogeneity/462534#462534 and especially this: https://stats.stackexchange.com/questions/462029/measuring-the-causal-impact-of-a-policy-that-is-not-binding/462098#462098
Comment: Correlation is not transitive.
Answer:
OLS Assumption-No correlation should be there between error term and
  independent variable and error term and dependent variable

No correlation between independent variable and error term is admissible definition, even if mean independence is more correct, but no correlation between dependent variable and error term is completely incorrect assumption. It is an absurd request. Error term is, by construction, a part of dependent variable, then, they must be dependent.

My question is that does endogeneity exists if there is correlation
  between dependent variable and error term, but not in between error
  term and independent variable

exactly the opposite is true.
The rest of the story sound like omitted variables problem. For discussion read here: https://en.wikipedia.org/wiki/Omitted-variable_bias
note that in this situation a correlation between $x_1$ and $x_2$, your notation, is implied.
Maybe you are interested in endogeneity problems. For discussion read here:
What is the actual definition of endogeneity?
Does homoscedasticity imply that the regressor variables and the errors are uncorrelated?
finally note that endogeneity not always is crucial assumption in regression; read here:
Endogeneity in forecasting
Comment: I did not understand why you said that correlation between independent and dependent variable is implied in my case
Comment: I have never said that. Correlation between $y$ and $x$ is precisely what you looking for with regression. Editing your question clarifying his math can be a good idea.


Enviar e-mail de forma assíncrona asp.net mvc

Question: Tenho um formulário que retorna ActionResult que envia um e-mail após concluir a operação.
Gostaria de deixar esse e-mail assíncrono, pois demora bastante as vezes, tentei colocar em uma Task usando o método SendMailAsync da classe SmtpClient, contudo não funciona.
Alguém saberia me dizer o que preciso fazer para enviar esses e-mails de forma assíncrona no asp.net mvc?
System.Threading.Tasks.Task.Run(() =>
{
   var smtp = new SmtpClient();
   smtpClient.SendMailAsync(message);
}

Answer: Edit:
Só seguir o exemplo:
public async Task SendEmail(string toEmailAddress, string emailSubject, string emailMessage)
{
    var message = new MailMessage();
    message.To.Add(toEmailAddress);

    message.Subject = emailSubject;
    message.Body = emailMessage;

    using (var smtpClient = new SmtpClient())
    {
        await smtpClient.SendMailAsync(message);
    }
}

Comment: Eu já tenho uma classe genérica, meu problema é que não faz envio de forma assíncrona.
Comment: então coloque o método de envio de e-mail de maneira genérica na sua aplicação também, mude ele conforme a sua necessidade (provavelmente vai precisar mudar o model que eu criei) e chame em seu controller (ou na parte correta da sua aplicação) que vai funcionar
Comment: editei minha resposta pra ficar de uma maneira mais simplificada
Answer: Tente com o seguinte código:
public async Task<ActionResult> MyAcation()
{
    //Codigo de criacao do objeto message
    Task.Factory.StartNew(() =>
    {
       var smtp = new SmtpClient();
       smtp.SendMailAsync(message);
    });
    return View();
}

Comment: Eu uso o `Task.Factory.StartNew` em meus projetos para fazer esse tipo de envio de e-mail(enviar e não aguardar confirmação) quanto as perdas, eu nunca tive problemas, porém não sei te responder se podem ocorrer, **Acredito(não tenho certeza)** que só ocorra falha caso tenha uma exceção, você pode tentar salvar um log ou algo do gênero.
Comment: Funcionou assim Leonardo, será que sempre é entregue de forma correta? Ou pode ocorrer perdas? Talvez para segurança eu deveria criar uma fila de menssageria para processar as mensagens?
Answer: você não precisa criar uma nova Task com o Task.Run ou o Task.Factory.StartNew, afinal o smtp.SendMailAsync já retorna uma Task.
Tudo o que você precisa fazer (ou melhor, não fazer), é não esperar pelo retorno dela, ou seja, não usar o await.
public async Task<ActionResult> MyAcation()
{
    var smtp = new SmtpClient();
    smtp.SendMailAsync(message);
    return View();
}


Equation $Q=kH^n$

Question: Hello i have a maths problem i am trying to solve. I have nearly completed it. I am just stuck on the last bit, and looking for some help.
My Question:
Two quantities Q and H are believed to be related by the equation $Q= kH^n$.
The values obtained for Q and H shown in the table below were obtained during an experiment.
Q
0.16
0.20
0.27
0.34
0.40
0.47
0.55
H
1.14
1.78
3.24
5.14
7.11
9.82
13.44
Plotting the values of Q and H using graph paper or computer graphing software show the relationship between Q and H and determine;
a. the gradient of the curve from your graph,
b. the law connecting Q and H, expressing the law that you have determined in the form of an equation.
So far i have drawn the graph and plotted all the points. I got the points like this:
$Q = KH^n$
$Y = ax^n$
$Log (y) = Log (ax)$
$Log (y) = Log (a) + Log(xn)$
$Log (y) = Log (a) + nLog (x)$
$Log (y) = Log (a) + nLog (x)$
[ y ]           [ c ]         [ x ]
1:
Log (0.16) = -0.796
Log (1.14) = 0.0569
2:
Log (0.20) = -0.699
Log (1.78) = 0.250
ETC..
I am now stuck on finding the graidient, and connection law. I know n is the graidient, just not how to find it.
Is the connecting law Logarithms?
Any help much appreciated, been stuck on this for a long time.
Comment: *gradient*, not *graidient*.
Answer: On a bilogarithmic plot, you expect a straight line,
$$\log Q=n\log H+\log k.$$ This is indeed what you observe.

As the alignment is excellent, you can simply use the two extreme points.
Then
$$n=\frac{\log Q_7-\log Q_1}{\log H_7-\log H_1}$$ and $\log k$ follows.
Comment: So i did $n=\frac{\ 0.259 - 0.796}{\ 1.128 - 0.0569}$. $n = 0.501$ .So the Gradient is 0.501
Comment: Or is the Gradient $-0.537$ in $Q$. $1.0711$ in $H$?
Comment: @KyleAnderson: no idea how you obtain this.
Comment: I obtained it by places the values in the equation you gave me. What have i done wrong?
Comment: @KyleAnderson Can't make sense of "Or is the Gradient −0.537 in Q 1.0711 in H?" Take $n=0.5$.
Comment: $LogQ7 - LogQ1 = -0.537$ $Log H7 = Log H1 = 1.0711$ Thats how i got them. I guess this is wrong. So does $n = 0.501$?

Equation $Q=kH^n$


Signed sum over labeled connected graphs

Question: Let $\binom{n}{2}$ be the set of all subsets of $\{1,2,3, \ldots, n\}$ of size $2$ and let $C_n$ be the set of $E \subseteq C_n$ so that the graph $G$ with vertex set $\{1,2, 3, \ldots, n\}$ and edge set $E$ is connected.  Using generating function methods one can show that $$\sum_{E \in C_n} (-1)^{|E|} = (-1)^{n-1}(n-1)!.$$
For example, if $n=3$ then $$C_n = \{\{12,23\}, \{12, 13\}, \{13, 23\}, \{12, 13, 23\} \}$$ and then $$(-1)^2 + (-1)^2 + (-1)^2 + (-1)^3 = 2!.$$
Is there a more direct proof?  For example, a sign-reversing involution argument.
Answer: The claim holds for $n=1$. Assume that it holds for $n-1$. Then the graphs in which $n$ has exactly one edge and the rest of the graph is connected yield the result. The graphs in which $n$ has at least two edges, say to $u$ and $v$, come in groups of $2$, with or without the edge $uv$, and thus cancel.
Comment: Nice!  To elaborate a little: there are $n-1$ choices for where to connect $n$ to, so by the induction hypothesis the sum is $(-1)(n-1) \cdot (-1)^{n-1} (n-2)! = (-1)^{n-1}(n-1)!$ over the first set you describe.


Can't uninstall forum module

Question: my core forum module installation gone wrong on a drupal 8.5.1 system and now, when I want to uninstall it I get:
    $ drush pmu --verbose forum
    Executing: mysql --defaults-extra-file=/tmp/drush_R3Uhpd --database=drupal_2 --host=localhost --port=3306 --silent  < /tmp/drush_enDNb4
    Executing: mysql --defaults-extra-file=/tmp/drush_OWoaeC --database=drupal_2 --host=localhost --port=3306 --silent  < /tmp/drush_3gNq9b
    The following extensions will be uninstalled: forum
    Do you really want to continue? (y/n): y
    array_flip(): Can only flip STRING and INTEGER values! EntityStorageBase.php:227                                                                                [warning]
    TypeError: Argument 1 passed to Drupal\forum\ForumUninstallValidator::hasTermsForVocabulary() must implement interface Drupal\taxonomy\VocabularyInterface, null given, called in                   [error]
    /usr/local/www/drupal2/core/modules/forum/src/ForumUninstallValidator.php on line 61 in Drupal\forum\ForumUninstallValidator->hasTermsForVocabulary() (line 103 of
    /usr/local/www/drupal2/core/modules/forum/src/ForumUninstallValidator.php)
    #0 /usr/local/www/drupal2/core/modules/forum/src/ForumUninstallValidator.php(61): Drupal\forum\ForumUninstallValidator->hasTermsForVocabulary(NULL)
    #1 /usr/local/www/drupal2/core/lib/Drupal/Core/Extension/ModuleInstaller.php(560): Drupal\forum\ForumUninstallValidator->validate('forum')
    #2 /usr/local/www/drupal2/core/lib/Drupal/Core/Extension/ModuleInstaller.php(365): Drupal\Core\Extension\ModuleInstaller->validateUninstall(Array)
    #3 /usr/local/www/drupal2/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(91): Drupal\Core\Extension\ModuleInstaller->uninstall(Array, true)
    #4 /vendor/drush/drush/commands/core/drupal/environment.inc(227): Drupal\Core\ProxyClass\Extension\ModuleInstaller->uninstall(Array)
    #5 /vendor/drush/drush/commands/core/drupal/pm_8.inc(79): drush_module_uninstall(Array)
    #6 /vendor/drush/drush/commands/pm/pm.drush.inc(1250): _drush_pm_uninstall(Array)
    #7 /vendor/drush/drush/includes/command.inc(422): drush_pm_uninstall('forum')
    #8 /vendor/drush/drush/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
    #9 /vendor/drush/drush/includes/command.inc(199): drush_command('forum')
    #10 /vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
    #11 /vendor/drush/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
    #12 /vendor/drush/drush/drush.php(12): drush_main()
    #13 {main}.
    TypeError: Argument 1 passed to Drupal\forum\ForumUninstallValidator::hasTermsForVocabulary() must implement interface Drupal\taxonomy\VocabularyInterface, null given, called in /usr/local/www/drupal2/core/modules/forum/src/ForumUninstallValidator.php on line 61 in /usr/local/www/drupal2/core/modules/forum/src/ForumUninstallValidator.php on line 103 #0 /usr/local/www/drupal2/core/modules/forum/src/ForumUninstallValidator.php(61): Drupal\forum\ForumUninstallValidator->hasTermsForVocabulary(NULL)
    #1 /usr/local/www/drupal2/core/lib/Drupal/Core/Extension/ModuleInstaller.php(560): Drupal\forum\ForumUninstallValidator->validate('forum')
    #2 /usr/local/www/drupal2/core/lib/Drupal/Core/Extension/ModuleInstaller.php(365): Drupal\Core\Extension\ModuleInstaller->validateUninstall(Array)
    #3 /usr/local/www/drupal2/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(91): Drupal\Core\Extension\ModuleInstaller->uninstall(Array, true)
    #4 /vendor/drush/drush/commands/core/drupal/environment.inc(227): Drupal\Core\ProxyClass\Extension\ModuleInstaller->uninstall(Array)
    #5 /vendor/drush/drush/commands/core/drupal/pm_8.inc(79): drush_module_uninstall(Array)
    #6 /vendor/drush/drush/commands/pm/pm.drush.inc(1250): _drush_pm_uninstall(Array)
    #7 /vendor/drush/drush/includes/command.inc(422): drush_pm_uninstall('forum')
    #8 /vendor/drush/drush/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
    #9 /vendor/drush/drush/includes/command.inc(199): drush_command('forum')
    #10 /vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
    #11 /vendor/drush/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
    #12 /vendor/drush/drush/drush.php(12): drush_main()
    #13 {main}
    TypeError: Argument 1 passed to Drupal\forum\ForumUninstallValidator::hasTermsForVocabulary() must implement interface Drupal\taxonomy\VocabularyInterface, null given, called in /usr/local/www/drupal2/core/modules/forum/src/ForumUninstallValidator.php on line 61 in Drupal\forum\ForumUninstallValidator->hasTermsForVocabulary() (line 103 of /usr/local/www/drupal2/core/modules/forum/src/ForumUninstallValidator.php).
    Drush command terminated abnormally due to an unrecoverable error.                                                                                [error]
    A non well formed numeric value encountered drush.inc:1671

How can I uninstall this module, because this problem leads to crash on the admin/modules/uninstall page:
The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\forum\ForumUninstallValidator::hasTermsForVocabulary() must implement interface Drupal\taxonomy\VocabularyInterface, null given, called in /usr/local/www/drupal2/core/modules/forum/src/ForumUninstallValidator.php on line 61 in Drupal\forum\ForumUninstallValidator->hasTermsForVocabulary() (line 103 of core/modules/forum/src/ForumUninstallValidator.php).

My server config:
Apache/2.4.29 (FreeBSD) OpenSSL/1.0.1u-freebsd PHP/7.1.14
PHP Ver. 7.1.14
DB MySQL Ver. 5.6.37
EDIT:
I forgot to mention, that admin/structure/forum gives me this:
Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 227 of /usr/local/www/drupal2/core/lib/Drupal/Core/Entity/EntityStorageBase.php)
#0 /usr/local/www/drupal2/core/includes/bootstrap.inc(582): _drupal_error_handler_real(2, 'array_flip(): C...', '/usr/local/www/...', 227, Array)
#1 [internal function]: _drupal_error_handler(2, 'array_flip(): C...', '/usr/local/www/...', 227, Array)
#2 /usr/local/www/drupal2/core/lib/Drupal/Core/Entity/EntityStorageBase.php(227): array_flip(Array)
#3 /usr/local/www/drupal2/core/lib/Drupal/Core/Entity/EntityStorageBase.php(212): Drupal\Core\Entity\EntityStorageBase->loadMultiple(Array)
#4 /usr/local/www/drupal2/core/modules/forum/src/Form/Overview.php(54): Drupal\Core\Entity\EntityStorageBase->load(NULL)
#5 [internal function]: Drupal\forum\Form\Overview->buildForm(Array, Object(Drupal\Core\Form\FormState), NULL)
#6 /usr/local/www/drupal2/core/lib/Drupal/Core/Form/FormBuilder.php(514): call_user_func_array(Array, Array)
#7 /usr/local/www/drupal2/core/lib/Drupal/Core/Form/FormBuilder.php(271): Drupal\Core\Form\FormBuilder->retrieveForm('forum_overview', Object(Drupal\Core\Form\FormState))
#8 /usr/local/www/drupal2/core/lib/Drupal/Core/Controller/FormController.php(74): Drupal\Core\Form\FormBuilder->buildForm('forum_overview', Object(Drupal\Core\Form\FormState))
#9 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#10 /usr/local/www/drupal2/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#11 /usr/local/www/drupal2/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#12 /usr/local/www/drupal2/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#13 /usr/local/www/drupal2/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#14 /usr/local/www/drupal2/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#15 /usr/local/www/drupal2/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#16 /usr/local/www/drupal2/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /usr/local/www/drupal2/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /usr/local/www/drupal2/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /usr/local/www/drupal2/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /usr/local/www/drupal2/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /usr/local/www/drupal2/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /usr/local/www/drupal2/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /usr/local/www/drupal2/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /usr/local/www/drupal2/core/lib/Drupal/Core/DrupalKernel.php(664): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /usr/local/www/drupal2/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#26 {main}.

Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 227 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).

Page not found.

THX
Comment: My guess would be when you enabled the forum module it created some taxonomy vocabularies and terms and you deleted them manually before doing the uninstall and the uninstall is trying to delete them but they no longer exist
Comment: I did not deleted anything. Like I sad...the web UI instalation of the forum modeule crashed. Then I did a composer/drush based reinstall of the geocoder module and then I found that the crashed forum install is blocking the admin/modules/uninstall feature.
Answer: Just re-create Forums vocabulary and then you should be able able to uninstall the module.
Comment: But how to do that? Is there some sql scritp to create the missing vocabulary?
Comment: Please read https://www.drupal.org/docs/user_guide/en/structure-taxonomy-setup.html to learn how to create taxonomy vocabularies.
Comment: admin/structure/taxonomy/add gives me this:
`Drupal\Core\Entity\EntityMalformedException: The entity does not have an ID. in Drupal\Core\Config\Entity\ConfigEntityStorage->save() (line 248 of /usr/local/www/drupal2/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php).`
Answer: You can temporally edit core/modules/forum/src/ForumUninstallValidator.php like that:
  /**
   * Determines if there are any taxonomy terms for a specified vocabulary.
   *
   * @param \Drupal\taxonomy\VocabularyInterface $vocabulary
   *   The vocabulary to check for terms.
   *
   * @return bool
   *   TRUE if there are terms for this vocabulary, FALSE otherwise.
   */
  protected function hasTermsForVocabulary(VocabularyInterface $vocabulary = NULL) {
    return FALSE;
    $terms = $this->entityTypeManager->getStorage('taxonomy_term')->getQuery()
      ->condition('vid', $vocabulary->id())
      ->accessCheck(FALSE)
      ->range(0, 1)
      ->execute();
    return !empty($terms);
  }

This way you will be able to uninstall the module. Then don't forget to rollback your changes!
Answer: The following fixed it and I suspect it's because of some bug in the Devel module (in my case) when generating Forum contents without having a Forums vocabulary :

Created a "Forums" vocabulary at  /admin/structure/taxonomy/add
Going back to /admin/modules/uninstall no more error but the Forum checkbox is disabled and has this message :

The following reason prevents Forum from being uninstalled:

To uninstall Forum, first delete all Forum content

At content admin admin/content?title=&type=forum&status=All&langcode=All delete all forum type content. (I had it generated by the Devel module).
Now going back to Modules > Uninstall  the forum checkbox is enabled and uninstallable.
Comment: This exact step fixed my issue.  BUT,,, I used drush for uninstalling this instead of the Extend -> Uninstall Module Route
Answer: try checking your db first:
select * from public.node__taxonomy_forums
select * from public.taxonomy_term_revision__forum_container;
I found 3 terms in taxonomy_term_revision__forum_container that I did not know about. Once these were deleted I was able to successfully uninstall Forum.
drush pmu forum

Can't uninstall forum module


Explain the xkcd jelly bean comic: What makes it funny?

Question: I see that one time out of the twenty total tests they run, $p < 0.05$, so they wrongly assume that during one of the twenty tests, the result is significant ($0.05 = 1/20$).
xkcd jelly bean comic - "Significant"

Title: Significant
Hover text: "'So, uh, we did the green study again and got no link. It was probably a--' 'RESEARCH CONFLICTED ON GREEN JELLY BEAN/ACNE LINK; MORE STUDY RECOMMENDED!'"
Comment: Who said it's funny?
Comment: 95% confidence will mean that on average in 5% of experiments (one out of 20) we'll get an opposite conclusion. Which is exactly what has happened here. I.e., if you also make the same experiment with orange jelly beans 1000 times, ~ 50 of those will give positive result. :)
Comment: See also [this discussion on explainxkcd.com](http://www.explainxkcd.com/wiki/index.php?title=882:_Significant)
Comment: @Glen_b, the favorite data analysis cartoon thread is appropriately CW, however, I see no reason this one should be. 'Why funny' aside, the question asks for an understanding of the statistical point at issue in the cartoon, which has an answer & should be on-topic & not-CW (& which I think you handled well below).
Comment: [Myself, besides the other 59 voters here](http://stats.stackexchange.com/a/9254/32036), so its $\text{funniness}>0$ at least! ;-P (This comment definitely doesn't represent my opinion of XKCD in general.) Unless there's such a thing as $\text{funniness}<0$, in which case we'd probably want better data. Nobody's downvoted it yet though, FWIW as an available operationalization of "negative funniness"...and with that, I've probably taken this comment into negative funniness territory $(p<.05)$...
Comment: Is this a candidate for CW, perhaps?
Comment: This cartoon also appeared in [What is your favorite "data analysis" cartoon?](http://stats.stackexchange.com/questions/423/what-is-your-favorite-data-analysis-cartoon)
Comment: @gung yes, I think I agree.  I was worried about the opinion involved in the humor part, but as I came to answer it, it became less of a concern
Comment: If someone has to explain the joke it makes the joke not funny anymore.
Comment: @Nick I was implicitly trusting this community to recognize a tongue-in-cheek comment.
Comment: Of course; despite appearances, I recognized it too :) As a somewhat self-indulgent psychologist with professional interest in operationalizing abstract constructs, I tend to brandish [Maslow's hammer](http://en.wiktionary.org/wiki/if_all_you_have_is_a_hammer,_everything_looks_like_a_nail) overzealously.
Comment: @MDMoore313 - hardly. In college, I had a classmate who was brilliant, and had a unique sense of humor. I set a goal to make a joke in class only he would understand. I found my chance, and was successful. He laughed, no one else did, and I explained it all after class. I forget the joke, but as long as one person found it funny.
Comment: @JoeTaxpayer after you explained the joke, did the rest of the class find it funny? did you still find it *as* funny?
Comment: @MDMoore313 - They understood how the genius found it funny. Humor is one of those things that's not always universal. I was born/raised in NYC. When I saw a Woody Allen movie in Texas with a NYC friend, we laughed at times no one else did, and vice versa. Some overlap, but not 100%. There are jokes about parking and/or traffic that aren't universal.
Answer: Humor is a very personal thing - some people will find it amusing, but it may not be funny to everyone - and attempts to explain what makes something funny often fail to convey the funny, even if they explain the underlying point. Indeed not all xkcd's are even intended to be actually funny. Many do, however make important points in a way that's thought provoking, and at least sometimes they're amusing while doing that. (I personally find it funny, but I find it hard to clearly explain what, exactly, makes it funny to me. I think partly it's the recognition of the way that a doubtful, or even dubious result turns into a media circus (on which see also this PhD comic), and perhaps partly the recognition of the way some research may actually be done - if usually not consciously.)
However, one can appreciate the point whether or not it tickles your funnybone.
The point is about doing multiple hypothesis tests at some moderate significance level like 5%, and then publicizing the one that came out significant. Of course, if you do 20 such tests when there's really nothing of any importance going on, the expected number of those tests to give a significant result is 1. Doing a rough in-head approximation for $n$ tests at significance level $\frac{1}{n}$, there's roughly a 37% chance of no significant result, roughly 37% chance of one and roughly 26% chance of more than one (I just checked the exact answers; they're close enough to that).
In the comic, Randall depicted 20 tests, so this is no doubt his point (that you expect to get one significant even when there's nothing going on). The fictional newspaper article even emphasizes the problem with the subhead "Only 5% chance of coincidence!". (If the one test that ended up in the papers was the only one done, that might be the case.)

Of course, there's also the subtler issue that an individual researcher may behave much more reasonably, but the problem of rampant publicizing of false positives still occurs. Let's say that these researchers only do 5 tests, each at the 1% level, so their overall chance of discovering a bogus result like that is only about five percent.
So far so good. But now imagine there are 20 such research groups, each testing whichever random subset of colors they think they have reason to try. Or 100 research groups... what chance of a headline like the one in the comic now?
So more broadly, the comic may be referencing publication bias more generally. If only significant results are trumpeted, we won't hear about the dozens of groups that found nothing for green jellybeans, only the one that did.
Indeed, that's one of the major points being made in this article, which has been in the news in the last few months (e.g. here, even though it's a 2005 article).
A response to that article emphasizes the need for replication. Note that if there were to be several replications of the study that was published, the "Green jellybeans linked to acne" result would be very unlikely to stand.
(And indeed, the hover text for the comic makes a clever reference to the same point.)
Answer: The effect of hypothesis testing on the decision to publish has been described more than fifty years ago in the 1959 JASA paper Publication Decisions and Their Possible Effects on Inferences Drawn from Tests of Significance - or Vice Versa (sorry for the paywall).
Overview of the Paper
The paper points out evidence that published results of scientific
papers are not a representative sample of results from all studies. The
author reviewed papers published in four major psychology journals. 97%
of the reviewed papers reported statistically significant outcomes for
their major scientific hypotheses.
The author advances a possible explanation for this observation : that
research which yields nonsignificant results is not published. Such
research being unknown to other investigators may be repeated
independently until eventually by chance a significant result occurs (a
Type 1 error) and is published. This opens the door to the possibility
that the published scientific literature may include a
over-representation of incorrect results resulting from Type 1 errors in
statistical significance tests - exactly the scenario that the original
XKCD comic was poking fun at.
This general observation has been subsequently verified and re-discovered
may times in the intervening years. I believe that the 1959 JASA paper
was the first to advance the hypothesis. The author of that paper was
my PhD supervisor. We updated his 1959 paper 35 years later and reached
the same conclusions. Publication Decisions Revisited: The Effect of the
Outcome of Statistical Tests on the Decision to Publish and Vice Versa.
American Statistician, Vol 49, No 1, Feb 1995
Comment: Sure - I edited my reply above to include an overview of the paper.
Comment: Related:   https://en.wikipedia.org/wiki/Half-life_of_knowledge
Answer: What people overlook is that the actual p-value for the green jelly bean case is not .05 but around .64. Only the pretend (nominal) p-value is .05. There's a difference between actual and pretend p-values. The probability of finding 1 in 20 that reach the nominal level even if all the nulls are true is NOT .05, but .64. On the other hand, if you appraise evidence looking at comparative likelihoods—the most popular view aside from the error statistical one (within which p-values reside) you WILL say there's evidence for H: green jelly beans are genuinely correlated with acne. That's because P(x;no effect) < P(x; H). The left side is < .05, whereas the right side is fairly high: if green jelly beans did cause acne then finding the observed association would be probable. Likelihoods alone fail to pick up on error probabilities because they condition on the actual data attained. There's no difference in the appraisal than if there had just been this one test of the green jelly beans and acne. So although this cartoon is often seen as making fun of p-values, the very thing that's funny about it demonstrates why we need to consider the overall error probability (as non-pretend p values do) and not merely likelihoods. Bayesian inference is also conditioned on the outcome, ignoring error probabilities. The only way to avoid finding evidence for H, for a Bayesian would be to have a low prior in H. But we would adjust the p-value no matter what the subject matter, and without relying on priors, because of the hunting procedure used to find the hypothesis to test. Even if the H that was hunted was believable, it's still a lousy test. Errorstatistics.com
Comment: It is very hard to tell exactly what this post is trying to say.  Let me focus on one part of it, hoping that a clarification might reveal the meaning of the rest: exactly what do you mean by "the overall error probability"?
Comment: @whuber I believe that the post is referring to the multiple comparisons problem.