Is there an advantage to using moving average versus removing outliers?

Question: I have a dataset and for each hour there is 3 readings (sometimes missing and sometimes clearly an outlier). I am trying to find the mean of the entire dataset for the parameter. It has been suggested to me to take the mean of each hour and then the mean of the entirety  of those means as this will help minimize the contribution of single outliers AND it was suggested to me to take the mean of the entire set and ignore the time.
Those two methods seem to have very similar results and similar standard deviations. However, if I trim out the outliers some datasets are significantly different than this (these are usually one observation that is more than 4 times the others etc and I think due to an observation error) so I think removing these outliers would be a good thing. So what is the advantage of a moving average? Is it inapropriately used here or am I misunderstanding it?
My dataset sort of looks like below:
Hour| observation
0              | 5
0              | 6
0              | 5.6
1              | .
1              | 4
1              | 4.8
2              | 5.1
2              | 5.4
2              | 498
.....
Comment: How did you get these data and what are they? It seems like measurement errors if they are "readings" of something. http://en.m.wikipedia.org/wiki/Outlier Given the variance of the seemingly "correct" observations "4 times" seems too much.
Answer: Removing 'outliers' is a good idea IF the outliers are properly described as erroneous readings, mistakes or they are known to be misleading. However, to ascribe one of those properties to the outliers requires something other than just inspection of the data. Were the three readings at each time point intended to allow assessment of whether the measurement 'worked' or are they intended simply to reduce the influence of measurement variability? If it was the former then you should be considering the known properties of the test and measurement system when deciding what causes outliers. Missing values and odd things like the decimal point without numerals may be indicative of a 'fragile' measurement or recording system that can be expected to yield outliers that are mistakes.
If a four times range for repeated measurements is plausibly just a result of the underlying variability of the values or of the measurement method then do not remove them. Perhaps the median of the distribution, which is less strongly affected by outliers, will serve instead of the mean.
If you have lots of data then you are in a good position to work out whether the outliers are bad values, because you can plot the distribution of the readings.
Comment: It's an instrument that is known to make lots of errors and have missing values.  I am unsure and will set up a meeting with the researcher thank you.


If a composition of linear transformation is invertible, then are each linear transformations invertible?

Question: If $S$ and $T$ are linear transformations from set $V$ to $V$, which is a finite-dimensional vector space, and if the composition $ST$ is invertible, how can we show that $T$ is one-to-one, therefore, invertible, and also that $S$ is invertible?
Answer: We have $ST$ is invertible if and only if $\det(ST)=\det(S)\det(T)\ne0$ so $\det(S)\ne0$ and $\det(T)\ne0$ and then $S$ and $T$ are both invertible.
Answer: Another way:
Take $\bf x$ and $\bf y$ such that $T{\bf x} = T{\bf y}$. Apply $S$. Then $ST{\bf x} = ST{\bf y}$, and we get ${\bf x} = {\bf y}$. In general, $\ker T \subset \ker ST $. So $T$ is injective, hence bijective (using finite dimension).
Now, let ${\bf z} \in \mathcal{V}$. Exists ${\bf x}$ such that $ST{\bf x} = {\bf z}$. Then, ${\bf y} = T{\bf x} \in \mathcal{V}$ satisfies $S{\bf y} = {\bf z}$, and $S$ is onto. So $S$ is bijective (using finite dimension).


Sort de um arquivo .csv à partir da coluna numérica

Question: Tenho o seguinte arquivo:
es;548
la;1832
primera;35
vez;107
que;2598
hago;15
un;878
pedido;642
y;1713
creo;83
ha;207
funcionado;1
muy;371
bien;257
los;1054
precios;88
fuesen;11

E gostaria de ordená-lo a partir da coluna numérica, do maior para o menor. Tentei isso, mas nao esta dando certo:
with open ("FREQ.csv", "r") as f:
    dados = f.read()
    colunas = dados.split(";")

    print (sorted (dados[1], key = int, reverse = True))

Comment: Um arquivo CSV é um arquivo que tem um numero fixo de colunas e várias linhas que seguem a mesma estrutura. No seu caso parece ser apenas um arquivo texto com apenas uma linha que tem dados separados por ponto-e-virgula. Pode colocar na pergunta um exemplo de saída correta dessa linha do arquivo?
Comment: Esta certo. Ele colocou apenas uma linha do arquivo CSV.
Comment: Mas o que você quis dizer com  'não esta dando certo', o que, de fato, acontece?
Comment: Eu tenho esta mensagem:

/usr/bin/python3.5 /home/janaina/Bureau/Lexique/Python/sort_freq.py
Traceback (most recent call last):
  File "/home/janaina/Bureau/Lexique/Python/sort_freq.py", line 7, in
    print (sorted (dados[1], key = int, reverse = True))
ValueError: invalid literal for int() with base 10: 's'

Process finished with exit code 1
Comment: @Pagotti eu tenho exatamente um arquivo CSV (nao fui eu que o criei), o problema é que nao consigo colocar aqui do jeito que ele é (duas colunas).
Comment: @pitanga você não precisa colocar o arquivo exato na questão. Apenas atualize a pergunta com um exemplo de dados (pode ser 2 linhas do arquivo) e um exemplo de como você espera que seja a saída. A forma como você está colocando a questão está confusa.
Answer: Utilize o módulo csv (https://docs.python.org/3.6/library/csv.html)
Realizei os testes utilizando python3.
import csv

with open ("freq.csv", "r") as f:
    dados = csv.reader(f, delimiter=";")
    # Com o arquivo lido pelo módulo csv é possível convertê-lo em uma lista
    lista = list(dados)
    # Ordenação da lista gerada considerando o segundo elemento em ordem decrescente.
    lista_ordenada = sorted (lista, key = lambda dado: int(dado[1]), reverse = True)

    for x in lista_ordenada:
      print(x)

Answer: Uma maneira mais simples de fazer isto é separar todas as linhas do csv \n e após isto separar todas as colunas do csv ;. Após agregar todas as linhas e colunas em uma lista basta dar um sort na coluna esperada, você pode usar o lambda e "personalizar" o método de ordenação, segue:
colunas = list([dado.strip().split(";") for dado in dados.strip().split("\n")])
colunas.sort(key=lambda linha: int(linha[1]), reverse=True)
print(colunas)

ou ainda em vez de dar o colunas.sort... você pode usar o sorted:
print(sorted(colunas, key=lambda linha: int(linha[1]), reverse=True))


Exchange ActiveSync certification error

Question: I have a problem when setting up a MS Outlook 2013 client. I'm trying to connect to the MS Exchange ActiveSync email server. I have installed the certificates for the mail.ourdomain.com, but there's also a problem with autodiscover.ourdomain.com, which doesn't have a certificate.
I can add the account, it says "Congratulations! You have successfully added the account" or something like that, then it asks me to restart Outlook, which I do, and then it displays and error, that it cannot connect to the proxy error, because of the certificate problem.
Any suggestions ?
Answer: You should be using a SAN certificate and adding the appropriate domains to it, such as mail.domain.com, autodiscover.domain.com, etc.
https://www.digicert.com/subject-alternative-name.htm

Exchange ActiveSync certification error


MS SQL Server procedure from php fails with 500 when returning query is not empty

Question: I have a stored procedure, which runs ok in Management Studio.
Then I have a php code, where I call it:
$sql = "EXEC MyProc @Param1=1, @Param2 = 2, @Param3 = '3'";
$stmt = sqlsrv_query($conn, $sql);

if ($stmt === false) {
    die(print_r(sqlsrv_errors(), true));
}

while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC))
{
    // and so on ...
}

it runs ok, with some set of parameters, that return 0 records (I simply get an empty array).
But when I change the params to return values, I get 500 error in JavaScript, which is calling the PHP script.
Here's how it's called in JS:
dojo.xhrPost({
    url: "/mySuperPhpCode.php",
    handleAs: "text",
    content: { Param1: 1, Param2: 2, Param3: 3 },
    load: function (response, ioArgs) {
        // some actions
    },
    error: function(response, ioArgs) {
        // some actions
    }
});

I know, that 500 error can point to many troubles, but I'm out of ideas for now.
My configuration: IIS 7.5, PHP 5.3.19. Ask, if any additional details needed.
Upd 1:
The code for processing results (inside while-loop):
$rez = array();
foreach ($row as $key => $value) {
    if (($key=="SomeDateFieldName1"||$key=="SomeDateFieldName2"||
         $key=="SomeDateFieldName3"||$key=="SomeDateFieldName4"||
         $key=="SomeDateFieldName5") && !is_null($value) ){
        $d=get_object_vars($value);
        $d=$d["date"];
        $zn=$d;
    } else {
        $zn=$value;
    }

    $rez[$key] = $zn;
}

$t[]=$rez ;

$t - will be returned from php-script.
One more addition: this php-file contains few calls to procedures (incoming parameters determines, which one will be called). Some of them work perfectly (in both cases: where no results and when there some records returned) and being processed with this code with no problems.
Comment: The 500 error isn't coming from SQL, or you'd see it when there were no results as well. I'm assuming, then, that the error is in how you handle the results when you get them. I'd revisit the contents of your loop on sqlsrv_fetch_array, because you might be handling the returned values incorrectly.
Comment: Hello, I wasn't thinking that it's SQL Server. Probably, I had to be more clear creating a title :) Anyways, I've updated the post with the code and some comments. Once more to clarify: I get this error only, when the procedure returns results. When it's empty, It goes with no errors.
Answer: Found it!
eemikula, you was right. The problem was in the result-processing section. I was trying to call get_object_vars on non-object value (in all previous cases, in the tables with the given "SomeDateFieldNameN" were DateTime objects, but in this table it was a varchar), so I added a check for it:
is_object($value)


MS-Access cant find unique index for the ref field of the primary table

Question: This is my task... please help!
Set up Referential Integrity between the sec0808_departments table and the
sec0808_employees table. The sec0808_depatrments table contains a list of all the valid values of the dept_code field.
sec0808_departments design view

sec0808_employees design view

Here is my code:
alter table sec0808_departments
add constraint fk_sec0808_departments_dept_code
foreign key(dept_code)
references sec0808_employees(dept_code);

Here is the error:

Thank you for any assistance!
Best :-)
Answer: Simply switch the tables in ALTER command to assign the foreign key in the Employees table referencing the Department table's primary key. Right now you are attempting to add a foreign key to Departments when it already maintains a primary key!
alter table sec0808_employees
add constraint fk_sec0808_departments_dept_code
foreign key(dept_code)
references sec0808_departments(dept_code);

This way Departments (unique dept_code on each row) to Employees (potentially repeating dept_code for employees who share same department) make a one-to-many relationship.


Fetching from AWS Lambda retrieves old data

Question: I have a serverless-based, isomorphic next.js app that fetches data from a CDN that it uses to render the website. It does this by what I might've thought was a fairly innocuous method:
const data = d3.csv(`https://cdn.example.com/data/my_data.csv?time=${Date.now()}`);

This retrieves the data nicely enough, but it retrieves stale data—at times many hours old. The same code, when it runs on the client side, happily fetches up-to-date data.
Relevant other information:

This happens on a number of computers (and I have caching disabled on my development browser) so it's not a local browser issue.
I do not have the site itself behind a CDN, and the data file's CDN updates fairly quickly (when I navigate to the file directly, I see the most recent update, and the client-side version has no problem accessing the newer file).
I have added a (theoretically) cache-busting query string to no avail.
I have gone so far as to remove and redeploy the entire app, and I still see the stale data.

Why is this happening, and more importantly: how can I get AWS Lambda to see current copies of the data file?
Comment: The data that you're trying to extract via fetch, is it behind a CDN or not? (wasn't clear from the explanation). Please note that CDNs apply caching as well. If the data is behind a CDN, you may just need to flush the cache on the CDN (via the CDNs settings).
Comment: Is `const data = ...` inside your handler function, or is it global?
Comment: `const data` is inside the handler function. Also, even if it were something global, surely deleting and redeploying the app clears even global variables?
Comment: to isolate the issue, can you log the content of `data` in cloudwatch? and see if the result is always the same even when the new data is available? And probably log the url itself (with the time query)
Answer: A couple of suggestion comes to mind:

As it is currently stated, the Date.now() function is never executed, c.f. the output of  ...time=${Date.now} vs ...time=${Date.now()}
What is the expected format of the time parameter? According to the documentation, the Date.now() function

returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC
Comment: Sorry, I mistranscribed the code—it uses Date.now(). I'll update. The parameter isn't used, it is just there to ensure the URL is always unique.


Propagate a custom event from a UICollectionViewCell

Question: I have a custom UICollectionViewCell with a button inside it. When I tap the button, an event is fired inside that subclass. I want to then trigger an event on the UICollectionView itself, which I can handle in my view controller.
Pseudo-code:
class MyCell : UICollectionViewCell {
    @IBAction func myButton_touchUpInside(_ sender: UIButton) {
        // Do stuff, then propagate an event to the UICollectionView
        Event.fire("cellUpdated")
    }
}

class MyViewController : UIViewController {
    @IBAction func collectionView_cellUpdated(_ sender: UICollectionView) {
        // Update stuff in the view controller
        // to reflect changes made in the collection view
    }
}

Ideally, the event I define would appear alongside the default action outlets in the Interface Builder, allowing me to then drag it into my view controller code to create the above collectionView_cellUpdated function, similar to how @IBInspectable works in exposing custom properties.
Is there any way to implement a pattern like this in native Swift 3? Or if not, any libraries that make it possible?
Answer: I don't understand your question completely but from what I got, you can simply use a closure to pass the UIButton tap event back to the UIViewController.
Example:
1. Custom UICollectionViewCell
class MyCell: UICollectionViewCell
{
    var tapHandler: (()->())?

    @IBAction func myButton_touchUpInside(_ sender: UIButton)
    {
        tapHandler?()
    }
}

2. MyViewController
class MyViewController: UIViewController, UICollectionViewDataSource
{
    //YOUR CODE..

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
    {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! MyCell
        cell.tapHandler = {
            //Here you can do your custom handling
        }
        return cell
    }
}

Let me know if you face any issues.
Comment: Hm, that would probably work too. I hadn't thought about using closures in that way.
Comment: Closures are actually more simple and easy to use than the delegate pattern.
Comment: @PGDev Totally agree...yet it's still hard to remember the to use them...and this is a lovely example to prompt the memory
Answer: Best thing to do is to make a custom protocol for your custom cell class
protocol CustomCellProtocolDelegate {
   func custom(cell: YourCellClass, hadButton: UIButton, pressedWithInfo : [String:Any]?)
}

Make this cell class have this protocol as a peculiar delegate, and to trigger this delegate:
class YourCellClass: UICollectionViewCell {

   var delegate : CustomCellProtocolDelegate?

   var indexPath : IndexPath? //Good practice here to have an indexPath parameter

   var yourButton = UIButton()

   init(frame: CGRect) {
      super.init(frame: frame)
      yourButton.addTarget(self, selector: #selector(triggerButton(sender:)))
   }
   func triggerButton(sender: UIButton) {
      if let d = self.delegate {
         d.custom(cell: self, hadButton: sender, pressedWithInfo : /*Add info if you want*/)
      }
   }

}

In your controller, you conform it to the delegate, and you apply the delegate to each cell in cellForItem: atIndexPath:
class YourControllerThatHasTheCollectionView : UIViewController, CustomCellProtocolDelegate {

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "identifier", for: indexPath) as! YourCellClass
        cell.delegate = self
        cell.indexPath = indexPath
        return cell
    }

   func custom(cell: YourCellClass, hadButton: UIButton, pressedWithInfo : [String:Any]?) {

        //Here you can process which button was selected, etc.. and apply your changes to your collectionview

   }

}

Best practice is to pass the cell's indexPath parameter in the delegate method inside of pressedWithInfo. It saves you the trouble of calculating which cell actually was pressed; hence why i usually add an indexPath element to each of my UICollectionViewCell subclasses. Better yet, include the index inside the protocol method:
    protocol CustomCellProtocolDelegate {
       func custom(cell: YourCellClass, hadButton: UIButton, pressedAt: IndexPath, withInfo : [String:Any]?)
    }

    func triggerButton(sender: UIButton) {
       if let d = self.delegate {
           d.custom(cell: self, hadButton: sender, pressedAt: indexPath!, withInfo : /*Add info if you want*/)
       }
    }

Comment: Thanks, this lets me do what I was trying to. However, I'm still curious whether it's possible to expose custom events to Interface Builder.
Comment: Interesting, I haven't found a way yet. However, it could be, potentially. Since the action/executable type `(()->())` can be parameter of a class, it could technically be detectable to the IB.. But that doesn't seem to be the case so far in my test. Will keep looking


android retrofit add custom header

Question: i using retrofit2 and want add some header using OkHttp3 addInterceptor
but not working
this is my code
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
    httpClient.addInterceptor(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
            Request original = chain.request();
            Request request = original.newBuilder()
                    .removeHeader("Authorization")
                    .removeHeader("Content-type")
                    .removeHeader("User-Agent")
                    .addHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8")
                    .addHeader("Accept-Language", "en-US")
                    .addHeader("User-Agent", ApiConfig.userAgent)
                    .method(original.method(), original.body())
                    .build();
            return chain.proceed(request);
        }
    });
OkHttpClient client = httpClient.build();

    if (apiInterface == null) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(ApiConfig.baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(client)
                .build();
        apiInterface = retrofit.create(ApiInterface.class);
    }
    return apiInterface;

please help me.
kind regards
Comment: follow this link:
https://stackoverflow.com/questions/32963394/how-to-use-interceptor-to-add-headers-in-retrofit-2-0
Comment: not working yet
Comment: put your logcat overthere
Answer: Try this if it helps
RestAdapter.Builder builder = new RestAdapter.Builder()
    .setRequestInterceptor(new RequestInterceptor() {
        @Override
        public void intercept(RequestFacade request) {
            request.addHeader("Accept", "application/json;versions=1");
            if (isUserLoggedIn()) {
                request.addHeader("Authorization", getToken());
            }
        }
    });

Comment: its retrofit 1.9 but am using v2

android retrofit add custom header


Installing Python Modules on Windows with Multiple Python Versions

Question: I have 2 Python 3.x versions installed on my Windows machine.
Python 3.8.x
Python 3.9.2

I want to install modules on the python 3.9 installation.
pip install paramiko

The command returns saying Requirement already satisfied.
However, paramiko is installed in Python 3.8.x but not Python 3.9.2.
I tried the following command which also didn't work.
python3.9.2 -m pip install paramiko

How can I install a module under the Python 3.9.2 version?
Comment: How do you typically run code with the 3.9 installation?
Comment: You could open a command prompt in the same directory as the `3.9` installation and run `python.exe -m pip install paramiko`.
Answer: Resolved with below change in command
python3.9 -m pip install paramiko


stop js script when scroll or click

Question: I am using this script to make an autoscroll on my website. When the user opens the website, theres a logo and after an amount of time, the browser scrolls down.
  $(document).ready(function () {
    setTimeout(function(){
       $('#logoclick').trigger('click');
    }, 3100); });

the problem is, that everytime the user enters the website, this script runs, which is bad, because, if the user enters the page on an anchorpoint (e.g: mypage.com#contact) the first thing happens is, that the browser goes to top of the page and then scrolls down.
The question is, how could I just disable the script, e.g. when the user scrolls or clicks?
Thank you!
AD
Answer: You could put this code within an if statement which checks if an anchor is present. If so, don't execute the code.
See here for how to do that.
EDIT
If you also want to stop the animation when the user scrolls, even when no anchor is present, you can do so using a jQuery stop() function in javascripts onScroll event.
See this for the on scroll event.
See this for the rather self-explanatory stop method.

stop js script when scroll or click


Start and Stop Tomcat from java code

Question: Based in a code I saw in Stackoverflow and other pages on Internet, I've created a method to stop and start tomcat at the moment I'll run a process in my system because I need to clean memory in my OS, I use System.gc() but still not enough to free memory, this is the code:
Global declaration:
private String server = "localhost";

Method to stop-start tomcat:
public void tomcat(){
    try{
        Socket s = new Socket(server,8005);
        if(s.isConnected()){
            PrintWriter print = new PrintWriter(s.getOutputStream(),true);
            print.println("SHUTDOWN"); /*Command to stop tomcat according to the line "<Server port="8005" shutdown="SHUTDOWN">" in catalina_home/conf/server.xml*/
            print.close();
            s.close();
        }
        Runtime.getRuntime().exec(System.getProperty("catalina.home")+"\\bin\\startup.bat");  /*Instruction to run tomcat after it gets stopped*/
    }catch (Exception ex){
        ex.printStackTrace();
    }
}

The code line to start tomcat works perfectly, but no the instructions to stop it because, when I instance the socket, gives me the following message: Connection refused: connect.
How can I solve this? or, is there another way to stop tomcat?
Thanks in advance.
Comment: if you run `netstat ` can you see that 8005 is open?
Comment: Sounds like a firewall issue
Comment: @user2310289 I've run `netstat -a` to see if the port was already open, but nothing, even when I was running my application, the results were the same.
@MadProgrammer I added the port as TCP in the firewall, but I still having the same problem. Even I restart my pc to validate if changes were applied.
Comment: check your server.xml to see whether this service is started
Answer: public static void shut_server(String lien)
{
      try {

        Process child = Runtime.getRuntime().exec(lien+"/shutdown.sh");
        System.out.println("Serveur est atteins");
    } catch (IOException ex) {
        Logger.getLogger(Installation.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println("erreur de demarrage");
    }
}

lien = path to your tomcat bin file
for example - /home/zakaria/Téléchargements/apache-tomcat-8.0.21/bin
Comment: Add proper code tags and some text with an explanation.
Answer: I had similar issue. I was getting the "Connection refused: connect" error message on creating the socket.
However, my use case is different from the one posted by Vlad. When the Tomcat server is starting up, my app is checking availability of some resources and if they are not, it needs to shutdown the server.
I added a 30 seconds sleep just before the line creating socket:
try {
    Thread.sleep(30000);
}
catch (Exception excp) {}
Socket socket = new Socket("localhost", port);

and it started working.
I think when Tomcat is starting up it needs some time to make the shutdown port ready to work.
The selection of 30 seconds is arbitrary, it could be probably shorter.
FYI, my Tomcat is running as Windows service.

Start and Stop Tomcat from java code


Can I use parfor within a parfeval in Matlab R2019b and if yes how?

Question: I'm encountering an issue with my MATLAB R2019b GUI project. I'm trying to display two sets of 4DCT (Four-Dimensional Computed Tomography) images simultaneously. Each set contains 10 CT volumes. While displaying the first case(two sets), I want to asynchronously load additional sets in the background. My approach involves using parfeval(@select_data, x, data{idx}) for each 4DCT, where select_data is a function utilizing parfor to read the 10 DICOM volumes.
When I run select_data independently, it performs well, utilizing all available workers efficiently (e.g., 12 workers). However, when I use parfeval, only one additional worker is utilized, leading to slower loading times (about 30-40 seconds per 4DCT). Also it causes lag in the main thread, even though I expect multiple workers to be employed for the loading process and the rest available for my main.
Here are the server specs I have access to:
CPU(s): 24
Thread(s) per core: 2
Core(s) per socket: 6
Socket(s): 2

Memory: 70GB
I've attempted to limit the number of workers to 8 in the parpool, leaving 4 cores free to handle the main GUI thread, but the lag persists.
It's possible that the issue lies with the usage of parfor within parfeval, which might not be leveraging all available workers as expected?
Edit: Using parfor within a parfeval is not possible, parfor will be processed as a normal for-loop if called by parfeval.
Answer: You certainly can use parfor in the functions invoked using parfeval. It is difficult to do this in a non-trivial manner in R2019b though. In later releases of MATLAB (>=R2020a), you can use a thread pool inside each local process worker. It's awkward to set up though, and even then there might be challenges getting everything you need running on thread-pool workers.
The approach I would explore is converting your select_data so that you can run it directly in chunks inside parfeval. I.e. instead of something like this
function out = select_data(in)
    parfor i = 1:n
        out(i) = dostuff(i);
    end
end

You somehow work out how many iterates you need and then effectively call the guts of the parfor loop directly from the client via parfeval, like this:
for i = 1:n
   fut(i) = parfeval(@dostuff, 1, i);
end
fetchOutputs(fut);

This also would let you use e.g. afterAll on the array of futures to do something else asynchronously once the work is all finished.
Comment: There was a recent video blog on this exact topic here: https://blogs.mathworks.com/videos/2024/03/20/switching-a-parfor-to-a-parfeval/
Comment: I tried something like this but still have the performance issues during the loading in the background. I dont necessarly need the speed up anymore for the subsequent volumes but I need to ensure that my GUI remains responsive. For instance, users should still be able to scroll through slices and switch phases seamlessly while working with the initially opened case. And currently I dont understand how parfeval has an influence on my main thread(scrolling etc) because in my understanding it should be a completly new thread and also the variables used are not shared with the main thread.
Comment: Had a conversion with one of the developers for the parallel computing toolbox and sadly it is not possible to use a parfor within a parfeval. The parfor then will be evaluated/processed in a sequential manner. But still thanks!
Link to his answer:
https://de.mathworks.com/matlabcentral/answers/2099541-can-i-use-parfor-within-parfeval-in-matlabr2019b-and-if-yes-how#comment_3112246

PS: I hope it was not a problem to ask this question in two different forums, just though the chances for an answer would be higher.
Comment: @max_hid Hm, Damian's comment isn't quite the full story. It _is_ possible as I outline above, but it is currently pretty awkward. It's definitely not possible (without a MATLAB Parallel Server license) in R2019b.
Answer: I expect nesting parallel structures to not yield any additional speed-up. You can assign a number of workers to the outer parallellisation, which doesn't leave any room to use even more workers from outside the current, already parallel, outer level. In any case, it's recommended to parallelise the outermost loop in case of nested loops, I expect the same to hold true for nesting other parallellisation structures.
In case your outer structure only contains two elements (i.e. your idx is 2), you might be better off by serially evaluating that loop and using parallellisation on the reading, since you've already verified that that does indeed use more workers and thus reduces execution time.
There's a bunch of background links on how and when to leverage parallellisation in this answer of mine as well as this one.
There's an example in the parfeval docs that updates a UI, that might be worth a try. Alternatively, you could try spmd() to parallellise your reading and assign a limited number of workers to each SPMD. Given you have two sockets with 6 workers each, I'd set the number of workers to 6, leaving a single socket for the main thread:
parpool(6)
spmd
    your_code()
end

Comment: To run parallel tasks asynchronously you might want to [`createJob()`](https://uk.mathworks.com/help/parallel-computing/createjob.html) to build up a bunch of tasks and then dispatch them to the local MATLAB cluster, with or without waiting on them to finish before doing something else
Comment: The problem with serially evaluating the loop over all my cases and using parallellisation(parfor) on the reading is that I'm blocking my main thread doing that. So I though using parfeval would be a good opportunity. And blocking the main thread would be an absolute no-go for my project. Is there any way of making sure that parfeval is not influecing my main thread? Because I could live with slower loading times but not with lagged visualization.


Problema com Git/Github - arquivos grandes

Question: estou com um probleminha ao criar e subir um repositório git.
Ele tentou subir um arquivo maior que 100.0MB e o GIthub me notificou a restrição. Porém, fui na pasta e apaguei o arquivo. Tentei subir novamente e ele me indica o mesmo erro, mesmo nao havendo o arquivo lá.
Tentei procurar na rede sobre isso e de várias formas e tentativas, não consegui resolver. Alguém pode me ajudar? =)
Comment: você removeu o arquivo, tudo bem, mas deu commit aplicando a remoção? basicamente você precisa comitar a mudança, ou o github vai achar que o arquivo ainda existe.
Comment: Sim, dei o commit.
Answer: Amigo realmente tem alguns complicadores, segue um texto de outra resposta para uma pergunta parecida com a sua:
O Git tem uma grande dificuldade com arquivos grandes (>50MB) e uma grande perda de recursos com repositórios grandes (>10GB).
1) Se você está rodando seu próprio git, vai ter que configurar nele um tamanho máximo pros arquivos do repositório. No github, o tamanho máximo de arquivo é 100MB. Mas com 50MB ele já te dá um warn.
2) Git não foi feito pra versionar arquivos binários. É melhor usar um rsync e copiar pra outro lugar.
3) Tem uma solução chamada git-annex para fazer a gestão de arquivos grandes. Dà uma olhada em http://git-annex.branchable.com/
Fonte: Manusear arquivos grandes com GIT
Comment: Mas esse arquivo não é necessário para o meu repositório. Simplesmente apaguei o mesmo. Porém não consigo dar um push pro rep remoto, pois ele ainda guarda essa memória em algum lugar, me parece.
Comment: você ja deu um git ignore nele ?
Comment: Já tentei também...


A problem involving showing the existence of a particular ODE

Question: I was working on a problem and I ended up needing to prove the existence of a $C^2$ function $\phi:(0,\infty)\to \mathbb{R}$ such that $\phi'(t)\geq0$ and given $p>2$ then $\phi$ satisfy:
$\bigg( \frac{4}{p-1} - \frac{1}{2p}\bigg)(\phi'(t))^2 + \phi'(t)(1-\frac{1}{2p}) +p-1\leq \frac{\phi''(t)}{2p}.$
But I have no ideia how to construct such function.
As the inequality seens to be fulfilled for a function that grows fast, I tried $\phi(t)=e^{f(t)}$, and then try to find a $f$ appropriated, but that didn't work .
Any help would be much appreciated!
Answer: It doesn't exist.
Note that the general solution of the differential equation
$f'(t) = k f(t)^2$ is  $f(t) = 1/(c - k t)$. If $f(0) > 0$ (so $c > 0$)
and $k > 0$, this "blows up" to $+\infty$ at $t = c/k$.  Your $\phi'$ is supposed to satisfy $\phi' \ge 0$ (and if $\phi'(t) = 0$, $\phi''(t) \ge 2 p (p-1) > 0$ so $\phi'(t_1) > 0$ for $t_1 > t$).  But then $\phi''(t) > k \phi'(t)^2$ with $k = 2 p (4/(p-1)- 1/(2p)) > 0$.  We conclude that $\phi'$ is greater than the solution of $f' = k f^2$ with the same initial condition, and so it must also go to $+\infty$ at a finite $t$.
Comment: Thanks for the help Robert!!


Spring Boot: modeling same entity across multiple databases with dblink

Question: I have one database MAIN_DB that has dblinks to other databases: EMP_DB1, EMP_DB2, EMP_DB3, EMP_DBx. Let's assume two other databases for simplicity.
EMP_DB1 and EMP_DB2 both have the table EMPLOYEE with the same table structure:
create table employee(
id number primary key,
first_name varchar2(40),
last_name varchar2(40));

MAIN_DB is able to query EMP_DB1 and EMP_DB2 through their dblink:
select * from employee@emp_db1;
1  John  Smith

select * from employee@emp_db2;
2  Jane  Doe

I would like for my RestController to listen on /employee/{id} and query the corresponding EMP_DBx depending on the id.
Current working (not ideal) example:
com.apitest.repository.PersonRepository
package com.apitest.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.NoRepositoryBean;

@NoRepositoryBean
interface PersonRepository<T> extends JpaRepository<T, Long> {
}

com.apitest.repository.EmployeeRepository
package com.apitest.repository;

import com.apitest.model.Employee;
import org.springframework.stereotype.Repository;

@Repository
public interface EmployeeRepository extends PersonRepository<Employee> {
    Employee findById(Long id);
}

com.apitest.repository.Employee2Repository
package com.apitest.repository;

import com.apitest.model.Employee2;
import org.springframework.stereotype.Repository;

@Repository
public interface Employee2Repository extends PersonRepository<Employee2> {
    Employee2 findById(Long id);
}

com.apitest.model.Person
package com.apitest.model;

...

@MappedSuperclass
public abstract class Person {
    private long id;
    private String firstName;
    private String lastName;

    @Id
    @Column(name = "ID")
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Basic
    @Column(name = "FIRST_NAME")
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Basic
    @Column(name = "LAST_NAME")
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String toString() {
        return "id: " + id + ", " +
                "first_name: " + firstName + ", " +
                "last_name: " + lastName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person employee = (Person) o;
        return id == employee.id &&
                Objects.equals(firstName, employee.firstName) &&
                Objects.equals(lastName, employee.lastName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, firstName, lastName);
    }
}

com.apitest.model.Employee
package com.apitest.model;

import javax.persistence.Entity;

@Entity(name = "EMPLOYEE@EMP_DB1")
public class Employee extends Person {

}

com.apitest.model.Employee2
package com.apitest.model;

import javax.persistence.Entity;

@Entity(name = "EMPLOYEE@EMP_DB2")
public class Employee2 extends Person {

}

com.apitest.controller.EmployeeController
package com.apitest.controller;

...

@RestController
@RequestMapping("/employee")
public class EmployeeController {
    private final EmployeeRepository employeeRepository;
    private final Employee2Repository employee2Repository;

    @Autowired
    public EmployeeController(EmployeeRepository employeeRepository, Employee2Repository employee2Repository) {
        this.employeeRepository = employeeRepository;
        this.employee2Repository = employee2Repository;
    }

    // logic will be different, this is just an example
    @RequestMapping(path = "/{id}", method = RequestMethod.GET)
    public ResponseEntity<?> getByUserid(@PathVariable("id") Long id) {
        if (id % 2 == 1) {
            Employee employee = employeeRepository.findById(id);
            return new ResponseEntity<>(ResponseEntity.ok(employee), HttpStatus.OK);
        }
        else {
            Employee2 employee2 = employee2Repository.findById(id);
            return new ResponseEntity<>(ResponseEntity.ok(employee2), HttpStatus.OK);
        }
    }
}

Is there a way to parameterize the Entity name?
@Entity(name = "EMPLOYEE@{db_link_name}")
public class Employee extends Person

If not, how can I query a dblink with @Query?
EmployeeRepository:
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
    @Query("select e from employee@emp_dbx e e.id = ?1")
    Employee findById(Long id);
}

Spring doesn't like the @dblink_name in the query string. I'm able to create synonyms to get around this, but I'm unable to parameterize the synonym name:
create or replace synonym employee_emp_db1 for employee@emp_db1;
create or replace synonym employee_emp_db2 for employee@emp_db2;

public interface EmployeeRepository extends JpaRepository<Employee, Long> {
    @Query("select e from ?1 e e.id = ?2")
    Employee findById(String dblinkName, Long id);
}

QuerySyntaxException: unexpected token: ? near line 1, column 15 [select e from ?1 e e.id = ?2]

Desired behavior:
GET /employee/1
{
    "headers": {},
    "body": {
        "id": 1,
        "firstName": "John",
        "lastName": "Smith"
    },
    "statusCode": "OK",
    "statusCodeValue": 200
}

GET /employee/2
{
    "headers": {},
    "body": {
        "id": 2,
        "firstName": "Jane",
        "lastName": "Doe"
    },
    "statusCode": "OK",
    "statusCodeValue": 200
}

My question boils down to what is the best design done Spring-fully and how can I achieve this?
Comment: I think this is on the borderline of being too broad / opinionated ... consider looking into [mcve] and ways to *minimize* your code input.
Comment: @GhostCat I added the different things I tried for completeness, but I can see how that makes it too broad. I'll break it up into separate questions.
Answer: You should implement Multi-Tenant architecture. It will be the correct design pattern to use for your use-case.
Check out this link to make your spring/spring-boot app multi-tenant.
https://fizzylogic.nl/2016/01/24/make-your-spring-boot-application-multi-tenant-aware-in-2-steps/
Comment: This is a great solution! Thank you for the link.


Merge dataframe cols and a row to specific index base on another dataframe column value

Question: Sorry If the headline isn't clear enough, i'll explain myself better with example:
dataframe1 = pd.DataFrame(columns=['UniqueNum', 'B' ,'A'])
dataframe1['UniqueNum'] = ['1a','2b', '3c']
dataframe1['A'] = ['2','6', '7']
dataframe1['B'] = ['3','88', '23']
print dataframe1
dataframe2 = pd.DataFrame(columns=['TestId', 'C' ,'D'])
dataframe2['TestId'] = ['1a','2b', '3c', '1a', '3c', '2b']
dataframe2['C'] = ['22','46', '47','22','46', '47']
dataframe2['D'] = ['13','88', '233','22','46', '47']
print dataframe2

print are:
>>>
  UniqueNum   B  A
0        1a   3  2
1        2b  88  6
2        3c  23  7
  TestId   C    D
0     1a  22   13
1     2b  46   88
2     3c  47  233
3     1a  22   22
4     3c  46   46
5     2b  47   47
>>>

I want to merge so the output dataframe will look like that:
      TestId   C    D   B  A
0     1a       22   13   3  2
1     2b       46   88  88  6
2     3c       47  233  23  7
3     1a       22   22   3  2
4     3c       46   46  23  7
5     2b       47   47  88  6

Meaning to add to dataframe2 the columns with the values correspond to the match between UniqueNum in dataframe1 to TestId in dataframe2.
Thanks
Answer: You can use DataFrame.merge with left join and rename columns:
d = {'UniqueNum':'TestId'}
df = dataframe2.merge(dataframe1.rename(columns=d), how='left', on='TestId')

Or created index instead rename and change parameters for left_on and right_index:
df = dataframe2.merge(dataframe1.set_index('UniqueNum'),
                      how='left',
                      left_on='TestId',
                      right_index=True)

Or specified both columns and last remove UniqueNum column:
df = dataframe2.merge(dataframe1,
                      how='left',
                      left_on='TestId',
                      right_on='UniqueNum').drop('UniqueNum', axis=1)

print (df)

  TestId   C    D   B  A
0     1a  22   13   3  2
1     2b  46   88  88  6
2     3c  47  233  23  7
3     1a  22   22   3  2
4     3c  46   46  23  7
5     2b  47   47  88  6


Composite function derivative/ Chain Rule

Question: If $F(x) = f(g(x))$,  $g(2) = 4$, $g'(2) = 3$, $f'(4) = 5$, what is $F'(2)$?
Please explain how you got the answer as well.
Answer: $F'(2)=f'(g(2))\;(g'(2))\; $ by the chain rule, so we have $F'(2)=f'(4)\;g'(2)=(5)(3)=15 $
Recall, this all follows from your definition, $F(x)=f(g(x)),$ so $F'(x)=f'(g(x))\;(g'(x))$ i.e., $F'(2)=f'(g(2))\;(g'(2))=f'(4)\;(3)=15$
Comment: It was that simple ._. . Thanks.
Comment: Yup thats it for this question! No problem


Proving $(x^{p}-x)^{a} \equiv 0\pmod{p^{a}}$ as a step to another problem?

Question: I have a problem where I have to use that $a^n\equiv a \pmod p$ to show that there exist non-zero polynomials modulo $n$ that are the zero function. I have tested some examples and figured that for the examples I tested, it seems that for $m\equiv p_1^{a_1}p_2^{a_2}\dots p_n^{a_n}$, the polynomial:
$$(x^{p_1}-x)^{a_1}(x^{p_2}-x)^{a_2}\dots(x^{p_n}-x)^{a_n} \tag{$\star$}$$
Is the zero function but I can't figure out why, I also tested some variations such as:
$$(x^{p_1^{a_1}}-x)^{a_1}(x^{p_2^{a_2}}-x)^{a_2}\dots(x^{p_n^{a_n}}-x)^{a_n}$$
But noticed they fail. I thought about writing $(\star)$ as:

$$\begin{eqnarray*}
  {(x^{p_1}-x)^{a_1}(x^{p_2}-x)^{a_2}\dots(x^{p_n}-x)^{a_n} }&\equiv &{0\pmod{p_1^{a_1}} } \\
  {(x^{p_1}-x)^{a_1}(x^{p_2}-x)^{a_2}\dots(x^{p_n}-x)^{a_n} }&\equiv &{0\pmod{p_2^{a_2}}} \\
  {\vdots\hspace{3cm}}&&{} \\
  {(x^{p_1}-x)^{a_1}(x^{p_2}-x)^{a_2}\dots(x^{p_n}-x)^{a_n} }&\equiv &{0\pmod{p_n^{a_n}}}
\end{eqnarray*}$$

And realized that if that is actually true, we must have:

$$\begin{eqnarray*}
  {(x^{p_1}-x)^{a_1} }&\equiv &{0\pmod{p_1^{a_1}} } \\
  {(x^{p_2}-x)^{a_2} }&\equiv &{0\pmod{p_2^{a_2}}} \\
  {\vdots\hspace{4mm}}&&{} \\
  {(x^{p_n}-x)^{a_n} }&\equiv &{0\pmod{p_n^{a_n}}}
\end{eqnarray*}$$

So it all boils down to proving that $(x^{p}-x)^{a} \equiv  0\pmod{p^{a}}$ for any $p$ prime and any positive integer $a$. But I have no clue on how to do that. Could you give me a hint?
Answer: Hint If $b \in \mathbb Z$ you know that
$$b^p-b \equiv 0 \pmod{p}$$
This means that
$$p|b^p-b$$
Deduce from here that
$$p^a|(b^p-p)^a$$
P.S. You can also show that there exist non-zero polynomials modulo $n$ that are the zero function by a very simple counting: there are finitely many functions $f: \mathbb Z/n \mathbb Z \to \mathbb Z/n \mathbb Z$ but infinitely many polynomials. Therefore, there are two polynomials $P \neq Q$ with the same function. Then $R:=P-Q$ is your polynomial. You can even restrict the degree to $\deg(R)\leq n+1$
Comment: Also not that the implicit problem is non-trivial: $\ker(\Bbb{Z}[x]\to \Bbb{Z}/p^a \Bbb{Z})$ is not $(p^a, (x^p-x)^a)$ for $a >1$ because $\Bbb{Z}[x]/(p^a,(x^p-x)^a)$ is a group with $(p^a)^{p^a}$ elements whereas not all functions $\Bbb{Z}/p^a \Bbb{Z}\to \Bbb{Z}/p^a \Bbb{Z}$ come from a polynomial, as $f(b+p)=f(b)\bmod p$.


How many IP addresses can I use from a pool of 4 IP

Question: My ISP says that it can provide an optic fiber connection with a pool of 4 static IP addresses(subnet 255.255.255.248 i think).
My question is that if I get that connection,
1 ip will be used for network
1 for default gateway
1 for broadcast.
So I will get only 1 usable ip address, while other internet plan have only 1 static ip address and cost less. So what is the benefit of pool of 4 ip?
Comment: You will probably get a pool of 4 static public addresses, but I think you'll only have one that's usable for personal use and then you just use NATting.
Answer: Public IP addresses don't fall under the same restraints as private IP addresses, as far as reserving addresses for the broadcast and network ID. Think of it like this:
The internet is one big network. The addresses that they assign to you are like clients on a personal network -- each client doesn't need to provide its own gateway and broadcast addresses... those are attributes of the network itself.
By receiving an IP address from them, you can do with it as you please. Usually, that consists of running it through a router and/or switch (thus creating private addresses for your network), and allowing multiple people to access the internet through NAT (which you can learn more about in-depth here).
In the end: you will be receiving 4 usable IP addresses, with which you can do whatever you please!
Answer: FYI subnet mask of 255.255.255.248 will give you a subnet of 8 IP addresses, not 4. 255.255.255.252 will give you a subnet of 4 IP addresses.
You're right, this subnet will allow you to use just one IP address for a host, but people do not use this subnet very often. Most of the time, these subnets are used for point-to-point connections, usually two network devices on both ends(like routers), where they are configured with a tunneling protocol so that they don't need a default gateway.
e.g. In case of a P2P connection between two routers, one of the devices would be a DTE(Data Terminal equipment) device and the other one would be a DCE(Data Circuit-terminating equipment) device. COnfigured so, they don't require a Default Gateway to route the packets.


Extracting images with scrapy

Question: This is my first post on this forum, so apologies if I'm missing anything!
Basically, I have had some success with the script(seen below), however, it is only returning one image(being the last image on the page).
Any help is appreciated!
import scrapy

class KwikEKartSpider(scrapy.Spider):
    name = "kek"
    allowed_domains = ["https://www.tesco.com/groceries/en-GB/shop/fresh-food/all"]
    start_urls = (
        'https://www.tesco.com/groceries/en-GB/shop/fresh-food/all',
    )

def parse(self, response):
    links = response.xpath("//img/@src")
    html = ""

    for link in links:
        url = link.get()

    if any(extension in url for extension in
    [".jpg", ".png"]):
        html += """

        """.format(url=url)

    with open("frontpage.html", "a") as page:
        page.write(html)
        page.close()

Answer: This is an indentation problem.
The only line inside your for loop is:
url = link.get()

You probably want to indent the rest of the code as well.

Extracting images with scrapy


Google Apps Script CoffeeScript

Question: What are some ways of hacking CoffeeScript into the Google Apps Script Editor (not an external editor)?  I realize I won't get autocomplete, but I would like to use CoffeeScript inside the google editor nevertheless.
Answer: You can't, because it's a JavaScript execution environment, not a CoffeeScript execution environment.  Google would have to add support for this themselves.
You could write locally in CoffeeScript and put the output code into the Google Apps Script editor?
Comment: That approach is described in [this question](http://stackoverflow.com/questions/9059475/how-to-generate-global-named-javascript-functions-in-coffeescript-for-google-a) and its answers.
Answer: Although I haven't looked at it, this seems like it might be helpful:
A CoffeeScript template for Google Apps Script development
Comment: Link only answers are discouraged, it is better if you could include the most relevant information into your answer.

Google Apps Script CoffeeScript


How to imitate the sound of other instruments with piano

Question: Playing classical music on an acoustic piano, one is often required to imitate the sound of other instruments in order to create different atmospheres.
This is especially the case in the music of Mozart, Beethoven, Schubert, to name a few composers. For instance Beethoven's op 26 first movement looks a lot like a string quartet and in this bit of Mozart's Fantasia in c, one can argue that the left hand motive imitates a muted horn whereas the right hand can be thought of as some woodwinds instruments.

This is a rather advanced topic that I'm discussing currently with my teacher, one with which I have practically no experience at all, except hearing suggestions of this kind in masterclasses on YouTube.
It has occurred to me that this may not be only a matter of stimulating one's imagination, but also a very practical means of achieving the desired sound.
I am struggling with this practical aspect. I understand that by varying articulation, range of dynamics, phrasing, etc. and in a more general way weight and velocity at the moment of striking the keys, one can achieve a million different kinds of sound. I would be very interested if anybody had any hints about what specifically can be done to approach the sound of different instruments.
More precisely I would like to construct a table with entries for each instruments such as "special quality of sound" and "means of achieving it".
Please note that I'm not talking about imitating in a strict way. I understand that a flute is a flute and that one cannot reproduce the sound of a flute on the piano for obvious reasons. I am interested in what can be done with the technical limitations of the piano to make it sound the most possible like a flute.
EDIT : in response to comment saying this question is too broad. I guess every instrument can achieve a variety of different colors itself so to determine a single way of imitating it whithout the help of the context is impossible. However I was hoping that it might be feasible to draw general guidelines.
For instance when imitating a flute, I noted the folowing guidelines : expressive phrasing while avoiding fortissimo, very soft attacks, carefull legato and the melody needs to breath a lot.
For a clarinett I might use a completely different touch. I repeat that I am a beginner in this kind of thinking, so I might be completly wrong with what I said about the flute, or even wrong in this kind of approach, hence my question.
Comment: I didn't think you could mimic other instruments on the piano, you don't have that much control over the attack.  On the other hand classical guitar music will often have direction in words to mimic other instruments and there are attack techniques for doing so.
Comment: This is a valuable topic, but I've voted to close, because, as asked, it's too broad to garner a few concise answers. Please consider editing or re-asking relative to a specific musical example (such as the Mozart excerpt).
Comment: Hmm.  Can you point us to some of these "masterclasses on YouTube"?
Comment: @ggcg - I'd be interested to find out more about 'guiar mimicking other instruments'.
Comment: Just a couple videos on the top of my head, I'm sure you could find many more, featuring different artists than Andras Schiff
https://youtu.be/IzTdpTHIgkc?t=936
https://youtu.be/jEI4OFemtLc?t=2010
Comment: There is also a book :  The art of piano playing by Heinrich Neuhaus which deals a little bit with this theme in the chapter about tone.
Comment: @Tim, when Debussy evoked guitar in the piano preludes he used repeated tones and open fifths. Not a dead on imitation, but less piano texture, some hinting at guitar texture.
Comment: Piano is really unique in how little control over the timbre it allows. If you dismiss tricks with harmony, all you have is volume, timing, sustain pedal and maybe sostenuto or mute. Everything else is in your head.
Answer: I think these effects come from:

characteristic rhythms
characteristic figures, melodic line
general range

So, for example horns can be imitated in mid range with tonic chord fanfare type figures, dotted rhythms would make sense.
Tympani could be imitated with low range, just rhythm, no "melody" (it's a drum), at the most play the fifth above for just tonic/dominant patterns. Even rhythms like one eighth, two sixteenths could suggest the two handed motion of drum sticks.
"Sighing" figures, appoggiaturas, and flowing scales in thirds/sixths, upper register,  might be a good way to suggest wood winds.
Certain figures would seem to fit into groups while excluding others. For example, tremolos in sixth in treble range would evoke fast bowing on violins, but probably not double bass or brass, certainly not a timpani.
I think you imitate instruments on the piano along these lines.
An orchestration book might provide some ideas. Check instrument ranges and examples of usage in the orchestra.
I wouldn't call this "advanced." Honestly, I think it works mostly by exploiting cliches of basic instrumentation.
Comment: This answer misses the point. I am not interested in guidelines for composing or improvising. Neither about spoting which part of the music is about which instrument. I am looking for guidelines about the quality of touch and interpretation.
Comment: @abernard, I didn't get that when I first read your post, but see it in your 5th paragraph. I don't know if there is more to add than what you wrote in your edit. Beyond that I think the rest will just be in the imagination of the performer, or a chance association in some listeners. You aren't going to use a particular touch and have listeners associate something like "that's flute definitely not clarinet." It sounds like a great way for a performer to be _more sensitive_ about expression generally, but it would never pass a blind listening test for mimicked instruments.
Comment: Thanks for your reply. The purpose of all of this is to have a more lively interpretation and have people react more deeply to the music. I guess you are right saying that it comes down primarily to the imagination of the performer. Whether or not the listener get's what instrument the pianist is thinking of when playing is not a big deal though.
Comment: I don't mean to be a wet blanket. I listened to the Andras Schiff lecture. The playing is fantastic, but I honestly don't hear all the imagined instruments. But I'm a bad pianist. Hopefully you get some answers from good pianists. There are actually many quietly lurking on this forum.


Group and compact variables

Question: I'm working on a menu calendar for a preschool. They have 8 different menus on rotation:
Summer 1, 2, 3, 4 and Winter 1, 2, 3, 4. It rotates every week like this:
Sep - Jun menu
I want parents to be able to look up the menu of the day based on the date. For example on sep 26th the school serves 'Summer menu week 4'.
The calendar in the link is ok but I'd like to provide infos in a more compact way (this is a good example of what I mean, except it doesn't work in my case - two different menus end up in the same spot).
Anyway, I'm stuck trying to find a way to visualize data. Does anyone have a suggestion?
Answer: Your existing design can be compressed by removing some redundancies and non-data. For instance, the menu number is indicated by both horizontal position and by a label for each day. And the week-ends can be removed or de-emphasized so the relevant data stands out better. Here's a more compact view of your design, using shared menu labels instead of repeated labels. (They should have gone at the top, but I'm not familiar with Google Spreadsheets and there was some hidden row I didn't want to mess up.)

However, using a familiar calendar layout make be easier to scan if you can afford the vertical space. In the try below, I use a different shade of color for each menu week. It would be better with thicker borders around each month, but Google Spreadsheet doesn't seem to support that.

By omitting week-ends, you do lose the ability to highlight the current day. In the second example, I instead used red text for the current week.
For more layouts along these lines, you might search for "calendar plot" and "calendar graph".

Group and compact variables


What is the initial piano chord in Ella and Louie's "I Won't Dance" recording?

Question: I'm learning this song for a duet performance. I can play the walking bass line and even the chord progressions on bass. I can even tap out the intro chords when the lyrics start in a Stu Hamm or Victor Wooten fashion (just an example so you don't question why I'm playing chords on bass). However, in the very beginning of the song the piano runs through (what I believe to be) an Eb chord. Now let me remind you I don't play piano. I play violin, autoharp, and bass, so I'm not very familiar with any piano techniques. But let me assure you I've heard this style of a run-up before. I've tried several ways of tapping out this chord in a very fast manner, but I just can't seem to make out all these notes, or quite frankly, what's going on here.
Comment: Get some software that can slow down the audio without changing the pitch - e.g. Audacity, or (specifically written for music transcribing) the demo version of "Transcribe". If you play it say 10 times slower than the original you should be able to pick out the notes. "Knowing about piano technique" wouldn't help - a good pianist can play any notes that he/she wants to in that sort of run!
Comment: @alephzero - with all the technology available, skill is taking a back seat. I wonder when our ears will become vestigial...
Comment: I agree, it's quiet a shame. I understand it makes things much easier, but even now, computers can replace instruments in a hardbeat. So much modern music is synthetic and without soul or feel.
Answer: Sounds like a diminished 7th arpeggio to me - same sort of thing that starts 'I Will Survive', except this rolls from Eb up to C. Taking the song into Ab.
Answer: The chord is an Eb7b9(add13).
The piano plays an Eb octave, arpeggiates a Go7 up a total of 7 notes (G Bb Db E G Bb Db), steps back down to the Bb, and resumes the arpeggio for a total of 8 more notes (Bb Db E G Bb Db E G), and finally ends on a C.


Execute PHP script when someone requested a certain file in another Folder

Question: I am building a WebHosting service. Users can create a Account and upload Files with FTP and access them by visiting username.mywebsite.com (just an example). I would like to record the number of visits any file in the Folder of my User has. So I would like to execute a PHP Script when any file in that Folder is visited. But I don't want to change the HTML/PHP files my User uploaded. How can I do that?
Thanks in advance,

Max
Comment: Parse the access log? Or better yet, use a already existing web statistics software that does that for you?
Answer: I think you are looking for something like the answer in this one: https://webmasters.stackexchange.com/a/32964
Basically, do something like this in your .htaccess file:
<code>Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ script.php?filename=$1 [L]
</code>

make script.php run your code and afterwards redirects using the filename variable you passed to it. ($_GET['filename'])


Application Scoped bean for converter for p:selectOneMenu

Question: i have implemented PrimeFaces selectOneMenu through github and PrimeFaces and not clear about why themeservice-bean has been defined as Application scope e.g.
<code>@Named
@ApplicationScoped
public class ThemeService {

    private List<Theme> themes;

    @PostConstruct
    public void init() {
        themes = new ArrayList<>();
        themes.add(new Theme(0, "Nova-Light", "nova-light"));
        themes.add(new Theme(1, "Nova-Dark", "nova-dark"));
        themes.add(new Theme(2, "Nova-Colored", "nova-colored"));
        themes.add(new Theme(3, "Luna-Blue", "luna-blue"));
        themes.add(new Theme(4, "Luna-Amber", "luna-amber"));
        themes.add(new Theme(5, "Luna-Green", "luna-green"));
        themes.add(new Theme(6, "Luna-Pink", "luna-pink"));
        themes.add(new Theme(7, "Omega", "omega"));
    }

    public List<Theme> getThemes() {
        return themes;
    }
}
</code>
in my view, the same bean should be defined as View/Request scoped as the list may need to be populated with different records, but as i change the scope it gives error of
<code>java.lang.NullPointerException
    at org.primefaces.showcase.convert.ThemeConverter.getAsObject(ThemeConverter.java:27)
</code>
at return statement in converter
<code>                ThemeService service = (ThemeService) fc.getExternalContext().getApplicationMap().get("themeService");
                return service.getThemes().get(Integer.parseInt(value));
</code>
may somebody shed some light on this.
Comment: Also relevant reading: https://stackoverflow.com/questions/2633112/get-jsf-managed-bean-by-name-in-any-servlet-related-class
Comment: Or even better: https://stackoverflow.com/questions/7665673/how-to-inject-ejb-persistencecontext-inject-autowired-etc-in-facesconve
Answer: You try to get a request or view scoped bean from applicationMap which stores application scoped beans only.
Try to replace getApplicationMap by getRequestMap or getViewMap.
Or even better @Inject the themeService into your converter:
How to inject @EJB, @PersistenceContext, @Inject, @Autowired, etc in @FacesConverter?
Comment: @NasirAbbas "it resolved" how did it resolve? And what does "too quick" mean?
Comment: too quick ... thanx it resolved. i didn't understand the converter fully.
Comment: And the themeService(applicationScoped) **IS** request  from the applicationMap.. Weird
Comment: @kukeltje OP asked in the question that getting the themeService from applicationMap stops working as soon as the scope of themeService is changed to view scope or request scope. (This is how I got the question tho).
Comment: Ok, now I read it again, with your comment I agree to your interpretation, but then the title and posted code are completely unrelated. OP should have posted a view or requestscoped bean that throws the error, not the working code (since the code that **_was_** posted seems fine...
Comment: @Selaron the response was too quick from ur side and immediately resolved and pointed out my mistake and actually i don't have any idea abt ApplicationMap bcoz i copied the example and implemented it as it is although i myself tried to understand.


Update table from text file?

Question: I have a table T1:

code
name

001
alias

002
row

and I have a text file code.txt
oldCode;newCode
001;d4f
002;bc3

I need to update table t1 (replace the old code with the new code) and the table be like that:

code
name

d4f
alias

bc3
row

Does anyone have the solution?
Comment: Use `OPENROWSET` and `JOIN` to that data in an `UPDATE` statement. `BULK INSERT` the text file into a staging table, and then `UPDATE` by `JOIN`ing that that table?
Comment: can you create the query for more understand I'm beginner in database and i need to solve this problem
Comment: The documentation has lots of information on all of these: [`OPENROWSET`](https://learn.microsoft.com/en-us/sql/t-sql/functions/openrowset-transact-sql?view=sql-server-ver15), [`BULK INSERT`](https://learn.microsoft.com/en-us/sql/t-sql/statements/bulk-insert-transact-sql?view=sql-server-ver15), [`UPDATE`](https://learn.microsoft.com/en-us/sql/t-sql/queries/update-transact-sql?view=sql-server-ver15) ([Example with `JOIN`](https://learn.microsoft.com/en-us/sql/t-sql/queries/update-transact-sql?view=sql-server-ver15#l-specifying-a-table-alias-as-the-target-object))
Answer: Taking Larnu's method, a query would be like:
UPDATE t SET t.code = DATA.newCode FROM T1 t JOIN OPENROWSET(BULK 'PATH_TO_FILE\code.txt', SINGLE_CLOB) AS DATA ON t.code = DATA.oldcode;
Keep in mind SQL server should have access to the file.

Update table from text file?


jquery - array from select children span text separated by commas

Question: I need to generate an array like this in JQuery:
one,two,three,four

by selecting the text from multiple  children:

<input value="somevalue"/>one

<input value="somevalue"/>two

<input value="somevalue"/>three

<input value="somevalue"/>four

I've tried with this:
$('html').find('#GROUP span').text();

But it joins all the text with no spaces:
onetwothreefour

I need to separate the text with commas

Solved
Working DEMO
Comment: You don't have to change your title as resolved instead mark any one of the answers as accepted to show your acceptance to other future visitors of this post... :) you can see a tick mark present in every answer use that... And this is not a compulsion... Just trying to teach the system... :)
Comment: i was waiting 11 min :) Sure, I accept it now :)
Answer: Try to use .map() along with .get() to collect those values in an array, afterwards .join() that array with any character you want.
var text = $('#GROUP span').map(function(){
    return $(this).text();
}).get().join();

DEMO
Side Note: By default .join() would join the text by using ,. So there is no need to specify that in our case.
Comment: Uncaught SyntaxError: Unexpected token ,
Comment: @user3746998 It was a typo, as a pgmer, you should have corrected of your own rather complaining to me..! Anyway i updated..
Answer: For getting them in array, you can use:
var spantexts= [];
$("#GROUP span").each(function() { spantexts.push($(this).text()) });

Demo
For getting them in as comma seprated value:
Using join:
console.log(spantexts.join(','));

or
var spantexts= "";
$("#GROUP span").each(function() {
    if(spantexts!="")
    spantexts+=",";
    spantexts+=$(this).text();
 });

Working Demo
Comment: you'd have to the use .join(): ```spantexts.join(',')```
Comment: @MilindAnantwar Really..? or kidding..?
Answer: As a minor update, the same using arrow functions:

let joinedText = $('#GROUP span').map(
    (index, domElement) => $(domElement).text()
).get().join(',');

$('#RESULT').text(joinedText);

Given:

<input value="somevalue"/>one

<input value="somevalue"/>two

<input value="somevalue"/>three

<input value="somevalue"/>four

Result:


Second Order Stochastic Dominance and $\Pr[X \leq Y]\leq1/2$

Question: Let $X$ be a random variables with continuou cdf $F$ in the support $[a,b]$.  Let $Y$ be another r.v. with cdf $G$, which is continuous in $[a,b)$ and has an atom at $b$.  $X$ and $Y$ are independent. We also have $E[X]=E[Y]$ and second order stochastic dominance
$$\int_a^k F(t)\,dt \leq \int_a^k G(t)\,dt, \  \ \  a \leq k \leq b.$$
Can we say the following:
$$\Pr[X \leq Y] \leq \frac 1 2 \text{?}$$
My attempt:  I have tried numerical analysis with different parameter values and the above statement is always true. However, it gets difficult to prove it analytically.
Answer: It's not true.
Intuitively, we could concentrate $X$ near the common expectation and spread $Y$ out to the two endpoints.  Provided most of the probability of $Y$ is near the smaller endpoint, $X$ will tend to exceed $Y$, but $Y$ will dominate $X$ (stochastically in second order) because the integral of $G$ rises rapidly at small values while the integral of $F$ does not start to rise above zero until later.

For an explicit counterexample, take $a=0$, $b=1$, and let $0 \lt p \lt 1/2$ be fixed.  Select $0 \lt \epsilon \lt p/2$, then choose $0 \lt \delta \lt p-(1+p)\epsilon$.  Let $X$ have a uniform distribution on $(p + (1-p)\epsilon-\delta, p + (1-p)\epsilon+\delta)$ and let $Y$ be a mixture of a uniform distribution on $(0,2\epsilon)$ (with weight $1-p)$ and an atom at $1$ with weight $p$.

The left hand graphic plots $F$ and $G$.  The right hand plots their integrals.  Graphs associated with $F$ are shown as a blue dashed line while graphs associated with $G$ are shown as a solid red line.
Since the expectation of any uniform distribution is its midrange, compute
$$\mathbb{E}(X) = p + (1-p)\epsilon$$
and since the expectation of a mixture is the weighted combination of the expectations of its components,
$$\mathbb{E}(Y) = (1-p)(\epsilon) + p(1) = p + (1-p)\epsilon.$$
Thus the expectations are equal, as required.
The second-order stochastic dominance is clear, because the $G$ integral is positive for small values of its upper limit while the $F$ integral is zero, then eventually both rise linearly to equal $1-E[X]=1-E[y]$ at $1$.  This is the point at which the graphs meet in the upper right of the right hand graphic.
Finally, since $\Pr(Y=0) = 1-p \gt 1/2$ and $\Pr(X \gt 0) = 1$, $\Pr(X \ge Y) \gt 1/2$.


Existe diferença de performance usando ngIf diretamente em um componente

Question: Olá, Alguém poderia me informar se existe diferença de performance nos trechos de código abaixo, e se existe, qual seria o mais performático? Obrigado!!

    <componente></componente>

<componente *ngIf="false"></componente>
Comment: Na realidade ambas as formas funcionam... o que gostaria de saber é se o  chega a ser instanciado no DOM e depois retirado do DOM, ou se nem no DOM ele entra. Outro detalhe... no exemplo fica mais claro se for usado o false... por que a dúvida é no carregamento do componente. Não sei se ficou claro.
Comment: Você chegou a testar se o `ngIf` funciona dentro de ``?
Answer: Ambas tem a mesma performance o ngIf é uma diretiva estrutural com isso ele gera um ng-template em volta do elemento que você coloca ele e manipula o dom de acordo. Sendo assim em nenhum caso ele instancia o componente se o ngIf for false. No entanto tem difernça entre a semantica e de estilo visto que o div tem um display block e o componente não necessariamente.
<componente *ngIf="hero" class="name">{{hero.name}}</componente>

vira
<ng-template [ngIf]="hero">
  <componente class="name">{{hero.name}}</componente >
</ng-template>

mais informações: Diferenças de diretivas no Angular


Is the distribution of the minimum of two other distributions a mixture distribution? Or is there a better term?

Question: This is a terminology question motivated by a review that I got on a paper. In the following I believe that $y$ would be considered to be distributed according to a mixture distribution:
$$y \sim \left\{
 \begin{array}{ll}
  f_1(\theta_1)  & \mbox{with } p ~ \mbox{probability} \\
  f_2(\theta_2)  & \mbox{with } (1 - p) ~ \mbox{probability}
 \end{array}
\right. $$
where $f_1$ and $f_2$ are probability distributions. But would it be correct to say that $x$ is also distributed according to a mixture distribution?
$$ x \sim \text{min}(z_1,z_2) \\
   z_1 \sim f_1(\theta_1) \\
   z_2 \sim f_2(\theta_2)$$
If not, is there a better term? Or, at least, a general term for a distribution that is some combination of two other distributions?
(I mean, $x$ is certainly the result of "mixing together" $f_1$ and $f_2$ in some way, but I don't know if this is enough to call it a mixture... :)
Comment: I believe there is no general term for "some combination" of distributions simply because the concept is far too broad to be useful.
Comment: I would say most latent variable models qualify for your "mixing" behaviour, but this does not help much because about everything is a latent variable model!
Answer: I don't think that counts as a mixture, no.
A mixture distribution draws from among a collection of distributions according to a random variable from another distribution (as in your first example, though of course they can be more complex than Bernoulli mixtures, including continuous mixtures).
The $\min$ case doesn't seem to have the characteristics I'd normally understand as being a mixture.
Comment: So do you have a suggestion for what to call it? A compound distribution? A hybrid distribution? A blend distribution? :)
Comment: No, I don't, sorry. If I had been able to think of a good specific term, I'd mention it. If I find one I'll let you know.
Comment: The best I could think of was "the distribution of the minimum" ... which is no help.


Drush update for the first time hosed my website

Question: Running latest versions of Drupal, etc.
Localhost - dev site
Maintenance mode
While trying to install Commerce_kickstart and running Drush for first time to update modules,  Drupal got completely hosed.
Can not find problem in database
Repaired all databases but get Drupal white screen, no error messages
Phpmyadmin won't work
Can anyone offer a series of steps to attempt recovery or at least find out what went wrong?
Thanks in advance.  I need ASAP.
Answer: Probably one of the updates of your modules is messing up. Most recently I had this problem with updating Rules which broke my site the same way it did yours (WSOD).
Reverting and updating one by one can show you what went wrong.
If you use drush you can do: drush up modulename (e.g. drush up rules) to update one by one, instead of drush up which updates everything. drush up drupal only updates core.


SoapClient PHP 5.6 Slow in IIS 7 (FastCgi), fine from CLI

Question: I've a php script that connects to a webservice.
When running the same script through the CLI it runs fine (initial connection a second and calls to the service very quick).
When running the page in PHP via an IIS FastCGI server it takes around 5 seconds delay on the first call to a webservice method.
The second call to the webservice method is fast as normal.
Any advice on where to check next would be appreciated. I'm at a loss of how to debug further.
I'm using PHP 5.6.13 on IIS Within Windows Server 2008 R2 Standard
This is the script i'm using to test this problem in isolation (webservice name anonymised as it's not publically accessible)
<code><?php
define('SOAP_URL', 'https://sandbox.webservice.com/Service.asmx?WSDL');
define('SOAP_NAMESPACE', 'http://service.webservice.com/');

class WebService
{
  public $client;

  function __construct($SoapURL = SOAP_URL, $SoapNS = SOAP_NAMESPACE)
  {
    $soapHeader = array('User' => '...', 'SecretKey'=> '...');
    $this->client = new SoapClient($SoapURL, ['trace'=>true]);
    $header = new SOAPHeader($SoapNS, 'ClientAuth', $soapHeader);
    $this->client->__setSoapHeaders($header);
  }
}

var_dump(['start', $time = time()]);
$service = new WebService();
var_dump(['init', time() - $time]);
$params = [
    'option' => 1000,
...
    'loads_of_options_skipped' => 1,
];

$service->client->GetInfo(['for_id'=>34]);

var_dump(['call1', time() - $time]);

$service->client->GetInfo(['for_id'=>34]);

var_dump(['call2', time() - $time]);
</code>
The ouput shows a delay of 4/5 seconds on the output of "call1".
this delay doesn't occur if I run the identical script via the CLI, nor on our old webserver which was php 5.4
Comment: Show us the script.
Comment: This issue isn't related to SOAP, as I've just came across the same issue with file_get_contents opening a url.  There appears to be a delay in the connection somewhere.  I have no idea why this would occur in IIS but not at the command line (running git bash on windows)
Answer: This issue isn't related to SOAP, as I've just came across the same issue with file_get_contents opening a url. There appears to be a delay in the connection somewhere. I have no idea why this would occur in IIS but not at the command line (running git bash on windows)


Drush and user permissions

Question: I see that my user is a member of the apache group. I added and confirmed via the following
$ sudo usermod -a -G apache `whoami`  # add my user to apache group
$ sudo chmod -R g+w .                 # permit group members to write
$ groups `whoami`                     # confirm I'm in the apache group

However, when I attempt to run a drush update core or even drush cron
$ drush cc all

unlink(sites/default/files/css/css_71ba7c25a8d3c47c68a8e05608ae525c.css):[warning]
Permission denied file.inc:482

And the CSS cache in this situation looks like
$ ll
total 1536
drwxrwxr-x.  2 apache apache  12288 Nov 26 10:12 .
drwxrwxr-x. 11 apache apache   4096 Nov 24 20:35 ..
-rw-rw-r--   1 apache apache 162269 Nov 26 10:06 css_00d5f4d7c5c92cd4f.css
-rw-rw-r--   1 apache apache 158090 Nov 26 10:02 css_0605989692a2119d305.css
-rw-rw-r--   1 apache apache 162269 Nov 26 10:02 css_0779dcac71ee9aa8e02d9e.css

I would assume that my user account, which has sudo access, should be a group member of apache (or www-data) and that the file tree should permit group write access. Any help or points in the right direction would be much appreciated.
Comment: run `newgrp apache` without sudo and try again
Comment: Did you log out and then back in again?
Answer: Arguably, a much more straightforward approach is to not muck with your user's group assignments at all and instead run drush as the web server user (ie: apache, www-data).
Use sudo:
sudo -u apache drush

or on debian/ubuntu:
sudo -u www-data drush

Create a command alias:
Then, to ensure that you always run drush like that, add an alias:
echo "alias drush='sudo -u apache drush'" >> ~/.bash_aliases

or on debian/ubuntu:
echo "alias drush='sudo -u www-data drush'" >> ~/.bash_aliases

Now when running any drush command, you'll be prompted for your password by sudo, and the command will run as the web server user. No more permissions problem reading and writing files.
Comment: When I run "sudo -u www-data drush" it complains that the drush-backups directory is not writable.
Comment: @Magmatic just change permissions to that folder, make it writeable for www-data, check who is the owner.
Comment: I have a related issue here where I'm trying to run drush commands against the production server via remote site aliases. Do you have any insight as to how to accomplish this? https://drupal.stackexchange.com/questions/312977/how-to-use-drush-remote-site-aliases-with-web-service-or-other-account
Answer: Though the other answer is informative, I now use the proper user permission as described in
Securing file permissions and ownership

https://www.drupal.org/node/244924

Which opens with

The server file system should be configured so that the web server
  (e.g. Apache) does not have permission to edit or write the files
  which it then executes. That is, all of your files should be 'read
  only' for the Apache process, and owned with write permissions by a
  separate user.
Comment: The article that you link to does not mention Drush. Could you, please, clarify which user you are using to run Drush commands and how is that user set up.
Comment: Interesting! I think you should also mention the 2 pargs that follow the one you already quoted ...
Comment: In Drupal files folder needs to be writable by the webserver, and in development you will probably need that for features folder too.
Comment: This article also says:

"...For the "files" directory in the sites/default directory and any other site directories in a multi-site installation, the permissions are slightly different because the www-data user must have write permission to the directory:..."

`[root@localhost]cd /path_to_drupal_installation/sites
[root@localhost]find . -type d -name files -exec chmod ug=rwx,o= '{}' \;`
Answer: When I ran drush as www-data drush was no longer available as my $PATH had changed.
As a workaround you can enter the whole path to drush.
E.g.
sudo -u www-data /home/vagrant/.composer/vendor/bin/drush status

To get the path of your drush you can run:
which drush

Which means you can also just run:
sudo -u www-data `which drush` status

which removes the need to hard code the path in the command.
Answer: Inside files folder
chown -R youruser:www-data .
find . -type d -exec chmod ug=rwx,o= '{}' \;
find . -type f -exec chmod ug=rw,o= '{}' \;

See: https://www.drupal.org/node/244924#linux-servers

Drush and user permissions


Maths question regarding union of multiple sets

Question: The question is as follows,
Suppose $A_1, A_2, \ldots A_{30}$ are thirty sets having 5 elements each and $B_1, B_2, \ldots B_n$ are $n$ sets having 3 elements each
Let $$\bigcup_{i=1}^{30}A_{i} = \bigcup_{j=1}^{n}B_{j} = S$$ and each element of $S$ belongs to exactly 10 of the $A_i$'s and exactly 9 of the $B_j$'s, then find the value of $n$.
In the solution since the total number of elements in $A_1 \cup A_2 \cup A_3,
\ldots A_{30}$ is 150. The following equation is given
$$S = \frac{30 \times 5}{10} = 15$$ where does this come from and what does the 15 even mean is it the number of elements in the set if so why>
Comment: If you were to list out all the elements of $A_1,A_2,$ etc. *with* repetition you would get $30\times 5=150$ listing of elements.  Now $S=\cup A_i$.  That means every element of $S$ is in an $A_i$ and all elements of all the $A_i$s are in $S$.  So the list of all the elements of $A_1,A_2...$ listed many times will include all the elements of $S$.  And as each element of $S$ is listed *exactly* $10$ times, then that listing of the $150$ elements of all $A_i$ will have each element of $S$ repeated $10$ times.  That means the number of unique elements of $S$ must be $\frac {150}{10}=15$.
Answer: Here you are counting pairs of the form $(A_i,x)$ with $x\in A_i$, $i\in 1,\cdots, 30$.  You can count the number of such pairs two ways:

There $30$ choices for $i$ and for each such choice there are $5$ choices for $x$.  Thus there are $30\times 5$ such pairs.

There are $|S|$ choices for $x$, and for each such choice there are $10$ choices for $i$. Thus there are $|S|\times 10$ such pairs.

Equating the two, gives the equation in the solution:
$$30\times 5= |S|\times 10,$$
which rearranges to $$|S|=\frac{30\times 5}{10}=15$$
The reason this is stated without much explanation is it is a fairly common trick when comparing the size of two sets, where an element of the first set and an element of the second may be in some sense "incident" to each other.  In this case $A_i$ and $x$ are incident if $x\in A_i$.
Note you can use exactly the same trick again to find $n$.  I suggest you do this before looking at the rest of the solution.
Answer: How many total elements do you get from sets $A_i$'s if you do not consider the equality of elements? The answer is $30\times 5=150$. Now, note that $$\bigcup_{i=1}^{30}A_i=S$$
and every element in $S$ occurs in exactly $10$ different $A_i$'s.
We are interested in the size of $S$, so we look at the total elements we get from sets $A_i$'s but take into consideration uniqueness of these elements. We can form groups of size $10$ among those $150$ elements such that each group has the same element repeated $10$ times.
Hence, total number of unique elements in $S$ are $150/10=15$. Similarly for the set $B_i's$, you have total number of elements without uniqueness consideration $=3n$. With uniqueness consideration, the total number of elements in $S$ is $\frac{3n}{9}$.
You have two different values for the number of unique elements in $S$. Equating them, you get
$$\frac{30\times 5}{10}=\frac{3n}{9}$$


How to combine bxslider and lightbox?

Question: On my page I have a little bxlider and I want to open a lightbox gallery when clicking on one of the slides but there are conflicts when using these two scripts. jQuery's noConflict() won't help in that case. Anyone know's how to fix this or a lightbox similiar library that works together with the bxslider?
Answer: Problem solved. My lightbox version was too old. With the current version it works.
The slides list has the following form:

How to combine bxslider and lightbox?


Argumento ao inicializar o Weka

Question: Na página de download do Weka há a recomendação de inicializar o arquivo .jar do Weka com o seguinte argumento <code>-Xmx1000M</code>. Porém não entendi o que o argumento irá alterar na hora que o Weka é executado. Sendo que a inicialização funciona mesmo sem o argumento, qual a diferença?
Answer: Este parâmetro define o tamanho máximo do Heap disponível para o Weka usar.
Pode ler o que é o Heap aqui.

Argumento ao inicializar o Weka


Exchange share a folder with a blocked suser

Question: an employee of a company I administer was retired, so I blocked sign in. This user (UserA) has some emails that must be accessed by another employee (UserB), but UserB cannot access UserA's entire mailbox. So I instructed UserB to create and share a folder in its mailbox, so I could put there some old and new emails as required. I gave myself (Global Administrator) Read and Manage permissions to UserA mailbox, accessed it with OWA and added UserB in "Add shared folder" in the topmost folder... getting "Not possible to complete... Try again later".
I already instructed UserB to share the folder with UserA and Global Administrator, and to give "Folder visible" permission to the inbox and root folders.
Is it possible to share a folder with a user with a blocked sign-in?
Thank you very much!
Answer: It's not possible to access a Mailbox of a disabled user. In order to do so, you have to convert the users mailbox into a shared ressource. You can use Set-Mailbox to do that:
Set-Mailbox -Identity <MailboxIdentity> -Type Shared

The user account for this Mailbox will stay disabled. Bonus: This will convert the Mailbox into a license free ressource.
Comment: Thank you! Makes no sense - the mailbox is fully functional, it receives email, sends... I will check the shared Mailbox.
Answer: Grant UserB Full Access to the mailbox for UserA.
the mailbox for UserA will automatically be added to Outlook for UserB if UserB is using Outlook as their email client, or UserB can access the mailbox for UserA in OWA by choosing the "Open another Mailbox" option.
Comment: "UserB cannot access UserA's entire mailbox"
Answer: I also tried to block sign-in for my test mailbox, then open it with my global admin account via OWA, and tried to add another shared mailbox to the test mailbox, the result that is same with yours is that the shared mailbox couldn't be accessed from the block sign-in user, but my admin account could.
As said in the following microsoft docs, Block sign-in in office 365 means that the employee's access to Microsoft 365 data is blocked: Block a former employee's access to Microsoft 365 data, it is due to design.
However, as bjoster said, you could convert this mailbox to a shared mailbox:
Forward a former employee's email to another employee or convert to a shared mailbox. Some points are needed to notice:

Creating a shared mailbox is the less expensive way to go because
you won't have to pay for a license as long as the mailbox is
smaller than 50GB. Over 50GB and you'll need to assign a license to
it.
If you convert the mailbox to a shared mailbox, all the old email
will be available, too. This can take up a lot of space.
If you set up email forwarding, only new emails sent to the former
employee will now be sent to the current employee.
Comment: Thank you for testing! Just one question: when you said "...the shared mailbox couldn't be accessed from the blocked sing-in user..." did you try to permit the Global Admin account to the shared mailbox as well? Did not work for me either, but if you are able to test, we can put down this option as well.
Comment: >> ***did you try to permit the Global Admin account to the shared mailbox as well?***
In your case, if the process is the following: Global Administrator(Open another mailbox) -> Retired "User A "(Add Shared Folder)-> Another Employee "User B" -> Error "Not possible to complete... Try again later", yes it is.
Comment: @acgomes Hi, i'm here to confirm the progress of your thread, is there any update? If the above info is helpful for you to fix your problem, you could mark the best answer. Have a nice day:-)


Netlogo giving attribute value of agent based on value of patch and slider parameter

Question: I want to give income attribute to agent which is based on patch value where the agent stays and slider parametre.
 to setup
   if pcolor = yellow
   [sprout-resident 1
   [set color sky
   set shape "default"
   set size 1
   set-income
   ask patch-here [set pcolor brown
                set landuse "resident"
                set is-bought? TRUE
                set owner [who] of myself]]]
   end

  to set-income
  ifelse land-price > buycapabilityhigh(this is the slider parametr) [set income "high"]
  [ifelse land-price < buycapabilitymiddlle and land-price > buycapabilitylow [set income "middle"]
  [if land-price < buycapabilitylow [set income "low"]]]
  end

so I want to give agent category high middle low income based on land price where the agent stays and based on buycapability which is set by slider. Please help giving advice to code this kind of mechanism. Thanks
Comment: 1. What problem are you running into?  What happens when you `ask turtles [set-income]`?  2. Just use a sequence of if statements; no need for nesting.
Comment: Agree, your code looks fine. If you're having some difficulty or problem with it, you need to tell us what it is.
Comment: oh ya.. I'm sorry for being not detail, when I run this code, this to-set-income makes all income attribute of agents becoming "low". Even tough land-price of an agent patch is greater than its buycapability of agent ,which should make the income attribute "high", the income attribute remain "low". So, I dont know wheter do I have to be more specific or restate in this to-se-income that the patch that I mean is the one that there is resident on it (I'm trying this alternative but still haven't found the right code/ I don't know how to code it) or what.. please help giving advice for this..
Comment: If there are only three categories (high, middle, and low), why do you have three thresholds? Shouldn't two thresholds be sufficient to distinguish between three categories? One for the threshold between low and middle, and one for the threshold between middle and high.
Comment: @SethTisue I still can't figure out how to make it to two thresholds, please kindly explain more. For example low threshold <50,  50 100 that's why I create 3 sliders to represent it.
Comment: @SethTisue yes, your right, I've just figured it out..I have made it to two sliders but it still produces the same result, all agent attributes are "low". what do you think that might wrong with the code?
Comment: Please update your question to include your current code.
Answer: Is the variable land-price a patch's attributes ?
If it is, then I think the problems is in your set-income function.
You should use [land-price] of patch-here instead of just land-price in the if-statement.
Moreover, just like Alan said. you could just use a sequence of if statements.
it goes like this
if [land-price] of patch-here > ... [...]
if [land-price] of patch-here < ... and ... [...]
if [land-price] of patch-here < ... [...]

Comment: yes... land-price is a patch's attribute and buycapability is agent's attribute. What about the buycapability?do I need to add something?
I've tried your suggestion but it seem still did'nt work.
      `to set-income
       ifelse [land-price] of patch-here > buycapabilityhigh [set income "high"]
  [ifelse [land-price] of patch-here < buycapabilitymiddlle and [land-price] of patch-here > buycapabilitylow [set income "middle"]
  [if [land-price] of patch-here < buycapabilitylow [set income "low"]]]
  end`
Comment: I am sorry, I mean buycapability is the slider parameter which will determine agent's attribut income wheter high, mid or low based on the land-price where the agents stand, lower, in between or greater than certain buycapability paramter value.
Comment: I also have used if statement, not ifelse but the result is still same. Please help to find my mistakes.
Comment: `[land-price] of patch-here` is synonymous with simply writing `land-price`. A turtle has direct access to the variables of the patch it is standing on.
Comment: I see, I didn't know that, thank you for correcting me Seth Tisue. and sorry for not being useful.
Comment: so. there are 3 sliders?
Comment: yes, there are 3 sliders... it's oke @M.R. Murazza I also just know that.
Comment: @M.R.Murazza so, do you have any idea what probably wrong with the code?


Music Mode what mode is song in?

Question: I have a Blues solo to analyse, the key is G major and it makes use of blue notes such as B flat and F natural, does anyone know what 'mode' the song is in
Comment: That's blues for you!
Comment: Hi, and welcome. There's nowhere near enough information here to elicit a good answer. Chances are it's not in a mode.
Comment: the solo//melody starts on the tonic but uses accidentals that don't correspond with the key signature
Comment: The blues uses the blues scale often, which doesn't match any modes.
Answer: Players don't generally think of modes while playing the blues.  It's just not inherent to the style.  But, blues is very much improvised over with the minor, or major pentatonic as a basis, and then additional notes are thrown in.  As a tip, one way of looking at modes, are that there are 3 major, 3 minor, and one diminished. The 3 major modes have the major pentatoic in them (plus 2 different "extras").  The 3 minor modes have the minor pentatonic in them (plus 2 different "extras").  I mention this because modal players tend to use a lot more stepwise action, and blues players have a greater sense of hierarchy in their note selection (end on tonic, hang on the fifth, etc)
Comment: Maybe barrelhouse blues players stick to pentatonic scales, but jazz blues uses all kinds of non-pentatonic material. Come to think of it, Robben Ford plays diminished scales all over the place.
Comment: All blues is based off the pentatonic scales.  With additional notes, diminished is supported, even for the tonic chord.  Since blues often uses dominant 7th chords, a diminished substitution is appropriate for each in context.  The pentatonic is not low brow as implied, nor is it a prison that you can't hit notes outside of.
Comment: "All blues is based off the pentatonic scales" -- well, that just isn't true. And I never implied that pentatonic is lowbrow, or that you couldn't use other notes. Merely pointing out that pentatonic scales are not always the basis from which players operate. There are an awful lot of varieties of the blues these days, you know....
Comment: BTW, no need to think of diminished scales as substitutions here. You can play the Half-Whole Diminished scale over alt chords (or the alt scale, for that matter), and alt chords are straight-up dominant 7th chords.

Music Mode what mode is song in?


Installing windows OS on iSCSI san storage using iPXE BOOT

Question: Captured boot up process
I'm trying to make a diskless PC client and install the operating system on a SAN Storage. As of now I'm using Windows Server 2012 R2 and it will serve as my DHCP/WDS and SAN server.
I found a video from yourtube on "Bjørn Jentoft" channel with the title "Hyper-V: Windows installation to ISCSI disk".  I followed all the steps and configurations but it didn't quite work for me.
I keep repeating his video to see if I missed something on the configuration steps, but when I checked everything it appears that I didn't miss anything based on what he showed on the video tutorial.
By the way he used HYPER-V on his tutorial and I'm using physical machines.
Answer: I've read about different successful iPXE implementations with StarWind iSCSI target, but haven't tested myself yet.
Here is an article that you may find helpfull: https://jonmccune.wordpress.com/2011/12/19/diskless-windows-7-with-iscsi-and-gpxe/
Comment: The link probably works fine, but it refers to gPXE and I think it should be clearly stated that gPXE is out of date and not maintained, so anything in that article that says gPXE should be replaces with iPXE, and there might be better way to do some things. for example replace `dhcp net0` with just `dhcp` and `set keep-san` is no longer used.
Answer: Message show in the image is:
tftp://192.168.1.1/client1.txt... No such file or directory (http://ipxe.org/2d12603b)
So the file "does not exist" on the tftp server and following that link there is some suggestions:

Check that you are attempting to download the correct file.
Check that you can retrieve the file using an alternative TFTP client, such as tftp-hpa on Linux.

My suggestion in a case like this is to check the tftp servers log, or resort to packet dumps (for example with wireshark) to see what is going on.
In this case my guess is on that Windows TFTP server has not been configured to allow that path. Normally it only accepts paths that starts with Boot, see this documentation: http://ipxe.org/appnote/chainload_wds
And here is a guide for what seems to be exactly this scenario: http://ipxe.org/howto/wds_iscsi