Solr4 installation with Jetty

Question: I am trying to install Solr4 latest and want to run it with Jetty (servlet container).
JAVA_HOME=/usr/lib/jvm/jre
JAVA_OPTIONS="-Dsolr.solr.home=/opt/solr $JAVA_OPTIONS"
JETTY_HOME=/opt/solr
JETTY_USER=solr
JETTY_LOGS=/opt/solr/logs
JETTY_ARGS=/opt/solr/etc/jetty-plus.xml

I download jetty init script from LINK
I added it chkconfig. Issue which I facing is that when I start jetty it is not getting started.  I followed the instructions provided on URL but nothing seems to be working.
netstat output
[root@localhost ~]# netstat -tlnp | grep 8983
[root@localhost ~]#

Nothing comes up in log file too I checked syslog as well as log defined in jetty too.
However when i run service jetty supervise it works and I can see the jetty is listening on port 8080. But its not getting started with init script.
Any clue what I have missed here, or let me know if any more infor is required from my end.
Aditional Info
java -version
java version "1.7.0_65"

cat /etc/issue
Amazon Linux AMI release 2014.03
Kernel \r on an \m

Solr 4.10
jetty-distribution-9.2.3.v20140905

EDITED
set -x
/etc/init.d/jetty restart
+ /etc/init.d/jetty restart
Stopping Jetty: OK
Starting Jetty: STARTED Jetty Thu Sep 18 18:07:27 UTC 2014
++ printf '\033]0;%s@%s:%s\007' root localhost '~'

Comment: Can you add at init script start the following `set -x` and post the output ?
Comment: I have provided the URL for init script which I am using its given by solr I will add the set -x output now
Comment: @Pierre-Yves Gillier :I have updated as you asked
Answer: Changing to bash shell should work for you. It seems that you have messed with installation
Let me give you steps to do it which worked for me:
I downloaded solr4.10.1 .
cd /tmp
wget http://apache.arvixe.com/lucene/solr/4.10.1/solr-4.10.1.tgz
tar -xzf solr-4.10.1.tgz

As you have messed up the installation I would suggest to take backup if you want and delete /opt/solr and do the following
cp -rf /tmp/solr-4.10.1/example /opt/solr

Adduser solr if not added
useradd -d /opt/solr -s /sbin/false solr
chown solr:solr -R /opt/solr

From Apache link
NOTE: If you don't have start-stop-daemon tool you have to setup /bin/bash instead /sbin/false.

Create default jetty file as below :
JAVA_HOME=/usr/lib/jvm/jre
JAVA_OPTIONS="-Dsolr.solr.home=/opt/solr/solr $JAVA_OPTIONS"
JETTY_HOME=/opt/solr
JETTY_USER=solr
JETTY_LOGS=/opt/solr/logs

NOTE: If you notice JAVA_OPTIONS in your default jetty file I have changed it to /opt/solr/solr do the same. Let other thing remain same.
Create /opt/solr/etc/jetty-logging.xml as Provided on link
Now download jetty 7 init script
wget https://raw.githubusercontent.com/eclipse/jetty.project/master/jetty-distribution/src/main/resources/bin/jetty.sh

cp jetty.sh /etc/init.d/jetty
chmod 755 /etc/init.d/jetty
chkconfig jetty on

So far we did single Solr installation with single core (collection1) , now start solr service and check if it is running and listening on default port
service jetty start

Go to your URL and http://IP:8983/solr and it should work fine for you.
Now we will go for Multicore setup
Move the folder /opt/solr/solr to /opt/solr/solr-bkp or delete it .
mv /opt/solr/solr /opt/solr/solr-bkp

Move the multicore folder as  /opt/solr/solr
mv /opt/solr/multicore /opt/solr/solr

And you are done other details you can follow from the document  SolrJetty
Hope this will help you.
Comment: Thanks for detailed steps .. Let me try this as well and will get back to you.
Answer: Not sure if you've resolved this, but having gone through the same trouble, the fix for me was setting the shell for the solr user to /bin/bash instead of /bin/false.
Comment: No that did not work for me :( `grep solr /etc/passwd
solr:x:501:502::/opt/solr:/bin/bash`

Solr4 installation with Jetty


Why are values in Entites obtained directly and sometimes by using getters?

Question: For example

Drupal\Core\Entity\Entity::id() returns $this->id(or NULL)
Drupal\Core\Entity\ContentEntityBase::id() returns $this->id->value
Drupal\Core\Entity\ContentEntityBase::uuid() returns $this->get('uuid')->value
Drupal\node\Entity\Node::id() returns $this->get('nid')->value

Also in some methods there are setValue() and getValue() utilised but sometimes there are just $this->field->value.
So what is the reason for this inconsistent behavior? From my understanding all the "fields" are TypedData fields hence the setValue() and getValue() methods should be used instead of directly access $this->field->value. Besides it's strange because $value is private.
Comment: My findings:
$this->entity_id->getValue() returns array
$this->entity_id->value returns string
$this->get('entity_id')->value returns string
Comment: http://drupal.stackexchange.com/questions/85351/entityng-when-to-use-methods-get-and-magic-offset?rq=1 earlier question
Answer: Ok, trying to answer this. This could get a bit long :)
First, to have that out of the way, Drupal\Core\Entity\Entity::id() is not TypedData relevant, only content entities (subclasses for ContentEntityBase) are typed data at the moment. So that implementation is for example used for config entities.
Now about the different methods that you mentioned.

getValue() is part of TypedDataInterface and it's not strictly defined what it returns, but it can be understood as the raw value of that typed data object. For anything that is not a so called primitive value (like a string or integer), getValue() returns an array. So if you call getValue() on the first field item of the node body ($node->body[0]), it will return array('value' => ..., 'format' => 'text_plain'). If you call it on the field item list, you get array(0 => array('value' => ..., 'format' => 'text_plain')). So for all complex data (another typed data term, it defines an objects that consists of sub-properties, like an entity or field item), think of getValue() as toArray().
Content entities no longer have public class properties. $entity->id->value goes through $entity->__get('id')->value, which is almost identical to $entity->get('id')->value, with the following differences:

get() currently only supports defined fields. _get()/_set() allow to set anything on an entity, mostly due to BC reasons, because a lot of code still sets tons of random stuff on $node. So print $node->bla works, $node->get('bla') will throw an InvalidArgumentException('Field bla is unknown.'). This could be changed if we want to.
Before PHP 5.4, $node->get('body')[1] is not supported (while $node->body1 works fine), so you have to use the rather weird $node->get('body')->offsetGet(1) (this is ArrayAccess, #2110467: Add first(), get($index) and possibly other methods to ListInterface will hopefully soon change that to a $node->get('body')->get(1)). Now that D8 will require 5.4, this isn't much of an argument anymore and the referenced issue makes it easier too.
get() is faster than __get(). On the large scale, there's not a big difference I think (other things are worse), but relatively speaking are magic method calls considerably slower than non-magic ones.

The ->value part involves more magic methods. To explain that, I first have to mention that all entity fields (including base fields like the ID) now have a fixed structure enforced: Entity : Field item list : Field item : Field properties (like value, format, target_id). If you write $entity->id->value then ContentEntityBase::__get() gives you the field item list for the id field. Then you call $field_item_list->value, which points to FieldItemList::__get() which assumes that you want to access the first field item, so it passes the call through to FieldItemBase::__get(), which then returns the value. I suggest that's enough detail for that question, if you want to know more about FieldItemBase, I'm happy to answer that in a separate question.
Now, $entity->id->getValue() and $entity->id->value are often mixed up, but they are not actually related in any way, it's just an unfortunate naming conflict. value happens to be the pseudo-standard main field property name, especially for those that only have a single value. Reference fields use target_id, and if you want to name the property of your own field type banana , then all you have to do is set it up accordingly in your FieldTypeItem::getPropertyDefinitions() implementation and it will be $entity->your_field->banana.
There are (at least) two remaining issues that will affect these API's. That is #2002134: Move TypedData metadata introspection from data objects to definition objects and #2002138: Use adapters for supporting typed data. The main goal of those combined is that entities and field items are no longer typed data objects themself but can be used as typed data through adapter classes. That in turn means that those classes do not have to respect (and poorly implement in case of entities) the TypedDataInterface/ComplexDataInterface interfaces but can define method names that make more sense in their context. For example, we can hopefully rename getValue() to toArray() or something else that has no naming conflict with value, we can rename $entity->getPropertyDefinitions() to $entity->getFieldDefinitions() and so on.

So, to come back to what your actual (I think) question is, $entity->id->value and $entity->get('id)->value are almost identical, both are currently supported, but I usually prefer and recommend get(). __get() could still change (although I consider it unlikely, as nobody is pushing there), so if you use get(), you're on the safe side I think.
Comment: @Serpiente BC = Backwards Compatible
Comment: what does BC reasons mean?


Creating an async method which throws an exception after a specified amount of time unless a certain condition is met outside of that function

Question: I am currently working on a Ruby script which is supposed to perform different tasks on a pretty long list of hosts. I am using the net-ssh gem for connectivity with those hosts. The thing is, there seem to exist some conditions under which net-ssh times out without throwing an exception. As of know, the script was only once able to finish a run. Most of the time, the scripts just hangs at some point without ever throwing an exception or doing anything.
I thought about running all tasks that may timeout in different threads, passing them a pointer to some variable they can change when the tasks finished successfully, and then check that variable for a given amount of time. If the task has not finished by then, throw an exception in the main thread that I can catch somewhere.
This is the first time I am writing something in Ruby. To give a clear demonstration of what I want to accomplish, this is what I'd do in C++:
    void perform_long_running_task(bool* finished);
    void start_task_and_throw_on_timeout(int secs, std::function<void(bool*)> func);
    int seconds_to_wait {5};
    int seconds_task_takes{6};

    int main() {
        start_task_and_throw_on_timeout(seconds_to_wait, &perform_long_running_task);
        // do other stuff
        return 0;
    }

    void perform_long_running_task(bool* finished){
        // Do something that may possible timeout..
        std::this_thread::sleep_for(std::chrono::seconds(seconds_task_takes));

        // Finished..
        *finished = true;
    }

    void start_task_and_throw_on_timeout(int secs, std::function<void(bool*)> func){
        bool finished {false};
        std::thread task(func, &finished);

        while (secs > 0){
            std::this_thread::sleep_for(std::chrono::seconds(1));
            secs--;
            if (finished){
                task.join();
                return;
            }
        }

        throw std::exception();
    }

Here, when 'seconds_task_takes' is bigger than 'seconds_to_wait', an exception is thrown in the main thread. If the task finishes in time, everything goes on smoothly.
However, I need to write my piece of software in a dynamic scripting language that can run anywhere and needs not to be compiled. I would be super glad for any advice about how I could write something like the code above in Ruby.
Thanks alot in advance :)
edit: in the example ,I added a std::function parameter to start_task_and_throw_timeout so it's reusable for all similar functions
Answer: I think module timeout has everything you need to do. It allows you to run the block for a while and raise an exception if it was not fast enough.
Here is a code example:
require "timeout"

def run(name)
  puts "Running the job #{name}"
  sleep(10)
end

begin
  Timeout::timeout(5) { run("hard") }
rescue Timeout::Error
  puts "Failed!"
end

You can play with it here: https://repl.it/repls/CraftyUnluckyCore. The documentation for the module lives here: https://ruby-doc.org/stdlib-2.5.1/libdoc/timeout/rdoc/Timeout.html. Notice that you can customize not only the timeout, but also error class and message, so different jobs may have different kinds of errors.
Comment: Note that `Timeout` can be very dangerous with many cases of undefined behavior. I would not rely on it in production unless you dig into its internals and really understand how it's dealing with thread interruption. Ideally, your long running tasks use libraries that have already meticulously tested that for you (e.g. `Net::HTTP`'s `read_timeout` option); you should much prefer using those native options instead. Otherwise, you need to dig into the `timeout` internals to make sure your code actually runs as intended. Cf: https://medium.com/@adamhooper/in-ruby-dont-use-timeout-77d9d4e5a001
Comment: > However, I need to write my piece of software in a dynamic scripting language that can run anywhere and needs not to be compiled. I would be super glad for any advice about how I could write something like the code above in Ruby. --- If you have a choice of tools, I would also point out that Ruby does single threaded scripting very well, but concurrency has always been a weakness for it. I'd point you to NodeJS if you can use single threaded async behavior instead. If you're looking for something that's similar to Ruby syntax-wise, Elixir works interactively, though still needs compilation.


Tell Jenkins to run a specific project on a particular slave node

Question: How do I tell Jenkins to run a specific project on a particular slave?
I've set up a Jenkins master node, and a slave node that I want to use for staging an application. But I can't figure out how to configure the project to run on the slave node I created.
Comment: http://stackoverflow.com/questions/9214501/jenkins-running-a-single-job-in-master-as-well-as-slave
Answer: Set the "Restrict where this job can be run" check box in your job configuration and specify the name of your slave.
If you add more slaves later, you can set labels for each slave and specify those in your job configs.
See this reference documentation:

https://wiki.jenkins-ci.org/display/JENKINS/Distributed+builds
Comment: Thanks. I used quite a while before found your answer. It should have added to this page https://wiki.jenkins-ci.org/display/JENKINS/Distributed+builds
Answer: If you are running a Pipeline job, you first want to add a label (e.g. 'slave') to the slave node (or agent as it seems to be called now).
Then, in the pipeline script, you specify the label the job runs on:
Declarative pipeline:
pipeline {
    agent {label 'slave'}
    stages {
        ...
    }
}

Scripted pipeline:
node (label: 'slave') {
    ...
}

This job will now run on any node with the label 'slave'.  If you only want the job to run on this particular slave, don't reuse the label.  And of course the label doesn't have to be 'slave'; it can be whatever you want.
Update:
In the scripted pipeline, if your node is named "My Node", you can also do this:
node ('My Node') {
    ...
}

If you only want the code block to run on that particular node, this is useful.  However, using labels is more flexible, and can make it easier to add nodes to share the workload.
Comment: This was so hard to find, the documentation for scripted syntax is dying in favour of declarative, I cannot migrate yet so thank you!
Answer: If you want to use Node/Label as a parameter then install NodeLabel Parameter Plugin
Comment: Note that if choose "Node" parameter for a job and you want to call it from Groovy then you need to create a special parameter: `params += new org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterValue('testServer', testServerLabel);` (instead of the usual `StringParameterValue`).
Comment: @Nux I can't know for sure because, well, "crisis adverted", but I'm assuming seeing your comment saved me hours of headache. Thanks!
Answer: Easy way to do this issue.
pipeline {
agent {label 'node1'}

stages {
    stage('Hello') {
        steps {
            echo 'Hello World'
        }
    }
}

}


How to fix items in div class="row" angular + bootstrap

Question: Do anyone have idea how to fix elements in div with class="row" ?
How it should look like: Good view, Click: Live show(example without angular)
How it looks like: Bad view
Switch component is repeated in lights component
When i remove

 elements looking good, but the are under themselves

    <app-switch  *ngFor="let switch of switches" [switch]="switch"></app-switch>

Link to my repository: SmartPi-Client
Answer: It is because Bootstrap 4 is using Flexbox. app-switch selector is between .row and .col divs so the correct bootstrap style wasn't applied to them.
You can make the browser to ignore this app-switch selector using the following css code.
:host {
  display: contents;
}

I added a working example here.
https://stackblitz.com/edit/angular-ho3q4q
Answer: The thing is that the style for the columns is applied to the direct child/ren of the html element with the 'row' class.
You could add that class to your app-switch component tag or use a wrapper around it to define the col design
Answer: Instead of adding .col-sm-12 .col-md-6 .col-xl-4 to child div of app-switch, add it to app-switch.

    <app-switch class="col-sm-12 col-md-6 col-xl-4" *ngFor="let switch of switches" [switch]="switch"></app-switch>


Load Multi-dimensional Mat from Text File using cv::FileStorage

Question: I have successfully saved a Mat of size(10,10, CV_32F24) to a text file using cv::FileStorage. However, when I try loading/reading it again using cv::FileStorage it fails and gives me the error below:
Error thrown:
"Unhandled exception at at 0x000007FEFD7D940D in CRF_6Epochs_d.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000015C3D0".
Error shown in console:
"OpenCV Error: Unspecified error (Too complex format for the matrix) in unknown function, file ......\modules\core\src\persistence.cpp, line 3106"
My code is as shown below:
const char *Path = "J:\\DATA\\WorkDIR\\AOI\\MultiEpochs\\54By54KM2\\Nodes\\Test.txt";
FileStorage saveNode(Path, FileStorage::WRITE);
saveNode << "NodePot" << fv1;
saveNode.release();

FileStorage loadNode(Path, FileStorage::READ);
Mat N(imgSize.height, imgSize.width, CV_MAKETYPE(CV_32F,24));
if(!loadNode.isOpened()){
    throw std:: runtime_error("Failed to Open File");
}

loadNode["NodePot"] >> N;
loadNode.release();

Answer: Because I came across the same issue. The problem is that there is an upper limit for the number of channels when you load a Mat from FileStorage. A possible workaround is reshaping the Mat to one channel like so:
saveNode << "NodePot" << fv1.reshape(1);

And then reshaping it back to the desired number of channels:
loadNode["NodePot"] >> N;
N = N.reshape(24);

You could also save the number of channels in the FileStorage, if it's not fixed anyway.
saveNode << "Channels" << fv1.channels();
int channels = (int)loadNode["Channels"];

Answer: from my knowledge you can only save data from opencv into xml and yaml files. so change your Test.txt to xml pt yaml file.
Comment: errm, nope, - anything not explicitly named ***.xml will get saved as yaml. (please try out yourself , before posting)


Get clicked pixel coordinates in photo overlay in Google Earth plugin

Question: I am  using Google Earth Plugin api to display large images as photo overlay (using image pyramid: https://developers.google.com/kml/documentation/photos). That works just fine.
However, now I need to add a user ability to mark a point on the image.
My questions:
1) Is it possible?
2) If not, are there other methods to display large images (vertical/diagonal) in google earth which allow this ability?
Answer: Yes it is possible, if the image is an overlay on the earth then each point of the image must correspond to a point on the earth.
It would simply be a case of allowing the user to put placemarks via clicking on the image.
There are a couple of tools that allow you to slice up large photos into image pyramids.
The first one "GMap Image Cutter"actually shows an example of the 'placemark for an image' idea in the output.
GMap Image Cutter - http://www.bartlett.ucl.ac.uk/casa/latest/software/gmap-image-cutter
MapTiler - http://www.maptiler.org/


Installing opencv in docker and run into compilation errors?

Question: I've been trying to build this repo and install it inside docker. https://github.com/Silvicek/baselines
I am installing it in dockerfile with pip3 install -e .. And there is a compilation problem in opencv.
My dockerfile:
FROM tensorflow/tensorflow:1.14.0-gpu-py3

ENV TZ="America/Los_Angeles"
ARG DEBIAN_FRONTEND=noninteractive
RUN rm /etc/apt/sources.list.d/cuda.list && \
    rm /etc/apt/sources.list.d/nvidia-ml.list && \
    apt-key del 7fa2af80 && \
    apt-get update && apt-get install -y --no-install-recommends wget && \
    wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb && \
    dpkg -i cuda-keyring_1.0-1_all.deb && \
    apt-get update
RUN apt-get install -y git python3-opencv
RUN mkdir /build
COPY baselines/ /build/baselines
WORKDIR /build/baselines
RUN ls -lrt /build
RUN ls -lrt /build/baselines
RUN pip3 install --upgrade pip setuptools wheel
RUN pip3 install -e . -vvv

docker build command:
docker build -f dockerfile --progress=plain -t dist_dqn .

It fails at the last step. There are 2 chunks of error outputs.
Chunk 1:
#14 1702.8   [100%] Generate files for Python bindings and documentation
#14 1704.0   /tmp/pip-install-jdnrgs2i/opencv-python_a75af04f83144d719ab5328e2c3bcd30/opencv/modules/
python/src2/typing_stubs_generator.py:54: UserWarning: Typing stubs generation has failed.
#14 1704.0   Traceback (most recent call last):
#14 1704.0     File "/tmp/pip-install-jdnrgs2i/opencv-python_a75af04f83144d719ab5328e2c3bcd30/opencv/
modules/python/src2/typing_stubs_generation/nodes/type_node.py", line 291, in resolve
#14 1704.0       self.value.resolve(root)
#14 1704.0     File "/tmp/pip-install-jdnrgs2i/opencv-python_a75af04f83144d719ab5328e2c3bcd30/opencv/
modules/python/src2/typing_stubs_generation/nodes/type_node.py", line 628, in resolve
#14 1704.0       self.full_typename, errors
#14 1704.0   typing_stubs_generation.nodes.type_node.TypeResolutionError: Failed to resolve one of "_
typing.Union[cv2.typing.Scalar, GMat, GOpaqueT, GArrayT]" items. Errors: ['Failed to resolve "GMat" e
xposed as "GMat"', 'Failed to resolve "GOpaqueT" exposed as "GOpaqueT"', 'Failed to resolve "GArrayT"
 exposed as "GArrayT"']
#14 1704.0
#14 1704.0   The above exception was the direct cause of the following exception:
#14 1704.0
#14 1704.0   Traceback (most recent call last):
#14 1704.0     File "/tmp/pip-install-jdnrgs2i/opencv-python_a75af04f83144d719ab5328e2c3bcd30/opencv/
modules/python/src2/typing_stubs_generator.py", line 49, in wrapped_func
#14 1704.0       ret_type = func(*args, **kwargs)
#14 1704.0     File "/tmp/pip-install-jdnrgs2i/opencv-python_a75af04f83144d719ab5328e2c3bcd30/opencv/
modules/python/src2/typing_stubs_generator.py", line 148, in _generate
#14 1704.0       generate_typing_stubs(self.cv_root, output_path)
#14 1704.0     File "/tmp/pip-install-jdnrgs2i/opencv-python_a75af04f83144d719ab5328e2c3bcd30/opencv/
modules/python/src2/typing_stubs_generation/generation.py", line 91, in generate_typing_stubs
#14 1704.0       _generate_typing_module(root, output_path)
#14 1704.0     File "/tmp/pip-install-jdnrgs2i/opencv-python_a75af04f83144d719ab5328e2c3bcd30/opencv/
modules/python/src2/typing_stubs_generation/generation.py", line 794, in _generate_typing_module
#14 1704.0       node.resolve(root)
#14 1704.0     File "/tmp/pip-install-jdnrgs2i/opencv-python_a75af04f83144d719ab5328e2c3bcd30/opencv/
modules/python/src2/typing_stubs_generation/nodes/type_node.py", line 297, in resolve
#14 1704.0       ) from e
#14 1704.0   typing_stubs_generation.nodes.type_node.TypeResolutionError: Failed to resolve alias "GP
rotoArg" exposed as "GProtoArg"
#14 1704.0
#14 1704.0     traceback.format_exc()
#14 1704.0   Note: Class cv::Feature2D has more than 1 base class (not supported by Python C extensio
ns)
#14 1704.0         Bases:  cv::Algorithm, cv::class, cv::Feature2D, cv::Algorithm
#14 1704.0         Only the first base class will be used
#14 1704.0   Note: Class cv::detail::GraphCutSeamFinder has more than 1 base class (not supported by
Python C extensions)
#14 1704.0         Bases:  cv::detail::GraphCutSeamFinderBase, cv::detail::SeamFinder
#14 1704.0         Only the first base class will be used
#14 1704.0   [100%] Built target gen_opencv_python_source
#14 1704.1   [100%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp
.o
#14 1779.0   [100%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2_uti
l.cpp.o
#14 1780.1   [100%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2_num
py.cpp.o
#14 1781.1   [100%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2_con
vert.cpp.o
#14 1782.7   [100%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2_hig
hgui.cpp.o
#14 1783.9   [100%] Linking CXX shared module ../../lib/python3/cv2.cpython-36m-x86_64-linux-gnu.so
#14 1787.9   [100%] Built target opencv_python3

Chunk 2:
#14 1788.3   Copying files from CMake output
#14 1788.3   Traceback (most recent call last):
#14 1788.3     File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/in_process/_in_process
.py", line 363, in <module>
#14 1788.3       main()
#14 1788.3     File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/in_process/_in_process
.py", line 345, in main
#14 1788.3       json_out['return_val'] = hook(**hook_input['kwargs'])
#14 1788.3     File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/in_process/_in_process
.py", line 262, in build_wheel
#14 1788.3       metadata_directory)
#14 1788.3     File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 231, in b
uild_wheel
#14 1788.3       wheel_directory, config_settings)
#14 1788.3     File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 215, in _
build_with_temp_dir
#14 1788.3       self.run_setup()
#14 1788.3     File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 268, in r
un_setup
#14 1788.3       self).run_setup(setup_script=setup_script)
#14 1788.3     File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 158, in r
un_setup
#14 1788.3       exec(compile(code, __file__, 'exec'), locals())
#14 1788.3     File "setup.py", line 537, in <module>
#14 1788.3       main()
#14 1788.3     File "setup.py", line 310, in main
#14 1788.3       cmake_source_dir=cmake_source_dir,
#14 1788.3     File "/tmp/pip-build-env-9wbzljs3/overlay/lib/python3.6/site-packages/skbuild/setuptoo
ls_wrap.py", line 683, in setup
#14 1788.3       cmake_install_dir,
#14 1788.3     File "setup.py", line 450, in _classify_installed_files_override
#14 1788.3       raise Exception("Not found: '%s'" % relpath_re)
#14 1788.3   Exception: Not found: 'python/cv2/python-3/cv2.*'
#14 1788.3   Building wheel for opencv-python (pyproject.toml): finished with status 'error'
#14 1788.3   ERROR: Failed building wheel for opencv-python
#14 1788.3   Created temporary directory: /tmp/pip-wheel-zsi8p8ua
#14 1788.3   Building wheel for future (setup.py): started
#14 1788.3   Destination directory: /tmp/pip-wheel-zsi8p8ua

Comment: you're trying to use some ubuntu/debian package, not the official opencv-python binary package. did you notice? -- `pip3 install opencv-python` (perhaps `-headless`) and be done with it?
Answer: Using the tensorflow/tensorflow:1.14.0-gpu-py3 base image appears to be a red herring. If the objective is to build the code at https://github.com/Silvicek/baselines then it's better to start from a python:3.7.17 base image.
I'll clone the repository directly onto the image here. You can volume mount a local clone instead.
Also downloading the MuJoCo license directly onto the image. You could also COPY from file on host or share via a volume mount.
 Dockerfile
FROM python:3.7.17

ENV TZ="America/Los_Angeles"
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        wget \
        git \
        mpich \
        libopenmpi-dev \
        libglew-dev \
        libosmesa6-dev \
        libgl1-mesa-dev \
        libglfw3

RUN wget -q https://www.roboti.us/download/mjpro150_linux.zip
RUN unzip mjpro150_linux.zip -d ~/.mujoco/

RUN wget -q https://www.roboti.us/file/mjkey.txt -P ~/.mujoco/

RUN git clone https://github.com/Silvicek/baselines.git /build

WORKDIR /build

# Add to end of ~/.bashrc.
RUN echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/.mujoco/mjpro150/bin' >> ~/.bashrc

RUN pip3 install -e .

# Remove from end of ~/.bashrc.
RUN sed -i '$ d' ~/.bashrc


Is there any limit to filesize while downloading through browser over http

Question: I am trying to download more than 10 GB of files over HTTP through the browser. While is accessed from CDN.
I am observing intermittent behavior, at times 2GB file downloads are failing but sometimes able to download up to 12 GB files successfully.
What is the maximum limit of file size that can be downloaded through the browser?
Is it a browser problem or client-side network problem or CDN problem on the server-side?
Comment: The only limit on the client-side is the client computer memory otherwise the issue is usually from the server where the stream times out.
Comment: As I am using CDN to get the content from Azure Verizon CDN, it shouldn't have any timeout.
Answer: There is no "Maximum" File size while transferring through HTTP. But sometimes it could be the browser's problem. It could also be a server-side problem as well.
But there is no actual maximum size.
Comment: I am getting this issue in Chrome, Firefox and Edge browsers. Haven't tried in any other browser.
Comment: Then it must be a server side issue if all the browsers are showing the same issue. @ChandrashekarH.L
Answer: http : no maximumsize so network or brower problem


Render View from string

Question: i need render view from string like this:
public class Controller : System.Web.Mvc.Controller
{
    public ViewResult ViewList()
    {
        string html = "
";
        html += Title(null);
        html += GridControls(null);
        html += FilterControls(null);
        html += Grid(null, new Sibi.Seg.User().List(pagina));
        html += "
";
        return View(html );
    }

}

Then i need render this string on return View() in Controller, see it:
public ActionResult Index()
{
      return ViewList();
}

Comment: While you could render your html using the helper method `Html.Raw()`, it leaves me wondering why you would want to do this?  This is a good example of breaking the separation of responsibilities for what MVC is intended.  Pass back a model containing your data and let the *View* decide how to render it.
Answer: You can use the Content method of the controller. Your code will look like this:
public ActionResult ViewList()
{
    string html = "
";
    html += Title(null);
    html += GridControls(null);
    html += FilterControls(null);
    html += Grid(null, new Sibi.Seg.User().List(pagina));
    html += "
";
    return Content(html, "text/html");
}

Or you can move the inner code to static classes and call static methods from mvc views, for example:
@{
    Layout = null;
}

    @(Html.Raw(StaticMethods.Title(null)))
    @(Html.Raw(StaticMethods.GridControls(null)))
    @(Html.Raw(StaticMethods.FilterControls(null)))
    @(Html.Raw(StaticMethods.Grid(null, new Sibi.Seg.User().List(pagina))))

Any of these 2 solutions will lead to the same result.
Comment: Thank you Vorrtex,
When i use this:

    public ActionResult ViewList()
    {
        string html = "";
        html += Title(null);
        html += GridControls(null);
        html += FilterControls(null);
        html += Grid(null, new Sibi.Seg.User().List(pagina));
        html += "";
        return Content(html, "text/html");
    }

The return ignores the Master Page (on MVC is _Layout.cshtml) therefore i need Render View.
Comment: @Lucas Argate You can ignore master page by using `Layout = null` as in the second example. Anything that can be done in code can be done in cshtml views too.
Comment: Thank you! I Could not do it, but i created a another solution for this problem, on Shared Folder, i create a View, with name ListView.cshtml and on Controller i returned the list view on method view.

Render View from string


Is there any performance improvement if I use MVVM

Question: I was checking about MVVM architecture. I am very interested to know if there is a very good performance improvement in Android app.
I have gone through several blog post which are talking about the comparison between MVP and MVVM. They are talking about it based on the following factors,

CPU Usage (MVVM has slight upper hand with MVP)
Memory Usage (MVP is good)
Execution time (MVVM is good)

Paper link:
https://www.atlantis-press.com/proceedings/issat-20/125949769
https://ejurnal.stmik-budidarma.ac.id/index.php/mib/article/view/4545
MVVM again has some flaws if the project grows, it's hard to maintain it because ViewModel may bloat hence we should user clean architecture.
I am confused here,
I have a project which does not follow strict MVVM practices but it is working fine and maintainable but it's not properly testable. Should I move to strict MVVM + Clean Architecture ? I agree that after this my code will be well testable and stick to the official guidelines. Because if i do so then in future, it may be easy for me to adopt Android guidelines.
But again the question remains same: Is there any performance, memory improvement ? And if yes, they how. In above papers, Execution time is claimed to be good with MVVM but how !
If i am moving to MVVM+Clean architecture then will i get any performance improvement!
Answer:
Is there any performance improvement if I use MVVM?

Short answer: No.

MVVM again has some flaws if the project grows, it's hard to maintain it because ViewModel may bloat hence we should user clean architecture.

This is not a flaw of MVVM - this is a flaw of the developer that allows the ViewModel to bloat.

I have a project which does not follow strict MVVM practices but it is working fine and maintainable but it's not properly testable.

One could argue that an app that is not "properly testable" is not actually "maintanable", but, OK.

Should I move to strict MVVM + Clean Architecture ?

That is a wholly subjective question no one can answer for you. Is this what you want to spend you time on? Is there an actual benefit to doing so?

But again the question remains same: Is there any performance, memory improvement ?

Probably not. Any performance / memory improvement will be realized by optimizing code for performance and memory, not by the architecture pattern you follow.

In above papers, Execution time is claimed to be good with MVVM but how !

I only skimmed said papers, but I don't know how anyone could reasonably review and measure app performance based on architecture.

If i am moving to MVVM+Clean architecture then will i get any performance improvement!

Probably not. If you're having performance problems now, it's likely due to some business logic that can be optimized irrespective of whatever architecture pattern you happen to be following.


Measure theory and the Intermediate Value Theorem

Question: I'm starting to study the basics of measure theory and found interesting this problem: Let us define $|E|=\int_{-\infty}^{\infty}1_E(x) \, dx$, where $E\subset \mathbb{R}$ and $1_E$ its characteristic function. Given $A\subset B \subset \mathbb{R}$, with $|A|=a<b=|B|$ and $x\in (a,b)$, is it possible to find $A\subset X \subset B$ such that |X|=x? Any ideas? Can I say this is an analogue of the Intermediate value theorem for the function $|•|$?
Comment: could you remove the ` ?
Answer: Correction due to @Brian Moehring:
Let $\varphi(x)=|A\cup(B\cap(-\infty,x))|$ for $x\in\mathbb{R}$, then $\varphi$ is continuous and $\varphi(x)\rightarrow|B|$ as $x\rightarrow\infty$ and $\varphi(x)\rightarrow|A|$ as $x\rightarrow-\infty$. Now Given $|A|<\alpha<|B|$, by IVT we have some $\varphi(c)=\alpha$ and $A\cup(B\cap(-\infty,c))\subseteq B$.
Comment: Thanks for the answer! I'll try verifying the continuity of the function. Is the definition of continuity the best approach? Thanks again!
Comment: Because it is how you connect to IVT.
Comment: I understand the connection but why is the function $\varphi$ continuous?
Comment: You may have to use Lebesgue Dominated Convergence Theorem to show that.
Comment: I heard about this theorem, I'll try. Thanks!


login programmatically with remember me feature

Question: I'm trying to create a custom login form, since I need it to be ajax based. And I can't use the existing modules that do this. So far I have achieved this by setting the global $user object to the loaded user and calling user_login_finalize(). But now I need to make the login persist and I have no idea how the default drupal login does it. Any tips are appreciated. Thanks
UPDATE:
The duplicate question indicated by Pontus Nilsson does not mention in any way how to make the login persist nor how to use the default drupal remember me or the RememberMe module functionality.
UPDATE 2:
I must elaborate that I have installed Remember Me module to make the persistent login optional for the user. Is that a reason why I needed to go through all this hassle explained in my answer to make the programmatical login persist?
Comment: possible duplicate of [How do I programmatically log in a user?](http://drupal.stackexchange.com/questions/5825/how-do-i-programmatically-log-in-a-user)
Comment: Where does it exactly answer my question there?
Comment: I guess you were a little bit quick with the duplicate button lol
Answer: This is how I accomplished the remember me feature. Since I didn't find any specific resources on this matter, the proposed solution may or may not be optimal and correct, although it works fine.
You use the following code to login a user programmatically:
$user = user_load($uid);
$login_array = array ('name' => $user_first_query->name);
user_login_finalize($login_array);

After that you have to decide whether to persist the login or not using the provided check box in the login form:
//at this point we need to persist the login by saving the user again
//with the remember_me data. But doing so, resets the user picture.
//So we need to preserve it somehow.
$user_picture_id = $user->picture;
if($_POST['remember_me']) {
    user_save($user, array('data' => array('remember_me' => (int)$_POST['remember_me'])));
}
else {
    unset($user->data['remember_me']);
    user_save($user, array());
}

//restore the user picture id
db_update('users')
    ->fields(array(
         'picture' => $user_picture_id,
    ))
    ->condition('uid', $uid)
    ->execute();

For the part where I have done unset($user->data['remember_me']); I have made sure that the rememeber_me data does not exist from a previous login. I think this should be done in the modulename_user_presave() hook but I couldn't implement it there.
Remember that since the main question is how to persist a user login, I have not provided a full login procedure, for example you should authenticate the user's credentials using the user_authenticate() function.


Why does mean-centering in a univariate logistic regression change p-values?

Question: I have a very simple logistic model with a single continuous independent variable and a two-category dependent variable. When I mean-center the IV, the p-value of the coefficient changes significantly, and I'm not sure why.
Example code snippet that reproduces the effect:
import statsmodels.api as sm
import numpy as np
x = [5, 5, 6, 6, 5, 6]
y = [1, 1, 1, 1, 2, 2]
xc = x - np.mean(x)
lr1 = sm.MNLogit(y, x)
model = lr1.fit()
lr2 = sm.MNLogit(y, xc)
model2 = lr2.fit()
print(model.pvalues)
print(model2.pvalues)

0.423
1.

Shouldn't the significance level of the coefficient not depend on the predictor variable's scale? All I can find from other threads is that centering will change the significance of interaction effects, but that's not applicable here.
I'm also wondering which of the two results I should ultimately use to determine if there is a significant relationship between the two variables. Intuitively, the model with centered input seems "more" correct, given that in this data set there is no relationship at all.
Comment: I'm betting this has to do with the lack of intercept.
Comment: I wonder how many disastrous decisions have been made throughout the world on account of statsmodels not automatically including an intercept? It's certainly wasted some of my time.
Comment: When  I run this in R, the p-value of 0.423 is associated with the intercept, and the p-value of 1 is associated with $x$, with both versions of $x$.  Are you sure your output is what you think it is?
Comment: I suspect this may not be a good illustrative example , as $x$ and $y$ appear to be independent.  Nor do I understand how both can exceed $1$ in a logistic regression
Answer: The statsmodels package does not include an intercept. When you include an intercept, only the intercept p-value changes (which makes sense for centering the feature).
import numpy as np
import statsmodels.api as sm
x = [5, 5, 6, 6, 5, 6]
y = [1, 1, 1, 1, 2, 2]
xc = x - np.mean(x)
lr3 = sm.MNLogit(y, sm.tools.add_constant(x))
model3 = lr3.fit()
lr4 = sm.MNLogit(y, sm.tools.add_constant(xc))
model4 = lr4.fit()
print(model3.pvalues)
print(model4.pvalues)

This happens in an OLS linear regression, too, and the visualization is easier.
x <- c(1, 2, 3, 4, 5, 6)
xc <- x - mean(x)
y <- c(1, 2, 5, 6, 8, 155)
L1 <- lm(y ~ 0 + x)
L2 <- lm(y ~ x)
L3 <- lm(y ~ 0 + xc)
L4 <- lm(y ~ xc)

par(mfrow = c(1, 2))
plot(x, y)
abline(a = 0, b = summary(L1)$coef[1], col = 'red')
abline(a = summary(L2)$coef[1], b = summary(L2)$coef[2])
plot(xc, y)
abline(a = 0, b = summary(L3)$coef[1], col = 'red')
abline(a = summary(L4)$coef[1], b = summary(L4)$coef[2])
par(mfrow = c(1, 1))

Black represents the regression models with intercepts; red represents the models without intercepts.
When there is an intercept in the model, all the centering does is shift the data to the left or right, but the slope does not change (notice how the black lines are parallel). However, when there is no intercept, the line has to fit the data as best it can while also having a particular y-intercept (zero), resulting in the line twisting and changing the slope (notice how the red lines are not parallel).
Comment: statsmodels does NOT make any changes to the design matrix provided by the user, unless formulas are used. Now we are stuck with it, the discussion and decision was 14 years ago. https://github.com/statsmodels/statsmodels/issues/8223 (I never had a strong preferences for adding or not adding constant.) Main advantage of not touching the provided design matrix is that we do not need to make a copy of it in most cases and so save time and memory. Use formulas if you want convenience over speed!
Comment: WOW that's quite the caveat to a Python package.
Comment: @lua It's a design decision to omit the intercept. While my naïve thinking disagrees with it, we do have a `statsmodels` developer on here who might be able to share why the intercept is excluded. Having interacted with him a few times, I expect there to be a compelling reason.
Comment: Ah that makes sense. Thanks!
Comment: If you use formulas in statsmodels, then it's about the same as in R or other packages. If you use pandas or numpy interface, then statsmodels assumes that you know what you want and provide that.


If I have a combination of pitches played as a chord in a MIDI, how do I extract only two pitches from it and get somewhat similar tone?

Question: While extracting pitches in a MIDI file of piano instrument, I get chords with combination of pitches as D2.D3.D4.F#4.A4 played for 0.2 duration. However, I want to receive only a maximum of 2 pitches to decrease the total number of unique combinations of pitches in my dataset.
For e.g. D2.F#4. Thus, how do I know which of the two pitches in the combination will give somewhat the same sound as the entire combination does? Any tips I can implement for this problem? I do not want to lose the actual melody of the piece of the music either.
Comment: Why do you need only 2 pitches?  If you want a simplified data set, I'd suggest mimicking what musicians do on their lead sheets and have 3 parameters- chord root, chord quality, and melody note
Comment: @ROOT31415 why does it need to be reduced to two pitches at a time?
Comment: How much music theory do you know? If we said to keep the root and third or third and seventh would that help? Also is the melody note that you want to keep one of the notes in the chord or is that a separate set of midi data?
Comment: Buy polyphonic synths, not paraphonic ;)
Comment: I am trying to develop an algorithm for getting a maximum of two notes played at a time. I am not that good at music theory. I am currently using music21 library to handle the MIDI datasets. And I have been getting trouble with a lot of unique combination of pitches. How can I address it?
Comment: I think this is a case where in order to create effective software, you might have to learn a lot about the field that the software operates in. In this case, you're trying to write a piece of software that is entirely based on music theory, while not being very good at music theory yourself. Imagine trying to write a program that graphs a mathematical function without knowing how to graph functions by hand. It would be very, very difficult, and you couldn't just read a short paper on how functions work. You'd have to know all the essential math. Same with music.
Comment: In other words, I suggest you team up with someone who is very strong in music theory and work with that person to address the nature of music theory and human perception of music. Without those skills, you can't hope to come up with an effective algorithm. Usually computers can help us do things that we already know how to do but more efficiently. It's very hard to get them to do things we don't know how to do at all.
Comment: Do you mean by sitting down and analyzing it by hand? Or are you trying to develop an algorithm that does this?
Answer: Assuming you mean to do this by a computer program...
You could invert the tones so they are a tertian stack then take the root and third.
You could invert to a tertian stack, take the root, and then also take the original highest tone as the "melody" tone to get chord roots plus melody for two parts.
Both methods won't make any overall analysis of the music and will very likely result in poor choices you wouldn't make if you just reduced the music to two parts.
Answer: One way to go about this would be to consider an approximate harmonic spectrum for your instrument and use this to estimate the harmonic spectrum for your chord. Then try to find two (or more generally n) different notes and velocities that explain the harmonic spectrum best. Keep in mind that the best notes do not necessarily need to be part of the given chord, so in the worst case we need to try (K n) combinations where K is the number of possible notes. With K=128 this would be 8128 combinations for n=2, 341376 for n=3. So this is computationally a bit hard. This means we most likely need to try to remove notes that are unlikely to be of use here.
Under strong assumptions (harmonic spectrum is independent of pitch and velocity) and ignoring things such as inharmonicity and tuning differences (that is we round each overtone to one chromatic scale tone) and using the first six harmonics (since these can be somewhat mapped to chromatic notes) this code in sageMath here does such a thing:
import scipy.optimize
import itertools

part = (0.91, 0.34, 0.09, 0.2, 0.08, 0.11)
steps = (0, 12, 19, 24, 28, 31)

def h(notes):
    res = [0] * (128 + steps[-1])
    for (i, v) in notes:
        for j in range(6):
            res[i + steps[j]] += (v * part[j])**2
    return list(map(sqrt, res))

def mod(notes):
    vars = var(",".join([f"x{k}" for k in range(len(notes))]))
    if len(notes) == 1:
        vars = [vars]
    notes = list(zip(notes, vars))
    return h(notes)

def err_fn(notes1, notes2):
    h1 = mod(notes1)
    h2 = h(notes2)
    sqerr = map(lambda x, y: (x - y)**2, h1, h2)
    res = sum(sqerr)
    return res.full_simplify()

def err_fn2fn(errfn):
    vars = errfn.variables()
    f = fast_callable(errfn, vars = vars, domain = RR)
    return lambda x: f(*x)

def solve_selection_efn(efn):
    v = efn.variables()
    n = len(v)
    efnfn = err_fn2fn(efn)

    res = scipy.optimize.minimize(efnfn, [0] * n, bounds = [(0, 127)] * n)
    res = [int(round(_)) for _ in res.x]

    return dict(zip(v, res))

def solve_selection(notes1, notes2):
    efn = err_fn(notes1, notes2)
    return solve_selection_efn(efn)

def ip(v1, v2):
    return sum(map(prod, zip(v1, v2)))

def proj(v1, v2):
    return ip(v1, v2) / sqrt(ip(v1, v1))

def ang(v1, v2):
    return ip(v1, v2) / sqrt(ip(v1, v1) * ip(v2, v2))

_STEP_MAP = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]

def step2notename(n):
    oct = n // 12 - 1
    cstep = n % 12
    return f"{_STEP_MAP[cstep]}{oct}"

def solve_n(notes, n, ths = 0.15, nsol = 5):
    lowest_step = min((note for (note, _) in notes))
    highest_step = max((note for (note, _) in notes))
    viable_notes = range(max(0, lowest_step - steps[-1]), min(127, highest_step + steps[-1]) + 1)
    ref = h(notes)
    norm_ref = sqrt(ip(ref, ref))
    viable_notes = list(filter(lambda nt: ang(h([(nt, 60)]), ref) > ths, viable_notes))
    print(viable_notes)
    print(len(viable_notes))
    c = itertools.combinations(viable_notes, n)
    exprs = [(cmb, err_fn(cmb, notes)) for cmb in c]
    sols = [(solve_selection_efn(errfn), cmb, errfn) for (cmb, errfn) in exprs]
    errs = [(sqrt(errfn.subs(sol)) / norm_ref, list(zip(cmb, sol.values())), [step2notename(_) for _ in cmb]) for (sol, cmb, errfn) in sols]
    return sorted(errs)[:min(nsol, len(errs))]

# May take some time!
solve_n([(38, 60), (50, 50), (62, 50), (66, 60), (69, 60)], 2)

https://sagecell.sagemath.org/?z=eJyVVltv2zYUfjfg_8CpGECljGMpi5cYyICu7fZUoOj2JgiCLFM1E4lSJdmzE-S_75xDUhcjAbYAochz_XhutCrrqulYm6n6tKjqTpXqSc5nypBVJ5uuqop2PpvP6hQo94wvF3eBYMvF9S-4Lu9wDWl7i2sQ-PNZ28m6JWHBAmAGIBWCfAgi1ygwn21lznZcV51s_fV8xuCvkagTLWN2wXgQ3rL3jAxFl0HsG5G8ahhXgh18pjQjbavsuA_IaFL9XfKVP-JZB5HqrT7EMXsPGA_gDi8HBP_iInRYun2jWaHajpdpzdsfTSfQgN-jL6vtFP8hbfAC8OGe8BYPldI8yr3j8-OLR9geB2yF1FbZj317OZWzgczu71kwwm-NR_iNDZkEgUYgn1RtNAWJOpv2Hi7SDrtsmiS3riCb9A3dPXYBGO1vF1hLuxCo1k5oae0PMITCEKEiLTfblB0FO60ZP7JLdsJwCjAH_6E_znG7LznpTlECc5HviyJpoQALlZ_4GeAQMMMu12chJ9oCDirdFLLlrlqAladtl2RpUSDHKItRpiBc26pMIS_37Nu3KRx3ozXL-cWxh9JWxUEmrSxk1qlKJxJBjSAhntfQoAvM78GeQSjXBry7GlhBL6NATRpzUSpNG066wvYKbDbVXm-pPkzL_eoTYxL0SOmONyjIE9-ngkyoICHqx3jwS3ffqszU1OGs6s9u_0YJydHNzkUmft4KpnOHCED1EA5DwuhBBWHV1U21FexpEBuQAuvhdeVBml0x7GzuKMGgDm36_7Uh6HgIDRQ0lfz19-evyZcPXzED3kdPMO_jO1w_0ULbz7j8QQud_6SFth9ooe3vXtwnAQZYiOHUaSl5X3pVhhNas6srKAFowMCQMxQnxs9An9wl9557gBHJxS_PYObFm-Zbu9kCtdbtsJpg0t_AEdhwuHEIiuofCf1mHUK5clI0cxt3giXD6HZDaqe-78Zq6fE_qR2ovxI3Bs1gRWVogTGQy9EzIggUNIiYeh0_NXAI-irNh6nn-rhqysQwXPbhhG2Sv4GMBnSuCnhO3ZjU3ZoqbMcjruFlWS19BIc22G8YYjEx4gzXDTbxhDNm0Hh5RS0DEP1jvsiqcqN0iv3WTsRFPzHksTbPDc_KjXCNTHtrmHIDBMxKZh8kKAaj9GpX09wWzBmEg8nvmADGyLU1CFRrEANtpny737TowMf2c7kQwyNI5oAPA7jY4_T1wWk07ZhkNP5APrZIQGuKT9GAcmj6kdV0cotoWj9aYzlpUsTgE9GnPn3HvqQn1qWPEjRKyWCEy5_gp5Htp4hf31LaBeM3ULA3tFuF_W7luKs7Ux7w88n_FwMMy1Y=&lang=sage&interacts=eJyLjgUAARUAuQ==
Here the chord D2,D3,D4,F#4,A4 with velocitites 60,50,50,60,60 would be reduced to D2,F#4 with velocities 83,60. So basically we'd try to get as much of the D3,D4,A4 by playing the root louder.
With three notes we'd go for D2,F#4,A4 with velocities 78,60,61 and with four notes we'd go with D2,D4,F#4,A4 with velocities 70,53,60,60.
With two notes we get a nearly similar match for D2,A4 and slightly worse match for D2,D4 and D2,D3.
With three notes we get noticeably worse matches for D2,D4,F#4 and D2,D3,F#4 and even slightly worse with A4 instead of F#4.
With four notes we get a slightly worse match with D2,D3,F#4,A4 and then a noticeably worse match with D2,F#4,A4,D5. This one is interesting as it gives us a similar sounding combination featuring a note not present in the original selection. All other 4-combinations match worse than the best 3-combination.
Answer: Because this is a matter of listening and not mathematics, the best way is to try all 2-note combinations, best via a MIDI-piano-keyboard to understand what's going on, and making a choice:

D2. D3 / D2.   D4 /   . . . /    .F#4 .A4

As suggested, consider inversion too, like:

F#4 -> F#3, hence e.g. F#3..A4 etc.

However, very likely you'll observe by ear:

the D-octaves are just octaves (i.e. sound quite the same)
the D-major chord sounds kind of nice D4.F#4.A4
which can be approximated by the power-chord, i.e. omitting the 3rd: D4. .A4
the 1st and the 3rd are not the best choice D4.F#4
even inversion won't do much magic: D3.F#4, or F#3.D4., or D4.F#5
and so on.

There are more things you could do with chord variations or chord extensions, which, as stated already in an other answer, depend on your music, i.e. the context where your 5 notes are played.
Answer: There are some details about what you're trying to achieve that are missing in the question, but I'm comfortable making two different recommendations.
If you're trying to preserve the overall character of an entire piece of music while only playing two notes at a time, then the best thing to do is simply preserve the highest and lowest notes. The highest note is usually the melody and/or the easiest note for listeners to hear, and the lowest note always plays an important role in the harmonic foundation (although not always the most important role).
One downside to highest and lowest note is that a lot of rhythmic content and inner harmonic movement can be lost. Determining what is the most important note to keep on a moment-to-moment basis would not be easy, because human hears and musical perception are very sophisticated systems.
If you're trying to preserve the character of a single chord, then the best notes to keep are the root and the third, except for many seventh chords keeping the third and the seventh can be a better option.
This method would require an algorithm to determine which of the notes at any given time is the root and which is the third (and potentially which is the seventh). This is not always easy. Also, if you fed this kind of algorithm a whole melody with accompaniment, it will very likely chop up the melody and bass line completely and the piece can end up sounding very different. It would have the same essential harmonic progression, though.


Looking for idea to solve an integral

Question: I am looking for idea to solve below integral
$$ \int_{0}^{a}\frac{{4\pi}\cos \left(\frac{\pi x}{30}\right)}{3\sqrt[3]{1-\left(\frac xa\right)^{3/4}} } \mathrm dx$$
I tried to use substitution, but got stuck
Can someone help me to find this integral. I am thankful for you hint in advanced. (It was in thermodynamics book)
Comment: at least this beomes uglier then a bessel function
Answer: Of course, you first want to do a change of variable $u = x/a$.
For positive integers $j$,
$$ \int_0^1 \frac{x^j\; dx}{\left(1-x^{3/4}\right)^{1/3}} = {\frac {4\;\Gamma \left( 4(j+1)/3 \right) \Gamma \left( 2/3
 \right) }{3\;\Gamma \left( (4j+6)/3\right) }}
$$
Then $ \int_0^1 \frac{\cos(tx)\; dx}{(1-x^{3/4})^{1/3}}$ can be expressed
as a rather nasty combination of hypergeometric functions:
$$ \eqalign{\int_0^1 \frac{\cos(tx)\; dx}{(1-x^{3/4})^{1/3}} &=
{\frac {8\,\pi\,\sqrt {3}}{27}
{\mbox{$_6$F$_{11}$}\left({\frac{7}{24}},{\frac{5}{12}},{\frac{13}{24}},{\frac{19}{24}},{\frac{11}{12}},{\frac{25}{24}};\frac14,\frac13,\frac38,\frac12,\frac12,\frac58,\frac34,\frac56,{\frac{7}{8}},1,{\frac{9}{8}};\,{\frac {-{t}^{6}}{46656}}\right)}
}\cr
&- {\frac {81\,{t}^{2}}{220}
{\mbox{$_7$F$_{12}$}\left(\frac58,\frac34,{\frac{7}{8}},1,{\frac{9}{8}},\frac54,{\frac{11}{8}};\,{\frac{7}{12}},\frac23,{\frac{17}{24}},\frac56,\frac56,{\frac{23}{24}},{\frac{13}{12}},\frac76,{\frac{29}{24}},\frac43,\frac43,{\frac{35}{24}};\,{\frac {-{t}^{6}}{46656}}\right)}
}\cr
&+{\frac {187\,\sqrt {3} \Gamma \left( \frac23 \right)^{3}{
t}^{4}}{11856\,\pi}
{\mbox{$_6$F$_{11}$}\left({\frac{23}{24}},{\frac{13}{12}},{\frac{29}{24}},{\frac{35}{24}},{\frac{19}{12}},{\frac{41}{24}};\,{\frac{11}{12}},{\frac{25}{24}},\frac76,\frac76,{\frac{31}{24}},{\frac{17}{12}},\frac32,{\frac{37}{24}},\frac53,\frac53,{\frac{43}{24}};\,{\frac {-{t}^{6}}{46656}}\right)}
}
}$$
I don't know if this can be simplified.
Comment: 1:thank you . 2:the answer does not depend on $a$ ?
Comment: It does.  For one thing, $t$ will depend on $a$.  Also there's a factor of $a$ from the change of variables.

Looking for idea to solve an integral


Quick way to denote the different solutions of an equation.

Question: Let's say that we conclude from $u^2+u-2=0$ that (over $\mathbb R$) $$u=- \frac{1}{2}\pm\sqrt{\frac{1}{4}+2}$$
What are the notational possibilities for this situation? Should I write
$$u^2+u-2 =0$$
$$\iff u=- \frac{1}{2}\pm\sqrt{\frac{1}{4}+2}$$
$$\iff (u=-2\lor u=1)$$
or can I write
$$\iff u=- \frac{1}{2}\pm\sqrt{\frac{1}{4}+2}\in\{-2,1\}$$
or something like that? Mostly I wanted to know whether there exists a short yet formally correct way of saying "$u$ can be this and that". Especially when $u$ can take on more than two values.
Answer: I think that it depend upon the last expression you get. If your expression can't be simplified as in $x=1\pm\sqrt{2}$, then use the "$\pm$" notation. Otherwise, as in $x=1\pm\sqrt{4}$, add an equivalent statement such as $x=3 \vee x=-1$, or even $x=3,-1$ which the same by convention.
Comment: I never dared to write $u=-2,1$, thinking of it as a no-go.


Phaser game perspective

Question: I'm new with Phaser and I would to receive some advice on how to start building this type of game. Any example, ideas, tutorials are welcome.
Thanks in advance!.
http://appcrawlr.com/ios/beat-mp3
Answer: Phaser is focused on 2D graphics, so sprites bitmaps tilemaps etc. The sprites can rotate and zoom, so with zooming and you can simulate the 3D perspective like in the example image. In other words, as long as you don't need the perspective of the 4 lanes to change (so you won't need a 3D model) you can make such a thing in Phaser.
Phaser is especially well suited for animated user-interface and particle effects. So animating the "perfect" and "combo" texts, and the white transparent stars at the bottom is relatively easy in Phaser, by using the build in tweens and emitters etc.
Your question about how to start building this type of game is too broad for stack overflow. I think it's better to ask this question in the Phaser forum at www.html5gamedevs.com
Comment: Thanks for your advice @BdR!
Comment: This tutorial is great for this type of thing... http://codeincomplete.com/posts/javascript-racer-v1-straight/ The math behind the setting the y position, speed and scaling is what you need.

Phaser game perspective


Am I singing in a mixed voice?

Question: I've been singing since I was like 12. I never took any lessons, but I've been trying to train my voice better. Here's the clip: https://vocaroo.com/i/s1J2DcCdndgn
My first question is am I a bass or baritone? I never could figure it out. The range I'm singing it feels fairly comfortable. I was driving so I wasn't breathing properly or anything but it felt good.
Also, I just learned very recently how to place my resonance in my mask. I feel as though I was doing it before but never really knew how to hone in on it and place the complete sound there. I usually pull my chest up. I've already noticed the difference. I would usually feel tension around my chords on this note.
My second question is am I singing in a mix? If so is it a chest mix? Thanks!
Comment: vocaroo as a a sound host regularly purges their audio files, and the point of stackexchange is to build a repository of answers that will be useful to other people with questions in the future.  I've made the same mistake before. I don't know if there's an official policy on preferred sound hosts here (like there is with imgur for images), but I've seen people often use soundcloud, I tend to use https://instaud.io/ or https://clyp.it because you don't need an account.  Thanks for the question though, I'll take a listen and answer if I think I have a good answer for you!
Comment: Wow, wonderful clip, you have a great ear for pitch, hitting all those blue sweet spots.  (microtonality babyyyyy)
Comment: @Some_Guy Thank you! And ah I didn't know they deleted the files. I'll use soundcloud from now on. Did you know if I was using mixed voice there?
Comment: gotta go now but I'll post an answer tonight! (in about 5-6 hours) :)
Answer: It appears to me that you are obviously a baritone, rather than a bass, based on the pitches, the tessitura, which is the range that you are most comfortable with and the timbre.
When you are singing, there is always a mix between chest voice and head voice, a 'mixed voice' usually refers to an equal mix between both chest and head voice. In this case, you are singing in mostly a chest mix, but when you reach the notes which are above your tessitura, your support drops and the mix is mostly an upper chest mix, however you do not really use a heady mix (which isn't necessarily bad). What I would suggest is that you get more control over your voice when alternating between low and high pitches, as the last high notes were uncontrolled, which indicates that you are not comfortable with that range yet, but also you do not have much control over your mix and support yet. This also results in a sudden 'high-larynx', which is an unhealthy technique when sustained. You can hear this by a loss of support and excessive increase in thinness of your voice. What I also notice is that you tend to 'push out' belts, which you usually do when you scream. Try to get more control of your belts by becoming more aware of the flaws. Your breath support is decent, but at the end of the phrasing, your vibrato sounds a little bit slurred, which is both a result of bad breath support, high-larynx and by 'pushing' belts out.
Ideally, you want to have a balanced chest and head mix when singing upper notes, which of course may depend on the intention/song/genre etc, but purely technically speaking. In this case, your voice gets thinner, but you do not really mix your voice equally. However, your timbre sounds really nice and your vocal pitch is relatively good. So keep up the good work!

Response to comments:
"And I have been having issues with keeping my larynx neutral. And you're saying that's due to my breathing?": No, I'm saying that your vibrato is slurred, which is a result of bad breath support AND high-larynx. High-larynx is not a result of bad breath support, but usually a result of pushing and strain. However, high-larynx is usually ACCOMPANIED by bad breath support. I can hear that your tessitura is in the bass range, however, your voice kind of starts to thin a little bit quick, so high-larynx is indeed a thing you have to work on. You should focus on notes which are in your tessitura and really remember the feeling of a neutral larynx. By doing this, sing open vowels such as 'oh' and by singing a note which you are comfortable with, your larynx will most likely be neutral. Now when you are singing along a scale, like in your recording, you keep pushing your voice up by putting more effort, which results in a high-larynx and a thinness of voice, which results in less resonance. There are a few tips how to prevent high-larynx (as well as low-larynx, which is just as unhealthy):

Sing open vowels like 'oh' in your tessitura. This will most likely be done in a neutral larynx. Now remember this feeling.
Now increase the pitch VERY slowly. Keep thinking of the feeling of a neutral larynx and try not to 'push' it upwards. The moment when you feel your larynx increasing, stop and do it again. Do not go further, as that isn't very effective.

Make sure that while doing this, your posture is right and relaxed. Do not strain your muscles and do not strain your voice when trying to reach the top notes. Get comfortable with your tessitura first.
Keep practising and eventually you will know and feel when your larynx is rising. By becoming aware and practising, you will eventually learn how to master this.

"Am I supposed to be pushing on my abdominal muscles to belt or should It be the same "suspended" type of air flow I would use when singing in lower? I think I'm a bit confused when it comes to support because in my mind I think supporting a note means using more air flow."
No, support does NOT mean using more air flow. When you are not controlling the air flow by using it excessively, you might even end up with less control over your belts and support, which results in a breathy and weak voice. With breath support, it is once again important to get a feeling of how proper breath support works. As you go up the scale, supporting your voice becomes increasingly difficult, which is natural, because of the extra effort you have to make, which might strain your voice easier.
'Support' is a way of using other parts of the body connected to the work of the lungs and larynx to produce a better tone production and the ability to sing extended phrases and sustain notes for longer. The successful connection between the musculature of the body (the abdomen and back primarily) and the larynx (for sound and tone production) is often referred to as 'support', 'breath support' or 'supporting the tone'.
"Would these higher notes be considered more supported?" These higher notes are unfortunately unsupported. I can see that you've explored your range well, as you seem to hit the high notes, however, it is not properly mixed. Your high notes are excessively mixed with head-voice, which results in a lack of agility, which will make you unable to sing faster passages while alternating between low and high notes, but also a too 'light' tone, which sounds less powerful. I can hear that you are mostly singing 'with your throat', which means that the sound is mainly resonating in your throat. You can hear this by a lack of resonance and a not 'full/round' sound. Your higher notes are also strained. Also, when you go even further, you can hear your voice cracking, which is NOT the result in this case because it is at the end of your range, but because you are straining and pushing your voice to that note.
General advice:

Work on your larynx position. Look at the tips which I have provided and mentioned above.
Work on your breath support. As this is a complex subject, I advise you to do more research on breath support on how to do it properly. Like I've mentioned before, you have to feel how proper breath support feels and sounds like. Once you discover this, it will become more natural.
It sounds like you are correlating the increase of pitch with effort. You are straining your voice by putting more effort into hitting higher notes. Higher notes do NOT mean that you have to put more effort, because like I've said, it will only result in a high-larynx, which again results in thinness and strain.
When singing a high-note, you have to prepare yourself mentally and physically for it. This will decrease the strain as you are anticipating it, but also increasing your vocal agility. In the recording, your agility is limited because of uncontrolled mixing of your voice, but as well as not preparing for a high-note. Do not surprise your own voice by suddenly 'jumping' to a high note, but anticipate it.
Work on your tessitura and get comfortable with it. When singing along a scale, do not go any higher until you feel completely comfortable with it, in terms of strain, larynx and support. Until then, go further. I can see that you have explored the ends of your range, but quality is more important than quantity, obviously.
Work on mixing your voice correctly. When singing high notes, your voice is too heady, which means that it is overly mixed with head voice. You want to be aware of it, by knowing how it sounds and feels like. This technique works the same as larynx-position. Sing an open vowel in your tessitura, and hear how it feels and sounds like. This will most likely be done, if you are truly comfortable with that note, with a neutral larynx and equal mixing. Because of your vocal type, a baritone, you might sing it with more chest mix than head mix. I would have to judge in a subsequent recording if that is the case. However, once you get an equal mixing, you want to remember that feeling and work on it the same way as controlling your larynx position.

Feel free to ask any more questions or post more recordings, so I can provide my subsequent advice. Good luck!
Comment: Thank you for the detailed response! Since I started doing these pharyngeal exercises I've noticed my voice is actually higher than I first assumed. I thought I was a bass lol. And I have been having issues with keeping my larynx neutral. And you're saying that's due to my breathing? Am I supposed to be pushing on my abdominal muscles to belt or should It be the same "suspended" type of air flow I would use when singing in lower? I think I'm a bit confused when it comes to support because in my mind I think supporting a note means using more air flow.
Comment: Would these higher notes be considered more supported? https://soundcloud.com/user-371953851/vocaroo-s0ptphabemav/s-qK17h
Comment: Hi! I will respond to your comments in my original post by editing it, considering it is quite long.
Comment: Don't be shocked by the amount of comments, I know it is difficult, but it is important to persevere and to not give up, you can certainly do it by being aware and by constantly reminding yourself of the given feedback.
Comment: This has been extremely helpful! I appreciate it a lot. I don't have any vocal coaches in my area that I know of so this information is awesome. I will add the open vowel exercise to my daily routine. I've been trying to read up about breath support. I believe I'm inhaling correctly. I feel my diaphragm and rib cage expand but it's the exhalation that confuses me. I have to figure out how much air flow is needed for each register. And I actually never exercised my upper range until these past few weeks when I learned how to get into head voice and I guess I got a little too excited haha.
Comment: I'm not exactly sure how to make it sound more chesty. I'm assuming that would be me adding more mouth resonance instead of nasal? I'm working on getting better at using resonance but it's strange because it's such a different sound and feeling that I perceive it as sounding weak and nasally, but it seems the more nasality I add the higher I am able to go comfortably. Around E4 - F4 is when I can feel my chest voice start to thin out. At that point I should start mixing correct?
Comment: That's a good question. Regarding the air flow, you actually want to keep it consistent throughout. You don't necessarily have to increase the airflow when hitting higher notes, so experiment with this and remember what gives you the best result. Regarding the mixing, you ideally don't want any nasal resonance at all, as that negatively influences the projection and resonance. Ideally, you want to keep the mix consistent, but when increasing the pitch, you want to slightly start mixing, while using your ears and feeling to control the balance. Do not over-do the head mixing (or under-do it)
Comment: When you get more comfortable with high notes, you naturally don't need as much mixing. However, at the beginning, it is almost inevitable to slightly start mixing more. This is completely fine, as that helps you to hit higher notes. However, ideally, you want to keep the chest and head voice equally mixed. And make sure to really control the belts! Sometimes your belts are uncontrolled and pushed, which you usually do when you scream. Make sure it is 'cantabile' at all times, which means singable. I highly advise you to listen very critically and carefully. You can do it!
Comment: Thanks! I've been monitoring my breathing to see when I start to feel tension and it's usually when I push my stomach in on a phrase or note that's higher because it feels natural to push it in when I want to go higher. Especially if it's a big jump in pitch. However when I try to keep my stomach evenly "pushing"  the note is easier! I think it helps if I try my best to keep my abdomen in the same position from when I inhaled for as long as I can. I seem to get a good even air flow that way. I'm still researching it though.
Comment: And I'm a bit confused when it come's to resonance because you say I should ideally have no nasal resonance I've been using this kind of "Learn At Home" singing course called Mastering Mix by Brett Manning and it says that I need to put the sound in my mask and when I attempt to put it in my mask it introduces more nasal resonance. Not so much that it sounds nasally but I can feel my nose vibrating. So I'm assuming that means I'm probably not doing it correctly haha.
Comment: https://soundcloud.com/user-371953851/20190401-200537a/s-FI5LW This would be me singing in what I'm assuming in my mask? I'm overdoing it a bit I think and I may sound a bit stuffy because I have allergies
Comment: The placement of the resonance has improved in that recording, as it no longer primarily resonates in your throat but more in the 'mask'. However, the projection is still limited because you are still pushing the notes and slightly increasing your larynx. You want to be completely comfortable with the higher notes, which of course takes a lot of practise and takes time. Your control of your balance is still uncontrolled. Your mix is initially balanced, but then you suddenly 'jump' to a head-dominant mix and you are not mixing your voice gradually, but in large intervals.
Comment: My advise would be to sing more open vowels, such as 'oh oh oh oh', while singing it legato. When you are saying 'nay nay nay nay', the vowel slightly restricts your projection, because when singing that vowel, it is easier to lose control of your mix, by 'jumping' to a head-dominant mix and straining your voice by pushing it. This is because when you sing 'nay' very slowly, you can hear that the vowel is initially an open vowel, but 'closes' gradually. By singing legato, you get more control of your gradual mixing, rather than 'nay . nay . nay . nay . nay . nay'.
Comment: Thanks again! I had a revelation haha. I've been doings "Oh oh" and "Ng Ng" exercises and found that I've been lowering my tongue in order to lift my soft palate and try to keep larynx down which was causing issues with resonance and causing tension. I always wondered why I was getting hoarse so often and my tone would get darker when I tried to go higher. I'm currently trying to retrain my tongue to stay forward and find a way to lift the palate without using my tongue

Am I singing in a mixed voice?


Can not reconnect to NX session

Question: I'm no NX expert.
My NXServer (NOMachine) has two running (GNOME) sessions and I can not reconnect to them ?
Even if I stop/start the nxserver daemon, the nxssh sessions are still there.
nxserver --shutdown also fails
Before I do a hard kill, I wanted to know if & how to reconnect them or stop them gracefully.
ADDITION OF LOGS
7:46 is when I failed to connect.
11:57 is when I decide to hard kill

Session: Suspending session at 'Thu Jun  9 00:08:21 2011'.
Info: Watchdog running with pid '29027'.
Info: Waiting the watchdog process to complete.
Session: Session suspended at 'Thu Jun  9 00:08:22 2011'.
Session: Resuming session at 'Thu Jun  9 07:45:37 2011'.
Info: Proxy running in server mode with pid '5038'.
Info: Waiting for connection from '127.0.0.1' on port '5026'.
Info: Aborting the procedure due to signal '1'.
Session: Display failure detected at 'Thu Jun  9 07:46:53 2011'.
Session: Suspending session at 'Thu Jun  9 07:46:53 2011'.
Session: Session suspended at 'Thu Jun  9 07:46:53 2011'.
Session: Terminating session at 'Fri Jun 10 11:57:06 2011'.
Session: Session terminated at 'Fri Jun 10 11:57:07 2011'.
Answer: Maybe useful to check log files for errors or anything?
If you find anything post them here so we have more information to work with.
Hard killing it wont be a problem but always check logs first.
Comment: good idea, just came too late I had to hard kill those tasks.

Can not reconnect to NX session


mongo c++ Bsonbuilder, BSONObj to final c BSON

Question: The underlying goal here is read json with arrays sub documents and whatever in string format  {key:"value", boolkey, true, {subkey: value}, array: [x,y,z] } and not caring to undertake append_int, append_bool and all that jazz.
any way of using the convenient C++ BSONObj, mongo::fromjson BSONObjBuilder to finally output a C bson_t.
ie. along the lines of either
 mongo::BSONObj& query = mongo::fromjson ( szJSON );
 bson_t bson = query.c_obj();

or
 BSONObj Builder builder;
 ... (build, build, build)

 BSONObj obj = builder.obj();

 bson_t bson = obj.c_obj();

given that c++ is built on the c driver one would think that the bson_t is lying within somewhere
Comment: `bson_t` is C API, while `BSONObj` is C++ API. What's the reason to mix them?
Comment: c++ driver is complex, not very stable. c driver is the foundation for many drivers so assume its stable. c bson library on the other hand is awkward to use.
Answer: You can use
bson_t* b = bson_new_from_data(obj.objdata, obj.objsize)

but you will always create objects twice.


WPF window not updating with binding in XAML

Question: Can someone please explain what's going on here? I'm new to WPF and migrating my Forms project to WPF with binding. I'm using AvalonDock but I'm not binding directly to any of the AvalonDock controls. Here's a couple excerpts. I removed a lot for brevity's sake but let me know if you need to see something else.
EDIT: These two StackPanels are just tests... trying to figure this stuff out.
EDIT2: I'm trying to do MVVM eventually; I just need to get a better handle on binding so I know how to structure it.
EDIT3: See bottom of post.
Q: The first StackPanel does not update at all, never mind updating after changes. I've tried setting the DataContext in the StackPanel, Grid and TextBlock. What am I doing wrong?
Q: The second works fine when the parent grid is bound in code behind but only if bound where you see it, not in the MainWindow_Loaded() method. What's different here?
I've read several tutorials as well as plenty of similar questions here but nothing's helping me understand what the difference is here and what I'm missing.
<Window x:Class="TestUIWPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ad="http://schemas.xceed.com/wpf/xaml/avalondock"
        Title="MainWindow" Height="768" Width="1024"
        Loaded="MainWindow_Loaded"
        xmlns:vm="clr-namespace:TestUIWPF.ViewModel"
        >

<ad:LayoutAnchorable Title="Test" >
    <Grid x:Name="gridTest">
        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Horizontal">
                <StackPanel.DataContext>
                    <vm:EntityViewModel />
                </StackPanel.DataContext>
                <TextBlock Text="Label" />
                <TextBlock DataContext="{Binding ActiveEntity}" Text="{Binding Path=Label}" />
            </StackPanel>

            <StackPanel Orientation="Horizontal" >
                <TextBlock Text="Label Again" />
                <TextBlock Text="{Binding Path=Label}" />
            </StackPanel>
        </StackPanel>
    </Grid>
</ad:LayoutAnchorable>

private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
    this.DataContext = this;
    SelectedEntityViewModel = new ViewModel.EntityViewModel();
    ImportEntityXML_Click(null, null); //skips clicking the menus
}
private void ImportEntityXML_Click(object sender, RoutedEventArgs e)
{
    //omitted OpenFileDialog and XmlReader stuff
    xmlreader = new XmlReader(dlg.FileName);
    Entities.Add(xmlreader.ReadEntityFromXML());
    SimulatedEntitySelection(Entities.ElementAt(0)); //haven't built any of the UI stuff for this yet
}

private void SimulatedEntitySelection(Entity ent)
{
    SelectedEntityViewModel.ActiveEntity = ent;
    gridTest.DataContext = SelectedEntityViewModel.ActiveEntity;
}

private void button_Click(object sender, RoutedEventArgs e)
{
    SelectedEntityViewModel.ActiveEntity.Label = "test";
}

Entity and EntityViewModel implement INotifyPropertyChanged and it works just fine with the second StackPanel. The button that calls button_Click() is just for testing the binding. EntityViewModel pretty much just wraps Entity through the ActiveEntity property and helps with reading the collections-of-collections within Entity.
EDIT3:
I've also tried a couple resources. Here's how I did the ObjectDataProvider:
<Window.Resources>
    <ObjectDataProvider x:Key="testVM" ObjectType="{x:Type vm:EntityViewModel}" />
    <vm:EntityViewModel x:Key="SelEntVM" />
</Window.Resources>

<StackPanel.DataContext>
    <Binding Source="{StaticResource testVM}" />
</StackPanel.DataContext>
<TextBlock Text="Label" />
<TextBlock Text="{Binding Path=ActiveEntity.Label}" />

Answer: It does work. You might be probably updating a wrong viewmodel.
Once you define the viewmodel in DataContext, youd have to access it this way:
private void button_Click(object sender, RoutedEventArgs e)
{
    var myModel = (ViewModel.EntityViewModel)(yourStackPanelName.DataContext);
    myModel.ActiveEntity.Label = "test";
}

Comment: Oh man... in all the angry haze in trying to get this to work, I did forget to set this for that first StackPanel. I'll have to take [Michal Ciechan's answer](http://stackoverflow.com/a/27761041/1137728) though as his note on the DataContext inheritance really clarified the entire issue for me.
Answer: Your first stack panel is not working, because the data context is inherited. Therefore, once you change the DataContext of the Grid to the ActiveEntity object, the binding on the text block in the first data context will set the datacontext for the TextBlock to the ActiveEntity on the current datacontext, which would already be the ActiveEntity (therefore ActiveEntity.ActiveEntity) And than try to bind to the Label property on that. E.g. ActiveEntity.ActiveEntity.Label
Before the click, you are setting the DataContext of that window to "this" which I am assuming is not the ViewModel, it is the code behind?
If you are using MVVM,
you should have something like this
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
    SelectedEntityViewModel = new ViewModel.EntityViewModel();
    this.DataContext = SelectedEntityViewModel;
    ImportEntityXML_Click(null, null); //skips clicking the menus
}

Or some other ViewModel which provides all the necessary data.
You nomrally would have a MainWindowView and MainWindowViewModel, at least that is the convention and usually you set the datacontext of the window in the constructor once(you can do it in the Loaded handler), in most cases you shouldn't need to manually change the DataContext of any framework elements in the code behind.
EDIT: Example Code:
MainWindow.xaml
<Window x:Class="SO27760357.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="300" Width="300">
    <Grid>
        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="Label" />
                <TextBlock Text="{Binding ActiveEntity.Label}"/>
            </StackPanel>

            <StackPanel Orientation="Horizontal">
                <TextBlock Text="Label Again" />
                <TextBlock Text="{Binding ActiveEntity.Label}" />
            </StackPanel>
        </StackPanel>
    </Grid>
</Window>

MainWindow.xaml.cs
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        this.DataContext = new MainWindowViewModel();
    }
}

MainWindowViewModel.cs (INotifyPropertChanged omitted for simplicity)
public class MainWindowViewModel
{
    public EntityViewModel ActiveEntity { get; set; }
}

EntityViewModel.cs (INotifyPropertChanged omitted for simplicity)
public class EntityViewModel
{
    public string Label { get; set; }
}

As you can see, I am setting the DataContext of the Window to the MainViewModel, therefore the DataContext(root of all bindings) is the MainViewModel, and each TextBlock needs to first access the ActiveEntity property first, before it can get to the Label proeprty.
THe other option is, that if everything inside the main stack panel you given us, will be bound to ActiveEntity, you can change the DataContext of that StackPanel, binding it to the ActiveEntity, and therefore all of its children datacontext will also be that object.
    <StackPanel Orientation="Vertical"
                **DataContext="{Binding ActiveEntity}"**>
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="Label" />
            <TextBlock **Text="{Binding Label}"**/>
        </StackPanel>

        <StackPanel Orientation="Horizontal">
            <TextBlock Text="Label Again" />
            <TextBlock **Text="{Binding Label}"** />
        </StackPanel>
    </StackPanel>

EDIT 2 - Advice
You should refrain from referencing objects by name as much as possible, and have as little logic in the code behind as possible, if any. For most simple screens there is no need to have anything in code behind other than the initial Binding of the DataContext (if you don't have a window service which creates + sets the DataContext of windows)
Comment: Glad I could help :-) Best of luck with MVVM, 2 quick notes, you should have a MainViewModel/MainWindowViewModel class, and all the clicks should be handled by commands where possible. Will make the code much neater, and more maintainable. http://www.codeproject.com/Articles/274982/Commands-in-MVVM#example1
Comment: Oh man. You hit it right on the head. Thank you! [Chris Eelmaa](http://stackoverflow.com/a/27760862/1137728) did point out my issue with the first StackPanel but you really did clarify the inheritance of the DataContext thing for me.
Comment: I'd upvote you again if I could. I knew my approach was kinda dirty but I was just going with it for the sake of figuring something out. Chris' answer resolved my problem for this "dirty" code but setting the DataContext for my entire MainWindow (which is substituting for the View I'll eventually build) ensures I can just move all this code to a real View once I get around to it... I've been trying to balance "just get it to work" with "plan for the future" while learning WPF, XAML and binding. Thanks again!


How can I verify the linear hypothesis in a multiple logistic regression using SAS?

Question: I have a multiple logistic regression where 2 of my independent variables are continuous. The rest are dichotomous. I am supposed to verify the linear hypothesis for the continuous variables. Is there a way to do this using SAS?
Answer: Sure, one way to do this is to introduce nonlinear terms into the model, and test their significance. A good way to do this is with regression splines. First, you need to create spline variables for your continuous predictors. This can be done using PROC TRANSREG or PROC IML. PROC TRANSREG offers various spline transformations, such as natural cubic splines. You will need to specify the number, and location, of knots. A common approach is to place knots at quantiles of the data distribution.  If the spline terms are statistically significant, it suggests that there might be a non-linear relationship between the continuous variable and the outcome. You should also check the model's overall fit and compare it to the linear model. And as always plotting the predicted probabilities or log odds against the continuous variable can provide a visual assessment of linearity.
PROC IML offers a higher degree of flexibility and control but at the cost of increased complexity. Using PROC IML for spline regression involves manually setting up the spline basis functions, which requires a solid understanding of matrix programming and the mathematical underpinnings of spline models. Additionally, implementing the logistic regression model itself, including the optimisation of the likelihood function, needs to be done manually in PROC IML. This approach provides the advantage of customisation and the ability to tailor models to specific analytical needs, but it is more time-consuming and requires advanced programming skills.
Answer: In R:
require(rms)
f <- lrm(y ~ rcs(x1, 4) + rcs(x2, 5), data=mydata) # restricted cubic spline, 4 or 5 default knots
anova(f) # gives test of no linearity (separate and combined x1,x2)

Comment: This has been flagged as low quality, probably due to its length and OP asking for SAS. While I disagree, perhaps, Frank, you can add a bit of context to that.


Alternative tests for Hotelling's two-sample T-test

Question: I have a bunch of vectors from two groups, $X$ and $Y$, and each vector in either $X$ or $Y$ groups has $m$ elements. Now I have $X_{1},\ldots,X_{8}$ and $Y_{1}, \ldots, Y_{8}$ in each group, and would like to compare/test the difference between the two groups. From the Wikipedia page of Hotelling's $T$-squared distribution, the assumption for the samples are two independent multivariate normal distributions with the same mean and covariance.
My question is that, when some of the assumptions of Hotelling's $T$ test are not satisified, shall I continue to use it or there are alternative more robust approaches to choose? For example, I only have (in each group) 8 samples, even though the number of elements in $X_{i}$ ($Y_{i}$) is large (say $50$), and they're not necessarily normal.
Answer: Since both your $X$ and $Y$ are rank deficient, you cannot directly compute the Hotteling $T$ because the $W$-matrix is singular.
So, you have to replace your $X$ and $Y$ by their reduced rank approximations, which I'll denote $X^k$ and $Y^k$.
where
$$X^k=(X-\bar{X})V[(X-\bar{X})/\sqrt{n_x-1}]$$
where $\bar{X}=n_{x}^{-1}\sum_{i=1}^{n_x} X_i$ and $V[Z]$ is a matrix whose column contain the left singular vector of $Z$ (ditto for $Y$).
Then, based on the reduced rank approximation of your data, you can compute a reduced rank Hotteling $T$. Finally, replace $p$ in all formulae by the rank of $X^k$ (in your case 8).
Now, since you suspect your $X$ and $Y$ to be contaminated by outliers,
you might as well also replace the algorithm used to obtain $X^k$ by a robust counterpart (one such algorithm is ROBPCA, You'll find a good R implementation of ROPBCA in the function PcaHubert here. You'll
find more details on page 26 of this note).


Flutter Mockito. Failing to mock

Question: I am trying to use mockito in my project to test an API. Here is a small snippet code under organization_test.dart. I will only provide up until the error line as it is the only concern.
class MockOrganizationRemoteDataSource extends Mock implements OrganizationRemoteDataSource {}

void main(){
 late final MockOrganizationRemoteDataSource mockOrganizationDataSource;
 late final IOrganizationRepository iOrganizationRepository;
 final tOrgName = "someOrgName";

 setUp((){
  mockOrganizationRemoteDataSource = MockOrganizationRemoteDataSource();
  iOrganizationRepository = IOrganizationRepository(mockOrganizationRemoteDataSource);
 });

 test("Should fetch the organization",() async {
  when(mockOrganizationRemoteDataSource.getOrganization(tOrgName)) // Getting ERROR on this line
   .thenAnswer(
      (_) async => Response(
       requestOption: RequestOption(
        path: <Some url in here >
        data: <Some json response here >
        responseType: ResponseType.json)
      ),
   );

   final result = await iOrganizationRepository.fetchOrganization(tOrgName);

   ...
   ... // some more code here

 });
}

Then I get error is type 'Null' is not a subtype of type 'Future<Response<dynamic>>'
I was expecting that if I use mock I can call the getOrganization method from the mockedDataSource and pretend to answer a response. Yet upon debugging this, I always ending up referencing to the Un-mocked class which is the OrganizationRemoteDataSource resulting the null value.
BTW I'm using flutter with null-safety enabled and Dio.
Comment: Did you follow the null-safety instructions and call `@GenerateMocks`?
Comment: Apparently, I have not and doesn't know that. Will check now. Thanks! I'll ask again if  I still get the same error.
Comment: Thanks @jamesdlin! It worked using the @GenerateMocks.
Answer: Thanks to jamesdlin's comment I was able to resolve this:

Add @GenerateMocks annotation to the void main()

@GenerateMocks([OrganizationRemoveDataSource])
void main(){
...
}

Removed the MockOrganizationRemoteDataSource class and used the build_runner to allow Mockito to generate the annotated GenerateMocks.

UPDATE:
Due to the intricacy of using Mockito in a null-safety dart. I came across a great library that works as alternative named Mocktail. You can see the library here https://pub.dev/packages/mocktail.

Flutter Mockito. Failing to mock


synchronous method calls not working with promise - nodejs

Question: Iam creating an http server. before creating the server i check db connection. if db is down..the check method will be called again until its connected. after this i start the server. after starting the server i need to check few configuration settings. server starts properly.  I wrote a code to call 3 configuration settings verification code one after the other using then. However 2 methods are executed simultaneously and last one is not called at all.
//to check connectivity to another app
function checkconfig1() {
    return request.post({
        headers: {
            'content-type': 'application/json'
        },
        url: url,

    }, function(error, response, body) {

    if (body == 'success') {
        //config 1 is verified
        console.log("config 1 is verified")

    }
    if (error) {
        console.log("config 1 is not correct")
        return Promise.delay(2500).then(checkconfig1);
    }
});

 }
 function checkconfig2() {

return request.get({
    headers: {
        'content-type': 'application/json'
    },
    url: url,

}, function(error, response, body) {

    if (error) {
        console.log("config 2 is not correct")
        return Promise.delay(2500).then(checkconfig2);
    } else {
        console.log("config 2 is verified")
    }

});

 }

     function checkconfig3() {
        var cmd = 'somecommand';
        return exec(cmd, function(error, stdout, stderr) {

            if (error) {
                console.log("config 2 is not correct")
                return Promise.delay(2500).then(checkFonts);
            } else {
                console.log("config 2 is verified")
            }

        });
     }

 module.exports = function() {

    return checkconfg1().then(checkconfig2).then(checkconfig3());
    //return checkFonts();
 }

Am I doing it correctly. Can anyone explain how to do this? Thanks
Comment: Why the down vote? it will be better if some explanation is given on down voting
Answer: I've modified your code a bit.
Can you try this:
function checkconfig1() {
    return new Promise(function (resolve, reject) {
        request.post({
            headers: {
                'content-type': 'application/json'
            },
            url: url,

        }, function (error, response, body) {

            if (body == 'success') {
                //config 1 is verified
                console.log("config 1 is verified")
                return resolve();

            }
            if (error) {
                console.log("config 1 is not correct")
                return resolve(Promise.delay(2500).then(checkconfig1));
            }
        });
    });
}
function checkconfig2() {

    return new Promise(function (resolve, reject) {
        request.get({
            headers: {
                'content-type': 'application/json'
            },
            url: url,

        }, function (error, response, body) {

            if (error) {
                console.log("config 2 is not correct")
                return resolve(Promise.delay(2500).then(checkconfig2));
            } else {
                console.log("config 2 is verified")
                return resolve(response);
            }

        });

    });

}

function checkconfig3() {
    var cmd = 'somecommand';
    return new Promise(function (resolve, reject) {
        exec(cmd, function (error, stdout, stderr) {
            if (error) {
                console.log("config 2 is not correct")
                return resolve(Promise.delay(2500).then(checkFonts));
            } else {
                console.log("config 2 is verified")
                return resolve();
            }

        });
    });
}

module.exports = function () {
    return checkconfig1().then(checkconfig2).then(checkconfig3);
    //return checkFonts();
};

Comment: Thanks for the edit. I tried the solution. now it calls all the three. but again simultaneously. rather than one after the other. first config is not set so it shows error message continuously but in the start it shows all three consoles and then the error message for the first config
Comment: That's strange. Are there any other part of your application that could log the same?
Comment: No. Only here I log it
Comment: I have edited the code and that works. but not sure how it works. trying to understand the concept. anyway thanks for the solution. am accepting the answer. however please verify my edit and let me know