Computation of the integral $\int_{0}^\infty \left( \frac{e^{\sqrt{2y}}-1}{\sqrt{2y}}\right)^2e^{-y}dy$

Question: I am currently struggling on the computation of the following integral:
$$I\triangleq \int_{0}^\infty \left( \frac{e^{\sqrt{2y}}-1}{\sqrt{2y}}\right)^2e^{-y}dy.$$
My attempt
I have tried a the change of vartiable $y=u^2/2$ to have more "gaussian" integral forms, thus we have:
$$I = \int_0^\infty  \frac{(e^{u}-1)^2}{u}e^{-u^2/2}du.$$
But I don't know what to do with that, does anyone have an idea ?
Thank you very much!
Comment: Hint: write $\frac{1}{u}=\int_{0}^{\infty}e^{-ut}\,\mathrm{d}t$. Mathematica gives $$I=\frac{\pi}{2}\left(\mathrm{erfi}\left(\sqrt{2}\right)-2\mathrm{erfi}\left(\frac{1}{\sqrt{2}}\right)\right)+2{}_2F_2\left(1,1;\frac{3}{2},2;2\right)-{}_2F_2\left(1,1;\frac{3}{2},2;\frac{1}{2}\right).$$
Comment: Thank you @KStarGamer ! With your hint (and Fubini theorem), I have $I = \int_0^\infty \int_0^\infty e^{-ut}(e^u-1)^2e^{-u^2/2}dudt$. By putting the $e^{-ut}$ into the gaussian exponential, I have some $e^{t^2}$ when I try to make a quadratic form appear, do you have any more hint please ? Thank you very much!
Answer: $$\frac{\left(e^u-1\right)^2}{u}=\sum_{n=0}^\infty \frac{2 \left(2^n-1\right) }{(n+1)!}u^n$$
$$J_n=\int_0^\infty u^n \,e^{-\frac{u^2}{2}}\,du=2^{\frac{n-1}{2}}\,\, \Gamma \left(\frac{n+1}{2}\right)$$ gives
$$I = \int_0^\infty  \frac{(e^{u}-1)^2}{u}\,e^{-\frac{u^2}{2}}\,du=\sum_{n=0}^\infty \frac{2^{\frac{n+1}{2}} \left(2^n-1\right) \Gamma
   \left(\frac{n+1}{2}\right)}{(n+1)!}$$
If $a_n$ is the summand
$$\frac{a_{n+1}}{a_n}\sim \frac{\left(2^{n+1}-1\right) (4 n-7)}{4 \left(2^n-1\right)
   n^{3/2}} \sim \frac 2{\sqrt n}$$
Using Mathematica
$$\sum_{n=0}^\infty \frac{2^{\frac{3 n+1}{2}} \Gamma
   \left(\frac{n+1}{2}\right)}{(n+1)!}=2 \, _2F_2\left(1,1;\frac{3}{2},2;2\right)+\frac{\pi}{2}
   \text{erfi}\left(\sqrt{2}\right)$$
$$\sum_{n=0}^\infty \frac{2^{\frac{
 n+1}{2}} \Gamma
   \left(\frac{n+1}{2}\right)}{(n+1)!}=\, _2F_2\left(1,1;\frac{3}{2},2;\frac{1}{2}\right)+\pi
   \text{erfi}\left(\frac{1}{\sqrt{2}}\right)$$
Recombining
$$\large\color{blue}{I=2 \, _2F_2\left(1,1;\frac{3}{2},2;2\right)-\,
   _2F_2\left(1,1;\frac{3}{2},2;\frac{1}{2}\right)+}$$ $$\large\color{blue}{\frac{\pi}{2}   \left(\text{erfi}\left(\sqrt{2}\right)-2
   \text{erfi}\left(\frac{1}{\sqrt{2}}\right)\right)}$$


Prove the inequality for mean curvature of a closed surface $M$

Question:
Let $M$ be the closed surface generated by carrying a small circle
  with radius $r$ around a closed curve $C$ embedded in $\mathbb R^3$
  such that the center moves along $C$ and the circle is in the normal
  plane to $C$ at each point. Prove that $$\int_M H^2 d\sigma \geq 2\pi^2,$$ and the  equality holds if and only if $C$ is a circle with
  radius $\sqrt{2}r$. Here $H$ is the mean curvature of $M$ and $d\sigma$ is
  the area element of $M$.

Assume the curve $C$ is $\alpha(s):[a,b]\to \mathbb R^3$, so the surface can be represented by $$X(s,\theta)=\alpha(s)+r\cos(\theta)n(s)+r\sin(\theta)b(s).$$
I calculated $H$ but it's hard to figure out the integral :(
Comment: Not necessary to do the integral, only to bound it from below. This relates to Fenchel's theorem for the closed curve $C.$
Comment: Note that the relationship to Fenchel's uses $\kappa \neq 0.$
Answer: This is a classical result that you can find on p.274 of T.J. Willmore's Riemannian Geometry with a fairly complete calculation. The integral turns out to be quite tricky so even Willmore refers to Mathematica!
Comment: pages 113-114 in his Total Curvature in Riemannian Geometry. Very little calculation, he relates it to Fenchel's theorem, pages 90 and 97.


How do I get the ID value from a URL

Question: example.com:8080/browse?category=137 is my URL for a taxonomy category page.
How am I supposed to take the category ID (137) from that URI?
Answer: You can take that id from get array, try
print $_GET['category'];

Answer: If you are using Drupal 7 then you can make use of existing function drupal_get_query_parameters
But also you can use

$_GET['category']

Make sure you use check_plain() to be sure of save URL values.

How do I get the ID value from a URL


Markov Chain Example

Question: I'm new at this topic and I didnt understand how can I solve that kind of problem:
A center which can call 0 or 1
may be reverted with prob. 0.01 as it travels btw 2 successive centers. Let Xn
be the digit received by the n'th center on the communication system.
Answer: I will assume here that a digit being 'reverted' means a digit being 'flipped', e.g., a 0 may turn into a 1, and vice versa. I am otherwise unfamiliar with the term.
Let's define a state $x=[p_0, p_1]$, where $p_0$ is the probability of your digit being in state 0 and $p_1$ is the probability of your digit being in state 1. In your case, the initial state $x_0 = [1,0]$.
Now, we send it off to the next link in the communication chain. Each digit has a probability $0.01$ of being flipped in transit. We can represent this as a transition matrix $T$:
$$
T=\begin{bmatrix}.99&.01\\.01&.99\end{bmatrix}
$$
Multiplying the transition matrix into your initial state yields the probability of finding each digit after that first step:
$$
x_1 = T\cdot x_0=\begin{bmatrix}.99&.01\\.01&.99\end{bmatrix}\cdot \begin{bmatrix}1\\0\end{bmatrix}= \begin{bmatrix}0.99\\0.01\end{bmatrix}
$$
We see that after one transmission, the odds of finding that your digit is 0 are 0.99, and the odds of finding your digit is 1 are 0.01.
For the $n^{th}$ station, we can find the transition probability as:
$$
x_n = T^n\cdot x_0=\begin{bmatrix}.99&.01\\.01&.99\end{bmatrix}^n\cdot \begin{bmatrix}1\\0\end{bmatrix}
$$
Let's solve this problem for n=3 in python:
import numpy as np

x_i = [1, 0]
T = np.matrix([[.99, 0.01],[0.01,.99]])
T_3 = np.linalg.matrix_power(T, 3)
print(np.dot(T, x_i))

We find (rounding to two digits for clearer presentation).
$$
x_3 = T^3\cdot s_0=\begin{bmatrix}0.97\\0.03\end{bmatrix}
$$
In other words, the probability that the third center receives the same digit is 0.97.
It's also good to check our intuition in the extreme case that $n\rightarrow\inf$. If we have some chance of flipping our digit at every station, then after enough stations we might expect equal odds of seeing a 0 or a 1, whatever our original input. Let's try:
trans_mat_1000 = np.linalg.matrix_power(trans_mat, 1000)
print(np.dot(T, x_i))

Indeed, we find:
$$
x_{1000} = T^{1000}\cdot x_0=\begin{bmatrix}0.50\\0.50\end{bmatrix}
$$
This should give us some comfort in our implementation.

Markov Chain Example


cloud function and jwt Google token request

Question: I know that I should use the cloud function service account to access to my bigquery but for my specific needs I want to have the choice of my service account.
So I decided to generate a token and use this token with the Google JWT client. The code (I retrieed in the Google example library) is working perfectly in local but when I try to deploy gcloud raises an error. I don't understand why and I don't know what way to explore to solve that.
const {JWT} = require('google-auth-library');
exports.getGoogleToken = (req,res) => {
    const client = new JWT(
    key.client_email,
    null,
    key.private_key,
    ['https://www.googleapis.com/auth/cloud-platform','https://www.googleapis.com/auth/bigquery','https://www.googleapis.com/auth/bigquery.insertdata']
  );
  await client.authorize();
  const url = `https://www.googleapis.com/bigquery/v2/projects`;
  const response = await client.request({url});
  authorization=response.config.headers.Authorization;
  res.status(200).send(authorization);
}

To deploy the function I use this syntax :
gcloud functions deploy getGoogleToken --region=europe-west1 --memory=128MB --trigger-http --timeout=60

And I get this error :
**ERROR**: (gcloud.functions.deploy) OperationError: code=3, message=Function
load error: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/index.js:32
await client.authorize();
      ^^^^^^

SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at getUserFunction (/var/tmp/worker/worker.js:388:24)

I suppose the library is not supported by Google cloud functions but it's a Google library?
Could someone help me please ?
Have a great day
Answer: My bad sorry, but if someone is asking the same question just read that.
For the moment cloud function is working with nodejs Version 6 and this code is using await/async requires higher version of nodejs.
You can solve this problem by using beta (Be carefull beta means there is no garantee and no SLA)
the deployment syntax is this one :
gcloud beta functions deploy [functionName] --runtime nodejs8

Replace [functionName] by your function name.
Note the word "beta" in the second place of the syntax.


Apply SSL into IONIC Apps or Angular Web

Question: I am new to this.
I have a app that build with IONIC, the backends(authentication, storage, DB) are running at firebase, and the IONIC will call some 3rd party API or my own API that build with node.js and hosted at heroku.
I would like to implement SSL to achieve point to point encryption, so that the real client data won't being hijack by fraud public wifi.
I have no clue where to start and how to do it, please advise and recommend.
Thank you.
Answer: All access to Firebase's backend services goes through secure connections (HTTPS/SSL). There is no way to access them through a non-secured connection.
To access for example the Firebase Database from your Ionic application, have a look at the documentation on getting started for web developers.
Comment: is that mean, by default, the connection with firebase is already secured with HTTPS/SSL?
Comment: The only way to access Firebase backend services is through a secured connection. So if you have that code accesses Firebase backend services, that will be going through a secure connection.
Comment: other than firebase? like node.js etc, have any idea?


How can I stop auto uploading of managed_file elements?

Question: I am trying to create a field to upload the xml format of site map. But when I add a file to my filed it automatically uploaded and saved in the S3 bucket before I click on the submit button.
The issue is when someone added a xml file to that field and then closes the tab without submitting the form. The xml file is already uploaded to S3 bucket that way.
I need a way to manually upload this. I need to upload the image only after I pressed the submit button in the form. Without uploading the xml file automatically when selecting.
This is my buildForm() function.
public function buildForm(array $form, FormStateInterface $form_state) {

  $form['sitemap'] = [
    '#type'              => 'managed_file',
    '#name'              => 'sitemap',
    '#title'             => t('Upload Site Map (xml)'),
    '#upload_location'   => 's3://private/sitemap',
    '#field_suffix'      => 'XML format supported',
    '#upload_validators' => [
      'file_validate_extensions' => ['xml'],
    ],
    '#required'          => TRUE,
    '#validated'         => TRUE,
  ];

  $form['submit'] = [
    '#type'       => 'submit',
    '#value'      => t('Save configuration'),
    '#attributes' => [],
    '#validated'  => TRUE,
  ];

  return $form;
}

Comment: Override the #attached or remove the "file/drupal.file" library from it or write js that overrides the Drupal.behaviors.fileAutoUpload
Comment: I have found a way !! Drupal has a hidden submit button for upload the file automatically. Remove that button with jquery or js so the file won't upload automatically. You can find the button with inspect element. The button has the class `js-hide button js-form-submit form-submit`. Peace !
Comment: That should be okay imho. There was extra work done in order to achieve the functionality of auto-upload as it improves the UX process a lot. The uploaded files are saved with a `status` of `0` and are mostly cleared on cron run.
Comment: @AjitS Yes true, but there are some things that I want to do before uploading the xml. I can write that in `submitForm(array &$form, FormStateInterface $form_state)`. But the thing is it only executes after I clicked on the submit button. Is there a way to do it before auto upload happens?
Comment: @IvanJaros Could you please elaborate more. I have found `Drupal.behaviors.fileAutoUpload`. But I don't know to edit it
Answer: Try overriding the #attached library on the managed file field:
$form['sitemap'] = [
'#type'              => 'managed_file',
'#name'              => 'sitemap',
'#title'             => t('Upload Site Map (xml)'),
'#upload_location'   => 's3://private/sitemap',
'#field_suffix'      => 'XML format supported',
'#upload_validators' => [
  'file_validate_extensions' => ['xml'],
],
'#required'          => TRUE,
'#validated'         => TRUE,
'#attached'          => [
   'library' => [],
 ]

];
Comment: This works perfectly.
Answer: I have stopped the managed_file auto uploading this way. This is like a workaround. But this works. You better put this in the $(document).ready in the js file.
(function($) {
    $(document).ready(function() {
        /*Drupal has a hidden submit button for upload the file
          automatically. This will remove the button so Drupal won't auto upload for the given managed_file field*/
        $("input[name*='name_of_the_button']").remove();
    });
}(jQuery));

note - make sure you find the correct button. This is not your upload file button. This is the button that drupal creates automatically to do the file upload. This button is not visible in the page. So you need to go the inspect element and find this button. The button has the class js-hide button js-form-submit form-submit. So you won't miss !
Comment: It work to remove only hide button. But on saving form data, image will  not be saved as its not working for me.


Como faço para saber a hora e a data de um local com PHP?

Question: Pretendo armazenar em uma variável a hora atual de Portugal e em outra variável a data atual de Portugal.
Como poderei fazer?
Answer: Podes fazer assim:
date_default_timezone_set('Europe/Lisbon');

$dia = date('Y-m-d'); // 2016-12-24
$hora = date('G:i'); // 16:29

DEMONSTRAÇÃO
Nota que na demonstração, a hora não está bem, mas deve ser por causa da plataforma ideone.
Answer: Configure o date_default_timezone_set para Europe/Lisbon e veja funcionando aqui no ideone:
date_default_timezone_set('Europe/Lisbon');

$date = time();
$date = date('Y-m-d', $date);
$hour = date('H:i:s', $date);
echo "Data: ".$date."\n";
echo "Hora: ".$hour;

Você pode conferir a lista de suporte de Fusos horários aqui na documentação do PHP.


Create custom plugin for Icinga2

Question: I am a beginner in icinga and nagios usage for server management. I setup icinga on a machine and set up all the basics. The next step I tried was to check if certain services were running at ports 8080, 8081 and 8082 or not. I wrote a quick python script for that. I placed that file under /usr/local/lib/myscript.py. The next step I did was to create a command under /etc/nagios-plugins/config/testone.cfg . My command looks like this
define command{
        command_name    check_restarts
        command_line    python /usr/local/lib/myscript.py -w 3 -c 5 -p 8080
        command_line    python /usr/local/lib/myscript.py -w 3 -c 5 -p 8081
        command_line    python /usr/local/lib/myscript.py -w 3 -c 5 -p 8082
        }

I then added a service to services.conf under /etc/icinga2/conf.d/services.conf. But this leads to an error when I restart icinga which shows up a message Backend icinga not running on the UI and errors point to services.conf when I try sudo service icings2 status.
Can anyone please guid me around these steps?
Answer: Don't get confused with Icinga and Icinga2. They are different tools.
Icinga2 configuration format is different from Icinga and Nagios.
So there is a big change in configuring objects in icinga2.
See the official migration doc: URL
So for your case, you need to use CheckCommand instead of command. Also service definition needs to be changed.
All config files are inside /etc/icinga2 dir and Plugin dir should be defined inside /etc/icinga2/constants.conf file.
check Icinga2 config files for syntax errors before restart/reload with command: /etc/init.d/icinga2 checkconfig
Answer: A nice way to get some more information is to run this command: icinga2 daemon -C.
It does pretty much the same as /etc/init.d/icinga2 checkconfig pointed out by 7171u.

Create custom plugin for Icinga2


pgpool for MySQL?

Question: Is there something like pgpool for MySQL?
It seems like there ought to be, and it'd be tremendously useful, but I've never heard of one.
Answer: Have you looked at MySQL_Proxy?
Comment: That looks pretty nice.  I'm most interested in the parallel query feature, and it's not clear if/how MySQL Proxy supports that, but it's certainly worth a look!

pgpool for MySQL?


Definir variável de acordo com registro de número até número

Question: Eu tenho o seguinte ideia:
$quantidade = $rowcount;
if $quantidade (?) '(?)') {
$valor = '1';

Eu preciso definir o $valor seguindo:
de 100 a 499 = 1
de 500 a 999 = 2
de 1000 a 1499 = 3
de 1500 a 1999 = 4
de 2000 a 3999 = 5
acima de 4000 = quantidade*valor

Alguém podem me ajudar?
Comment: Essencialmente é isto: https://pt.stackoverflow.com/q/258024/101
Comment: Supondo que isso vem de um banco de dados, eu já traria calculado de lá, via SQL.
Comment: ta faltando um ( ai no if
Answer: Você pode usar um if e uma array, por exemplo:
if($quantidade >= 4000){
    echo $quantidade * 0.03;
} elseif ($quantidade >= 100) {
    echo [1,2,3,4,5,5,5,5][(int)$quantidade/500];
}

Se o número for maior ou igual a 4000 irá multiplicar por 0.03. Se ele for menor que 4000 e maior que 100 ele irá pegar o valor da array, que é exatamente 1 até 5.
Answer: Simplesmente use if, que teria o mesmo efeito do seu switch, só que provavelmente o código ficaria um pouco menor (sem necessidade de break de case):
$valor = <valor inicial aqui>;
$quantidade = $rowcount;

if ($quantidade >= 4000) {
    $valor = $quantidade * $valor;
} elseif ($quantidade >= 2000) {
    $valor = 5;
} elseif ($quantidade >= 1500) {
    $valor = 4;
} elseif ($quantidade >= 1000) {
    $valor = 3;
} elseif ($quantidade >= 500) {
    $valor = 2;
} elseif ($quantidade >= 100) {
    $valor = 1;
} else {
    die('O valor inserido é menor que 100');
}

echo $valor;

Veja ficou até que bem legível e simples de compreender
Answer: Obrigado Inkeliz.
Eu acabai fazendo assim:
switch($quantidade) {
    case ($quantidade <= '100'): {
        $valor = '1';
        break;
    }
    case ($quantidade <= '500'): {
....

 default: {
        $valor = $rowcount*valor;
    }
}

Comment: Então se for menor que 100 deve ser 1 também?


A completely regular space is a Hausdorff space

Question: A completely regular space is a $T_1$ space $X$ with the property that if $x\in X$ and $F$ is any closed subspace of $X$ which does not contain $x$ then there exists a function $f\in\mathcal{C}(X,\mathbb{R})$, such that $f(x)=0$ and $f(F)=1$. (Here $\mathcal{C}(X,\mathbb{R})$ is the class of all bounded continuous real functions on $X$).
Though it is intuitively clear, how does this imply that every completely regular space is a Hausdorff space?
Answer: In a $T_1$ space sets consisting of single points are closed sets. Just use such a set for your $\cal C$.
Edit, to reply to a comment: Now choose a continuous function $f$ like the one which is guaranteed by the regularity assumption. Then look at the sets $f^{-1}((3/4, 5/4))$ and $f^{-1}(-1/4, 1/4)$, these are disjoint open neighbourhoods of the points under consideration. Hence $X$ is $T_2$.
Comment: Choose a continous function $f$ which separates the points (which exists by the regularity assumption) and consider $f^{-1}$ applied to disjoint open neighbourhoods of ${0}$ and ${1}$.
Comment: how does that imply Hausdroff? we need to show that two distinct points have disjoint open neighbourhoods right?
Comment: Nice one, that explains it.


OAuth - O que é? Qual sua finalidade?

Question:
O que é OAuth?
Qual sua finalidade?
O que ele faz?
Existe outras tecnologias alternativas a ele?
Comment: Quem votou negativo, será que poderia me dizer o motivo por favor, agradeceria muito?
Comment: Não é bem um acesso a banco de dados de outro domínio que ocorre. Acredito que para isso eles usem uma técnica chamada oAuth. http://www.diogomafra.com.br/2010/09/como-funciona-autenticacao-oauth.html
Comment: [OWIN e OAuth O que são e como utilizar?](http://pt.stackoverflow.com/a/76638/70)
Answer: O que é OAuth 2.0 e qual a sua utilidade?
O OAuth é um protocolo de autorização para API's web voltado a permitir que aplicações client acessem um recurso protegido em nome de um usuário.
Quando desenvolvemos uma API web temos em mente que ela seja consumida por aplicações client. A ideia é que a lógica de negócio em si e os dados da aplicação podem ser acessados por meio de uma API web. O que o usuário final vai realmente usar, por outro lado, é um exemplo de aplicação client.
Um exemplo disso seria com as aplicações de página única (SPA's) construídas em JavaScript, ou então um aplicativo móvel construído com android.
Além disso, as aplicações client não são necessariamente só as aplicações que interagem diretamente com o usuário final. Qualquer aplicação que para seu funcionamento precisa utilizar a API web construída é uma aplicação client dessa API.
Nesse sentido, quando utilizamos API's web é comum e necessário considerarmos que uma ou mais aplicações vão precisar interagir com essa API. Mais do que isso, é comum que aplicações de terceiros precisem usar essas API's.
Se existem recursos protegidos na API, ou seja, que devem ter o acesso controlado e só podem ser acessados por um usuário específico, então é preciso considerar como levar em conta essas diversas aplicações client, porque afinal, o usuário não vai a acessar o recurso diretamente, mas vai, na verdade, delegar essa tarefa a uma aplicação client.
Uma opção inicial seria que o usuário especificasse em cada aplicação client os seus dados de acesso (como login e senha), mas isso tem alguns problemas. Alguns desses problemas são listados na própria especificação, que estão abaixo em tradução livre:

As aplicações de terceiros precisam salvar as credenciais do usuário para uso futuro, tipicamente uma senha em texto claro.

Os servidores precisam suportar autenticação por senha, apesar das falhas de segurança inerentes a esse tipo de autenticação.

As aplicações de terceiros ganham um acesso muito amplo aos recursos protegidos do usuário, deixando o usuário sem a possibilidade de restringir a duração desse acesso ou limitar o acesso a um subconjunto dos recursos.

Os usuários não podem revogar o acesso a uma aplicação de terceiro de forma individualizada sem revogar o acesso a todas as aplicações de terceiros, e para fazer isso é necessário trocar a senha.

É por isso tudo que é necessário o OAuth para fazer autorização de forma segura e coerente no contexto de API's web.
O que o OAuth 2.0 faz?
O OAuth, sendo uma especificação, descreve de forma detalhada uma maneira de tratar todos os problemas considerados. Ele estabelece definições como:

Resource Owner: a entidade que é capaz de controlar o acesso a um recurso protegido. É o "dono do recurso", mas nem sempre é uma pessoa. Quando ele é uma pessoa ele é o usuário final.

Resource Server: o servidor que possui os recursos protegidos e recebe as requisições para acessar esses recursos.

Authorization Server: é um servidor que gera tokens de acesso para permitir que o client acesse os recursos que o resource owner permitiu com o nível de acesso que o resource owner especificou.

Client: é a aplicação que acessa os recursos no resource server em nome do usuário. O client pode ser qualquer tipo de aplicação que faça isso.

Com essas definições, o OAuth estabelece que quando uma aplicação client precisa acessar um recurso protegido no resource server ele deve obter um "token de acesso". Esse "token de acesso" é um token contendo as informações que caracterizam o acesso que o resource owner permitiu aos recursos protegidos.
Perceba que isso resolve os problemas especificados pois: o client não precisa das credenciais do resource owner, somente precisa de um token gerado pelo authorization server, que é uma aplicação confiável. Através do token, o resource owner pode especificar um acesso personalizado, e permitir ao client acesso somente a um subconjunto dos recursos protegidos. Além disso, é fácil revogar o acesso, pois basta invalidar o token concedido, sem falar que os tokens possuem um tempo de vida específico e não podem ser usados para sempre.
Além disso tudo, o OAuth especifica fluxos. Cada fluxo é para uma situação particular de interação entre cliente, authorization server e resource server. Esses fluxos são detalhados e dizem todos os passos necessários para, naquele caso, obter o acesso desejado. Para ver esses fluxos em detalhes é recomendável olhar na especificação.
Existem alternativas?
Existem outras formas de gerenciar autorização em API's web como o tradicional modo de usar usuário e senha, mas como já explicado, esses métodos mais tradicionais tendem a ter alguns problemas que o OAuth foi pensado para resolver.
Comment: Dei a recompensa sem querer errado, mas pode ficar tranquilo que assim que eu conseguir completar 1200 de pontuação eu ofereço outra recompensa na pergunta de novo para dar pra você. Por quê agora o mínimo é 200. Estou tipo, meu Deus como eu sou lerdo e distraído pra não perceber isso
Comment: @José, na verdade não é bem assim. O OAuth é uma especificação, é algo abstrato. Em geral existem bibliotecas para te auxiliar a implementar o OAuth na sua aplicação. Por exemplo, no ASP.NET Core existe o Identity Server 4, mas não é a única opção. É importante entender essa distinção: o OAuth é uma especificação, um contrato que diz o que deve ser feito, quais fluxos devem estar presentes e como tudo deve acontecer, e aí tem as implementações concretas que se devem seguir a especificação.
Comment: Pra eu instalar é só baixar a extensão dll e pronto?
Comment: Bacana sua resposta @Leonardo, já deixei o meu +1 a muito tempo. Quer ganhar mais 200 pontos? Me ajude aqui: [Como implementar a autorização do google no asp.net core?](https://pt.stackoverflow.com/questions/320643/como-implementar-a-autoriza%C3%A7%C3%A3o-do-google-no-asp-net-core) :)
Answer: O que é OAuth?
O OAuth é um protocolo de autorização muito utilizado em aplicações web escaláveis. A versão atual é a 2.0 e utiliza tokens para acessar seus dados em outro sistema e provavelmente em outro banco de dados.
Tem a documentação e exemplos na página oficial: link
Qual sua utilidade?
Você já pensou em como é feito o acesso a sua conta Google ou Facebook nos jogos do Android? Pois bem, é usando esse protocolo.
Ele possibilita que outros sistemas acessem alguns dados sem que você precise fazer login com usuário e senha ou informe seus dados sempre, retornando tokens de autorização.
Como usar?
Na documentação oficial tem alguns exemplos em diversas linguagens, você pode criar clientes para consumir dados do Facebook, por exemplo, ou criar um servidor de autorização para que outros sistemas consumam ele.
Verifique algumas documentações sobre a implementação:
Facebook
Google
(Opcional) Como posso aplicar ao meu script PHP?
Vai depender do que você precisa fazer. Eu, por exemplo, crio algumas aplicações com login através do Facebook e do Google, você pode fazer isso. Além de poder implementar o PayPal, pagseguro e outros sistemas usando-o.
Comment: Uma dúvida, ele pega informações dos servidores além de dados com permissão do usuário?
Comment: Sim. Ele dá permissões para que você acesse informações diversas. Por exemplo: no Facebook é possível acessar a lista de amigos, dados de cadastro etc.

OAuth - O que é? Qual sua finalidade?


Client side data compress/decompress?

Question: I'm looking for a JavaScript implementation of a string compress/decompress algorithm where data is created at the client side and stored in hidden fields within HTML forms.
I read about gzip, but it compresses the data server side whereas in my case I want to compress it client side, send it to the server, or receive it from server to decompress it again at client side.
I found this LZF Compression example based on LZFjs but it will generate binary data which needs to be processed and stored in a hidden form field, and it works on files rather than pure data.
Suggestions on a pure data client-side data compression/decompression that is also efficient?
Comment: possible duplicate of [Javascript client-data compression](http://stackoverflow.com/questions/2252465/javascript-client-data-compression)
Comment: http://danml.com/js/compression.js  you';; want to use atob/btoa to go in-between client and server.
Answer: There is this open-source Javascript compression library, by Pierre curto :
https://github.com/pierrec/node-lz4
Googling around, I also found this zlib implementation (not tested by me) :
http://nodejs.org/api/zlib.html
Comment: Thanks, but I am not working on a node app, I just need the compression code without the related node integration .. may be two function for compress and de-compress
Comment: It no longer needs 'node', and can be integrated directly within the browser.
Answer: You may also try JSZip. To run it in browser you just have to download  and include dist/jszip.js or dist/jszip.min.js.
This is actively supported and supports a wide variety of browsers including everyone's favorite IE6/7/8!
Usage (from their docs):

<code>var zip = new JSZip();

zip.file("Hello.txt", "Hello World\n");

var img = zip.folder("images");
img.file("smile.gif", imgData, {base64: true});

var content = zip.generate({type:"blob"});
</code>

Client side data compress/decompress?


VIF, condition Index and eigenvalues

Question: I am currently assessing multicollinearity in my datasets.
What threshold values of VIF and condition index below/above suggest a problem?
VIF:
I have heard that VIF $\geq 10$ is a problem.
After removing two problem variables, VIF is $\leq 3.96$ for each variable.
Do the variables need more treatment or does this VIF seem fine?
Condition Index:
I have heard that a Condition Index (CI) of 30 or more is a problem.
My highest CI is 16.66. Is this a problem?
Other Issues:

Are there any other dos/donts that need to be considered?
Are there any other things that I need to keep in mind?
Comment: Please clarify the question. In particular, these were some comments from before: By @chl - "you should consider writing clear questions (they are interesting on their own), with one definitive issue, and reserve comments for additional infos relevant to your original question, not follow-up". By @shane - "Regarding this current question: it could also be improved because it's asked many different questions without a clear common thread. Are you interested in multicollinearity in general? Or are you interested in VIF? It would be better to break these out for clarity."
Answer: Multicollinearity problem is well studied in actually most econometric textbooks. Moreover there is a good article in wikipedia which actually summarizes most of the key issues.
In practice one starts to bear in mind the multicollinearity problem if it causes some visual signs of parameter instability (most of them are implied by non (poor) invertability of $X^TX$ matrix):

large changes in parameter estimates while performing rolling regressions or estimates on smaller sub-samples of the data
averaging of parameter estimates, the latter may fall to be insignificant (by $t$ tests) even though junk-regression $F$ test shows high joint significance of the results
VIF statistic (average value of auxiliary regressions) merely depends on your requirements to tolerance level, most practical suggestions put an acceptable tolerance to be lower than 0.2 or 0.1 meaning that corresponding averages of auxiliary regressions $R^2$ should be higher than 0.9 or 0.8 to detect the problem. Thus VIF should be larger than rule-of-thumb's 10 and 5 values. In small samples (less than 50 points) 5 is preferable, in larger you can go to larger values.
Condition index is an alternative to VIF in your case neither VIF nor CI show the problem is left, so you may be satisfied statistically on this result, but...

probably not theoretically, since it may happen (and usually is the case) that you need all variables to be present in the model. Excluding relevant variables (omitted variable problem) will make biased and inconsistent parameter estimates anyway. On the other hand you may be forced to include all focus variables simply because your analysis is based on it. In data-mining approach though you are more technical in searching for the best fit.
So keep in mind the alternatives (that I would use myself):

obtain more data points (recall that VIF requirements are smaller for larger data set and the explanatory variables if they are slowly varying, may change for some crucial points in time or cross-section)
search for lattent factors through principal components (the latter are orthogonal combinations so not multi-collinear by the construction, more over involve all explanatory variables)
ridge-regression (it introduces small bias in parameter estimates, but makes them highly stable)

Some other tricks are in the wiki article noted above.
Answer: I believe Belsely said that CI over 10 is indicative of a possible moderate problem, while over 30 is more severe.
In addition, though, you should look at the variance shared by sets of variables in the high condition indices.  There is debate (or was, last time I read this literature) on whether collinearity that involved one variable and the intercept was problematic or not, and whether centering the offending variable got rid of the problem, or simply moved it elsewhere.

VIF, condition Index and eigenvalues


Build failure when running "mvn clean" for the first time while installing

Question: I'm new to Maven and trying to use this for the first time in my project.
I've set the system variables;
JAVA_HOME System Variable
M2_HOME System Variable
%JAVA_HOME%\bin;%M2_HOME%\bin; to System Path
In cmd prompt using "mvn -version" i can see all relevant details.
But when I run "mvn clean", I get the following error
C:\Users\Naina Mantry>mvn clean

[INFO] Scanning for projects...

[INFO] ------------------------------------------------------------------------

[INFO] BUILD FAILURE

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 0.105 s

[INFO] Finished at: 2016-02-15T08:00:48+05:30

[INFO] Final Memory: 5M/86M

[INFO] ------------------------------------------------------------------------

[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (C:\Users\Naina
 Mantry). Please verify you invoked Maven from the correct directory. -> [Help 1]

[ERROR]

[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

[ERROR] Re-run Maven using the -X switch to enable full debug logging.

[ERROR]

[ERROR] For more information about the errors and possible solutions, please read the following articles:

[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException

I'm not able to understand, how to fix it. kindly help me please...
Thanks in advance :)
Comment: Do you have `pom.xml` inside `C:\Users\Naina Mantry`?
Answer: when you run Maven, you need to run it from your proyect directory, where you have your workspace. You need to have a pom.xml file on that Directory.
For example:
C:\Users\Naina Mantry\workspace\proyect

and on that directory you run mvn clean
Answer: You seem to be executing mvn clean from a wrong directory. Make sure there is a relevant pom.xml. Maven by default refers to the current working directory. Alternately, you can use -f option to specify a pom.xml located in a different directory.

Build failure when running “mvn clean” for the first time while installing


java.net.SocketException: Connection reset when connection time out >0

Question: I am calling an api to send sms with a java apache common client, and it looks like setting a time out for more than 0 is returning a "java.net.SocketException: Connection reset" error.
Here is a the code sample
<code>// creating the http client
HttpClient client = new HttpClient();
</code>
Setting a connection time out of 10 sec (I receive a successful response
          as soon as I remove this part of the code)
<code>client.getHttpConnectionManager().
getParams().setConnectionTimeout(10000);
</code>
Rest of the code
<code>//creating the request method
GetMethod method = new GetMethod(smsUrl);

// setting its params
method.setQueryString(new NameValuePair[] {
        new NameValuePair("username", user),
        new NameValuePair("password", pass),
        new NameValuePair("action", "sendsms"),
        new NameValuePair("from", "Woosh"),
        new NameValuePair("to", toMobile),
        new NameValuePair("text", textBody)
    });

//calling the method
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
        new DefaultHttpMethodRetryHandler(3, false));

int statusCode = client.executeMethod(method);
</code>
Comment: Possible duplicate of [java.net.SocketException: Connection reset](https://stackoverflow.com/questions/62929/java-net-socketexception-connection-reset)
Comment: @LarentB Its a different issue, mine is occurring because I am setting a connection time out. I get a successful response as soon as I don't provide any
Answer: The issue was sorted out, it was an issue caused by the server of the api I was calling. Not sure what was it though


Class isn't recognized

Question: I created a method class that will test the months and days and tell you what the season is. I'm creating a tester class but for some reason it won't recognize the getSeason() class from the methods but it shows they are connected.
Method Code:
public class Season {
    private String season;

    public String getSeason(int month, int day) {
        if (month == 1 || month == 2 || month == 3) {
            season = "Winter";
        } else if (month == 4 || month == 5 || month == 6) {
            season = "Spring";
        } else if (month == 7 || month == 8 || month == 9) {
            season = "Summer";
        } else if (month == 10 || month == 11 || month == 12) {
            season = "Fall";
        }

        if (month % 3 == 0 && day >= 21) {
            if (season.equals("Winter")) {
                season = "Spring";
            } else if (season.equals("Spring")) {
                season = "Summer";
            } else if (season.equals("Summer")) {
                season = "Fall";
            } else {
                season = "Winter";
            }
        }
        return season;
    }
}

Tester Code:
import java.util.Scanner;

public class SeasonTester {
    public static void main(String[] args) {
        Season s = new getSeason();
        Scanner input = new Scanner(System.in);
    }
}

I get a cannot get symbol - class getSeason error when I compile
Comment: Please follow a basic tutorial explaining how to work with objects and how to invoke methods.
Answer: You are calling a method instead of constructor here:
    Season s = new getSeason();

should be
    Season s = new Season();

Then you can call isntance method using this:
s.getSeason();

Comment: I'm very new at Java, this did it. Thanks!

Class isn't recognized


pd.read_table for .dat fills null values

Question: I am trying to learn data analysis using "Python for Data analysis" by WesMcKinney.
There is a .dat file with the following data :
1::F::1::10::48067
2::M::56::16::70072
3::M::25::15::55117
4::M::45::7::02460

I'm trying to import them using :
unames=['user_id', 'gender', 'age', 'occupation', 'zip']
users = pd.read_table('D:/INSOFE/Python_practice/users.dat', sep='::', header=None,names=unames,engine='python')

But, it shows nulls

Please let me know what I'm doing wrong.
Comment: Can't reproduce, when I create the `.dat` file as you provide, and load it via your exact `pd.read_table`, it looks fine on my computer. Perhaps check your path to you `users.dat`, and make sure it's a valid file?
Comment: Could you copy paste the code before `unames` definition?
Comment: It looks like you might have obtained the dat file from a web page, but rather than save the contents of the page, you have saved the page itself (including a bunch of HTML). Could that be it? Try opening the file to see what it contains.
Comment: @sacul : the file path and file both are valid.
Comment: @fuglede : yes, I've opened the file in notepad, it contained the html in it too. https://github.com/wesm/pydata-book/blob/1st-edition/ch02/movielens/users.dat  ,I got it, I will try downloading only the data. I thought .dat files contain html too.
Comment: @fuglede : yes, it worked. Thank you so much for figuring it out.
Answer: The read_table method expects relatively clean data; if you've simply saved the web page containing the table (cf. the clarifying comments), you will end up with a file full of HTML which pandas will not know what to do about.
Instead, you will want to get the raw contents of the file. In principle you could simply copy the 6040 lines from GitHub into your favorite text editor and save the contents as users.dat.
GitHub makes your life a bit simpler than that by supplying a view of the raw data as well.

With that, if you choose to save the file, most browsers (including e.g. Firefox) will produce a proper users.dat with only the data. Command line tools such as wget or curl allow you to get at the same data without having to use a fully-fledged browser.
Comment: yes, you are correct :)..I have downloaded the entire zip folder of the book's code to avoid this confusion. Thanks a lot.


contar quantas vezes a palavra carregada do arquivo txt aparece python

Question: Preciso fazer um programa em que eu salvo um arquivo txt, depois abro e leio ele. Até ai tudo bem. Mas não sei como fazer para mostrar quantas vezes aparece cada palavra do texto aberto aparece.
Ex: O texto aparece a palavra mil 5 vezes, a palavra casa 7 vezes e etc. Como faço pra ler o que está dentro do texto, sem precisar criar uma lista pra isso?
Comment: @AndersonCarlosWoss também pensei nisso, mas acho que esta pode ir por um caminho não tão trabalhoso. A outra implicava a abertura de dois arquivos e processamento dos dados entre eles
Comment: Queres contar apenas quantas vezes aparece uma palavra em especifíco no ficheiro?
Comment: carro casa chocolate prato colher tapete chapa tapete prato prato chocolate
from collections import Counterwith open('/Users/DIGITAL/Desktop/Python/teste.txt') as f:
ocorrencias = Counter(f.read().split())
print(ocorrencias)

As palavras que estao no texto foram essas, so que na hora de ordenar,preciso que apareça em ordem crescente, ta aparecendo assim: choclocate 3 vzs, casa 2.. e eu preciso que apareça ao contrário, do menor para o maior
Comment: Olá acho que deves fazer uma nova pergunta independente desta, essa parte não faz parte nem está de todo comtemplada nesta pergunta/resposta. É melhor apagares o que fizeste em baixo visto que é um espaço exclusivo para respostas. Bem vindo ao Stackoverflow
Answer: Para contar uma palavra podes fazer assim:
palavra = 'casa'
with open('arquivo.txt') as f:
    ocorrencias = f.read().count(palavra)
print(ocorrencias) # num de vezes que a palavra aparece

Feito isto, se quiseres contar todas a ocorrências de todas as palavras:
from collections import Counter

with open('arquivo.txt') as f:
    ocorrencias = Counter(f.read().split())
print(ocorrencias) # num de vezes que as palavras aparecem

NOTA: nesta ultima cria-se uma lista explicíta quando f.read().split(), apesar de não darmos por ela


Pesquisa TMemo Delphi

Question: Boa tarde a todos!
Estou fazendo pesquisa por nome completo em um TMemo com Delphi, quando o nome inteiro encontra-se na mesma linha funciona bacana, porém se parte do nome está numa linha e a outra parte na linha seguinte, a pesquisa não encontra. Alguma ideia pra solucionar isso?
procedure TForm1.BitBtn4Click(Sender: TObject);
var
  acha:string;
begin
  if (Memo1.GetTextLen > 0) then
  begin
    zPessoa.First;

    if not zPessoa.Eof then
      repeat acha:=zPessoanome.Value;

    if pos(acha, AnsiUpperCase(memo1.Lines.text))>0 then begin

Comment: Como está seu código, no momento?
Answer: Deve-se utilizar o Memo.Lines.Text para tal:
  if Pos('Nome', Memo1.Lines.Text) > 0 then
    ShowMessage('Achou')
  else
    ShowMessage('Não achou');

Se precisar saber o número da linha:
var
  i: Integer;
begin
  for i := 0 to Memo1.Lines.Count - 1 do
  begin
    if Pos('Nome', Memo1.Lines[i]) > 0 then
      ShowMessage('Texto encontrado na ' +IntToStr(i+1) +'ª linha');
  end;
end;

No seu código, o problema é que acha também precisa ser UpperCase, senão ele sempre vai comparar, por exemplo, João Silva com JOÃO SILVA, o que sempre vai dar diferença.
if not zPessoa.Eof then
   repeat acha := AnsiUpperCase(zPessoanome.Value);

Após o assunto ser melhor explicado, o seu problema pode ser resolvido substituindo a quebra de linha por espaço, utilizando Replace (StrUtils):
if Pos('Nome', Memo1.Lines.Text.Replace(sLineBreak, ' ')) > 0 then
  ShowMessage('Achou')

Comment: O código tá funcionando muito bem, o problema é que ele não encontra o nome que esteja numa quebra de linha.
Comment: Tipo: Marques Leão Magalhães, assim acha com ou sem acentuação!
Comment: Mas: Marques Leão (Final de uma linha)
Magalhães (Inicio da próxima).
Comment: Substitua a quebra de linha por espaço. Editei minha resposta com um exemplo.
Answer: Bom dia a todos!
Agradeço aos que se interessaram em me ajudar! Resolvi o problema fora da rotina, como precisava copiar o texto do diário oficial pro Memo, antes de "despeja-lo" lá, jogo no Notepad++, transformo em uma única linha e problema resolvido!
Comment: Fico feliz que tenha resolvido. Mas para efeitos de ajudar as próximas pessoas que tiverem um problema semelhante, poderia dizer se a minha resposta funcionou ou não para seu caso? Eu havia proposto substituir a quebra de linha por um espaço, que teria o mesmo efeito que você executou fora da rotina.
Comment: Obrigado Cleber Griff! Não funcionou, inclusive, constatei que quando essa situação ocorre dentro do Word, com a busca do próprio, não funciona...
Comment: Nem com o ``.Replace(sLineBreak, ' ')`` ? Fiquei curioso rs

Pesquisa TMemo Delphi


Slashes in single route parameter or other ways to handle a menu tail with dynamic number of params

Question: According to the Symfony documentation, a route defined as below should trigger the specified controller for both /hello/bob and /hello/bob/bobby:
_hello:
  path:     /hello/{names}
  defaults: { _controller: \Drupal\mymodule\Controller\Main::Controller }
  requirements:
    _access: 'TRUE'
    names: .+

In the case of a request to /hello/bob/bobby the {names} param would be "bob/bobby" (slash intact) and it would be up to the controller to break that down into multiple variables or to leave it as a single string. The trick to that is the altered regex (".+") used to filter that {names} param.
This stackoverflow post also implies that custom regex can be used to allow slashes in a route param (at least in Symfony 2).
If I try this against Drupal 8.0.0-beta15 it does not work and the specified controller is only triggered for a request to /hello/bob. However, I can confirm that this used to work in previous betas (I think up until ~beta13).
Has something changed in the way Drupal integrates with the Symfony routing component that would explain this? Perhaps there is an alternate way to accomplish the passing of slashes in routing params? I know there is a movement toward Symfony 3.0 in core, but I'm not sure if that could explain things.
I also know that route subscribers are available to manage dynamic route structures. However the case I am working on requires an almost infinite combination/number of dynamic parameters at the end of a base path (but which are trivial to parse in my controller). I'm also trying to avoid query strings (e.g. /hello?names[]=bob&names[]=bobby) for this case.
Mainly I'm just confused as to the disconnect with the Symfony documentation, which seems to state that this should be possible.

Additional Notes
After posting this question I discovered this discussion in the D8 core queues: [Discussion] Drop automated passing of extra argument: Y/N. It seems to conclude that "menu tail" support (which is essentially what I am after) will officially be dropped in D8. That discussion ended 3 years ago and so I can only guess that some of the more generalized implementation specifics were not fully realized until recently (~beta13). This may explain why I've only now noticed this change.
I'm guessing that Drupal (not Symfony) is now generating a 404 response based on the raw slash-delimited request before any of the Symfony-specific routing logic further dissects the route (and it's param-specific regex, etc.). If this is the case it could explain why technique above stopped working. I am still wondering however if there are alternative ways to deal with this need that avoid using query params and custom route subscribers.
Comment: It's not clear what `path:     /hello/{names}` and `username: .+` have to do with each other.
Comment: From what I know about Symfony I would expect /hello/{username} to match on /hello/bob but not on /hello/bob/smith. If you want additional parameters, you have to set defaults for them as in http://stackoverflow.com/questions/11980175/how-can-i-have-optional-parameters-in-symfony2-route. But maybe I don't understand the question.
Comment: Configuring defaults works as expected (i.e. it's possible to set {names} as an optional param). So yes, I suppose I could have a route path like /hello/{arg1}/{arg2}/{arg3}/.../{argN}, which could work with 0-N params. However that sets a static limit on the number of params and feels pretty messy. My understanding that it should be possible to do this differently, via slash delimiters in a single param, is based on the Symfony documentation (http://symfony.com/doc/master/cookbook/routing/slash_in_parameter.html) along with previous experience with older Drupal core betas.
Comment: @chx, sorry, I had edited my question right after posting in an effort to make it more generic. In that process I forgot to update the yml snippet. I've fixed that. It should read "names: .+"
Comment: I just noticed that my last comment may give the impression that I solved things. Please note that I only had a typo in my post. The question/issue still stands as it's now phrased.
Comment: @rjacobs -- I'm a little puzzled here as well.  If you look at system.routing.yml, you'll see that your trick is used in core, to handle private files:
Comment: @rjacobs --adding to before...I'm trying to do the what system.module does with private files.  I copied the route definition to my module's *.routing.yml file, changing the route and the path, but keeping "{filepath}" at the end of the path, and "filepath: .+", exactly as system does.  Yet the router doesn't match my URLs.  Why it works for private files and not for my case completely baffles me.
Comment: @Torenware Networks -- This is a very interesting observation. I had a look at the related files controller and I see what you mean. I can't tell for sure if this controller is actually implementing this "menu trail" concept or if it's just leftover logic from earlier versions of core. If the former then I too am at a loss for how it's working in that case and not anywhere else.
Comment: There's a related feature request to add support for slashes in route parameters: https://www.drupal.org/project/drupal/issues/2741939
Comment: @TorenwareNetworks, core handles this with a path processor. See `Drupal\system\PathProcessor\PathProcessorFiles` at `core/modules/system/src/PathProcessor/PathProcessorFiles.php`.
Answer: You can alter the path by adding a class that implements the InboundPathProcessorInterface
namespace Drupal\mymodule\PathProcessor;

use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;

class HelloPathProcessor implements InboundPathProcessorInterface {

  public function processInbound($path, Request $request) {
    if (strpos($path, '/hello/') === 0) {
      $names = preg_replace('|^\/hello\/|', '', $path);
      $names = str_replace('/',':', $names);
      return "/hello/$names";
    }
    return $path;
  }

}

This way the router will interpret the path /hello/bob/bobby as /hello/bob:bobby and you will get the parameters separated by : (or any other character that won't conflict with the parameters) in your controller.
You will also need to register the class as a service in mymodule.services.yml (make sure the priority is set higher than 200)
services:
  mymodule.path_processor:
    class: Drupal\mymodule\PathProcessor\HelloPathProcessor
    tags:
      - { name: path_processor_inbound, priority: 250 }

Comment: Yeah this is a good point, and I suppose this is the same mechanism that's used to do path aliasing? If going this route I assume that the router path would be unchanged (/hello/{names}) and then "names" could still be handled as a single route param. So if a URL using this route was generated programmatically names would still have to be constructed with the custom-delimiters (bob:bobby), but the system would still be *compatible* with more "friendly" URL input (bob/bobby)?
Comment: When I am generating the URL in my twig, it doesn't work. My code: `{{ path(urlPath, {'hello': "name/anothername"}) }}`
Answer: You can do the following to retrieve path params:
In this case, I want to retrieve everything that comes after /rest/ as an array of strings.
Your yourmodule.routing.yml file should look something like this.
yourmodule.rest:
  path: /rest/{path_parms}
  defaults:
    _controller: 'Drupal\yourmodule\Controller\YourController::response'
    _title: 'Rest API Title'
  requirements:
    path_params: '^[^\?]*$'
    _permission: 'access content'

or in path\to\yourmodule\src\Routing\RouteProvider.php
/**
 * @file
 * Contains \Drupal\yourmodule\Routing\RouteProvider.
 */

namespace Drupal\yourmodule\Routing;

use Symfony\Component\Routing\Route;

/**
 * Defines dynamic routes.
 */
class RouteProvider
{
    /**
     * Returns all your module routes.
     *
     * @return RouteCollection
     */
    public function routes()
    {
        $routes = [];

        // This route leads to the JS REST controller
        $routes['yourmodule.rest'] = new Route(
            '/rest/{path_params}',
            [
              '_controller' => '\Drupal\yourmodule\Controller\YourController::response',
              '_title' => 'REST API Title',
            ],
            [
              'path_params' => '^[^\?]*$',
              '_permission' => 'access content',
            ]
        );

        \Drupal::service('router.builder')->setRebuildNeeded();

        return $routes;
    }
}

Next, add a Path processor to your module as follows.
path\to\yourmodule\src\PathProcessor\YourModulePathProcessor.php
namespace Drupal\yourmodule\PathProcessor;

use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;

class YourModulePathProcessor implements InboundPathProcessorInterface {

    public function processInbound($path, Request $request) {
        // If a path begins with `/rest`
        if (strpos($path, '/rest/') === 0) {
            // Transform the rest of the path after `/rest`
            $names = preg_replace('|^\/rest\/|', '', $path);
            $names = str_replace('/',':', $names);

            return "/rest/$names";
        }

        return $path;
    }
}

Finally, in your controller, do this:
path\to\yourmodule\src\Controller\YourController.php
namespace Drupal\yourmodule\Controller;

use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

/**
 * Controller routines for test_api routes.
 */
class YourController extends ControllerBase {

    /**
     * Callback for `rest/{path_params}` API method.
     */
    public function response(Request $request) {
        $params = explode(':', $request->attributes->get('path_params'));

        // The rest of your logic goes here ...
    }

}

Comment: its not working with drupal 8.7.9
Comment: Really? Have you found an alternative though?
Comment: not yet, if you have any solution please share
Comment: Sorry it took me so long, I have updated my post to show what I finally did to get path params. In my own case, I needed it for my custom REST API.
Answer: Alternative solution:
Create a route parameter that receives a json array.

mymodule.routing.yml
_hello:
  path:     /hello/{names}
  defaults: { _controller: \Drupal\mymodule\Controller\Main::index }
  requirements:
    _access: 'TRUE'

\Drupal\mymodule\Controller\Main
public function index($names_json) {
  $names = Json::decode($names_json);
  // Do something with $names
}

Comment: Yes, encoding multiple arguments into one route parameter is certainly an option. I assume you are implying that the "names" param would be a formal php array that's directly encoded/serialized? If so, wouldn't there be more appropriate encoding options for a path component that JSON? Note that this would also make for a much less user-friendly path regardless of the encoding technique (a potential issue for human input, but not necessarily for programmatic path generation).
Comment: Of course you can use any encoding technique you want. I prefer JSON as it is very standardized with an encoder (/decoder) in most languages. This would make paths much less user friendly. If the path is exposed outside then I think passing the names in the query (name[]=Ben&name[]=George) is much more readable.


Maximum safe hard drive temperature?

Question: I have two new-ish 1TB hard drives in my server, both running at 38 degrees C at the moment. Should I be worried?
Comment: Hi, I wasn't logged in when I posted the OP so can't comment on your answers directly.

@Cakemox, thanks for that, seems like I have no worries :)

@Iain, the specs say 0-55 degrees C, however I heard you should take spec sheets with a pinch of salt. Adding to that, according to Google's research (which I've just been looking at), SMART data and manufacturer ratings aren't a very good indicator of imminent drive failure.

@Paul, that sounds like a bug in the SMART reading software. Have you done a smartctl -a on the drive?
Answer: 38C should be fine.  A quick look at some spec sheets shows that operating temperature is 0C to 60C on many models.
You might be interested in section 3.4 of a study done by Google on hard drive failure rates.  Temperature is not an issue in drives until they are a few years older, and even then, it seems, it's not much of an issue under 40C.
Answer: What does the manufacturer's datasheet/documentation have to say about temperature ?
Answer: Be careful of the interpretation of your sensors.  I have Munin running, and the smartd results shows my drives have "Temperature_Celcius" of around 230.0 (which if true would probably indicate they were on fire) but another probe called "HDD Temperature" records them around 27 and 29 C, which seems much more likely to me.
Comment: Most likely the 230.0 should be 23.0, some sensors provides results in 1/10th of a degree, which a lot of programs interpret wrong.
Comment: I think 230.0 is 'VALUE' of smartctl outpit, not 'RAW_VALUE'. Value shows how far your drive from being fault. For example, this is output from smartctl on my note:

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
194 Temperature_Celsius     0x0022   091   085   000    Old_age   Always       -       56

It's templerature is 56 (from raw_value column), not 91 from value col.
Answer: Slightly OT: If you're concerned, I find hddtemp on Linux indispensable:
# hddtemp /dev/sdb
/dev/sdb: ST9160412AS: 43°C
You can run it as a daemon or script around it very easily.

Maximum safe hard drive temperature?


Explicit formula for invariant inner product of the standard representation of $S_3$

Question: Let $V$ be a representation of a group $G$ over $\mathbb{C}$. Given the standard Hermmitian inner product $\langle\cdot,\cdot\rangle$ on $V$ we can always define a $G$-invariant inner product by
$$\langle x,y\rangle_\text{new} := \frac{1}{|G|} \sum_{g \in G} \langle g x, g y\rangle$$
Can anyone calculate this explicitly for the standard representation of $S_3$? Is there any easy way to do this in general (for other reps of $S_n$) aside from the above method?
Comment: There is no "standard" inner product on an abstract vector space. Specifying an inner product on such a space is equivalent to specifying a basis of it, and bases don't always "come in the box." What basis do you want to use for the standard representation of $S_n$?
Comment: If by *standard representation* you mean the rep as $3\times3$ permutation matrices (as opposed to, say, the *regular representaion*), then what's wrong with
$$\langle(x_1,x_2,x_3),(y_1,y_2,y_3)\rangle=x_1\overline{y_1}+x_2\overline{y_2}+x_3\overline{y_3}?$$
Place the bars according to your taste of w.r.t. which slot the Hermitian inner product is linear as opposed conjugate linear.
Comment: @JyrkiLahtonen The [standard rep](http://groupprops.subwiki.org/wiki/Standard_representation) of $S_3$ is $2$-dimensional.
Comment: Thanks for the link, @whacka. So it is a subspace of the 3-d rep I talked about. And we can simply restrict the above Hermitian inner product.
Answer: Let $V = \Bbb C^2$ with the standard basis, and let $\rho: S_3 \to GL_2(\Bbb C)$ be given by:
$\rho(e) = I$, $\rho((1\ 2\ 3)) = \begin{bmatrix}-\frac{1}{2}&-\frac{\sqrt{3}}{2}\\ \frac{\sqrt{3}}{2}&-\frac{1}{2} \end{bmatrix}$,  $\rho((1\ 3\ 2)) = \begin{bmatrix}-\frac{1}{2}&\frac{\sqrt{3}}{2}\\-\frac{\sqrt{3}}{2}&-\frac{1}{2} \end{bmatrix}$
$\rho((2\ 3)) = \begin{bmatrix}1&0\\0&-1\end{bmatrix}$,  $\rho((1\ 2)) = \begin{bmatrix}-\frac{1}{2}&\frac{\sqrt{3}}{2}\\ \frac{\sqrt{3}}{2}&\frac{1}{2} \end{bmatrix}$,  $\rho((1\ 3)) = \begin{bmatrix}-\frac{1}{2}&-\frac{\sqrt{3}}{2}\\-\frac{\sqrt{3}}{2}&\frac{1}{2} \end{bmatrix}$
As one can readily verify, these are isometries under the standard Hermetian inner product, so for each $g \in S_3$ we have:
$\langle gu,gv\rangle = \langle u,v\rangle$, and our $G$-invariant inner product is the same as the standard one.


prove a property for the stabiliser of 0 by the map apply action of a discrete subgroup of Aut(D)

Question: It's a note from Donaldson's Riemann Surface,section 3.2.3.
Aut(D) is the holomorphic automorphism group of the unit disk in the complex plane. Explicitly, all möbius holomorphic maps:
$$
z \mapsto \frac{\alpha z+\beta}{\bar{\beta} z+\bar{\alpha}}
$$
where $|\alpha|^{2}-|\beta|^{2}=1$. Now we have the following proposition. It is isomorphic to PSL(2, R). And with the metric defined by  $\left|\alpha-\alpha_{1}\right|^{2}+\left|\beta-\beta_{1}\right|^{2}$  it forms a topological group.
Let G be a discrete group in Aut(D) and Z be the stabilizer of 0 in G. Hence Z is a finite cycle group with $\beta=0$. But how to prove that:
there is some
$k<1$ such that if $\gamma \in G$ is $\gamma(z)=(\alpha z+\beta) /(\bar{\beta} z+\bar{\alpha})$, where $|\alpha|^{2}-|\beta|^{2}=1$, and if $|\beta| \leq k|\alpha|$, then $\gamma$ is in $Z$.
How to prove this property? Donaldson says it's easy but I'm really stuck here for a long time. I tried to prove it by contradiction. I figured it out that if no such k exists then there is some element in G getting closer and closer to the circle in Aut(D). But I canot prove that it conflicts with the discreetness of G. Thanks!
Answer: With some hints from Free discrete action vs discrete subgroup. Maybe I found a proof, though lossing many details, and it's not totally rigorous:
theorem
Let $\Gamma$ be a discrete subgroup of holomorphic automorphisms group Aut($D$), which is the set of all Mobius maps of the form
$$
 z \mapsto \frac{\alpha z+\beta}{\bar{\beta} z+\bar{\alpha}}
 $$
where $|\alpha|^{2}-|\beta|^{2}=1$, and modulo $\{-1, 1\}$. Let $Z$ be the stabilizer of $0$ in $\Gamma$. Then:

$Z$ is a finite cyclic group.
There is some  $k<1$ such that if $\gamma \in \Gamma$ is $\gamma(z)=(\alpha z+\beta) /(\bar{\beta} z+\bar{\alpha})$, where $|\alpha|^{2}-|\beta|^{2}=1$, and if $|\beta| \leq k|\alpha|$, then $\gamma$ is in $Z$.

Proof
Elements in the stabilizer of $0$ in $\Gamma$ has the form $z \mapsto e^{i\theta}z$. Since $\Gamma$ is discrete, and the intersection of a discrete subspace in another subspace is still discrete, and the intersection of two subgroup is still a subgroup, $Z$ is a discrete subgroup of the stabilizer of $0$ in Aut($0$), which is a circle. Hence $Z$ is a finite cyclic group. Otherwise it would be dence (Subgroup of the unit circle under complex multiplication). Hence property 1 holds.
Suppose property 2 does not hold. Then for any $n \in \Bbb{N}^{+}$, there is $\gamma_{n} = (\alpha_n z+\beta_n) /(\bar{\beta}_n z+\bar{\alpha}_n) \in \Gamma $,  where $|\alpha_n|^{2}-|\beta_n|^{2}=1$, and $|\beta_n| \leq |\alpha_n|/n$, such that $\gamma_n$ is not in $Z$. Then $|\alpha_n| \rightarrow 1, |\beta_n| \rightarrow 0 $. Hence there is some subsequence $\{n_m\}$, such that $\{\alpha_{n_m}\}$ converges to some complex number $e^{i\theta}$. Without loss of generality, suppose $\{(\alpha_n, \beta_n)\} \rightarrow (e^{i\theta}, 0)$.
Since $(1, 0)$ is in $Z \subset \Gamma$, by the discreteness of $\Gamma$, there is some neighborhood $N$ of it such that $N \cap \Gamma = \varnothing$. If $\theta$ defined above satisfying that $\theta/\pi$ is rational, there is some positive $M$ such that $e^{iM\theta} = 1$ and hence $(e^{iM\theta}, 0) = (1, 0) \in N$. Otherwise since every subgroup of the circle is either finite cyclic or dense, there is some positive integer $M$, such that we still have $(e^{iM\theta}, 0) \in N$.
Define $F: \text{Aut}(D) \rightarrow \text{Aut}(D) $ by $\gamma \mapsto \gamma^{M}$ (applying itself $M$ times). Then $F$ is a continuous function from $\text{Aut}(D)$ to itself. Hence by $\{(\alpha_n, \beta_n)\} \rightarrow (e^{i\theta}, 0)$, apply it to the image of $F$, the limit $F(\alpha_n, \beta_n) \rightarrow (e^{iM\theta}, 0)$ holds. Since $F(\alpha_n, \beta_n)$ is self composition of element in $\Gamma$, it's in $\Gamma $ too. And since $(e^{iM\theta}, 0) \in N$, there has to be some $F(\alpha_n, \beta_n) \in \Gamma$. This conflicts with the discreteness of $\Gamma$.
Hence property 2 holds.


Excel Macro to concatenate cells and shift over

Question: I want to be able to select any number of cells (all on the same row), and run a macro that will concatenate all the highlighted cells, then shift all of the remaining cells over.
My description might not be clear - hopefully this makes more sense:
In the example below, I have data in columns 1 to 8.
I would highlight the cells in colums 1 to 3, run the macro, and have the values in the highlighted cells merged to the left (with spaces between), and have the remaining cells shifted over.
BEFORE
Column1 Column2 Column3 Column4 Column5 Column6 Column7 Column8
A       B       C       D       E       F       G       H

AFTER
Column1 Column2 Column3 Column4 Column5 Column6 Column7 Column8
A B C   D       E       F       G       H

Is this possible to do with a macro (that I'd execute via keyboard shortcut)? I've got a general understanding of excel and vba macros, but I'm sadly not good enough to know if this is practical or possible.
I've found some macros that concatenate cells data, but not based on highlighted cells.  Any advice would be appreciated. Thank you.
Answer: this would definitely be possible. the execution depends on how you want to "Hgihlight" cells. if you are selecting them, you'd just use .selection in your code.
this is a function I use to combine columns:
Function combineColumns(ByVal Columns As Variant, ByVal EmptyCol As Long) As String

    Dim tempColumn As Long
    Dim str As String
    Dim base As Long

    base = LBound(Columns) 'Columns could be 0 or 1 based array

    str = "="
    'compiles string formula for combining the columns
    For i = base To UBound(Columns)
        'tempColumn = Range(Columns(i) & "1").column
        If i > base Then 'if i > base it means that the loop is not on the first run, so the "&" is added for concatenation
            str = str & "&"" ""&RC[-" & (EmptyCol - Columns(i)) & "]"
        Else
            str = str & "RC[-" & (EmptyCol - Columns(i)) & "]"
        End If

    Next

    combineColumns = str

End Function

That function takes an array of column numbers, and returns a string that can be inserted into a cell to combine the passed columns into the passed blank column. Should be easily adaptable to fit your solution. (loop through columns in .selection and add all column numbers to an array, then pass to my function, and use the returned string. )
if you are highlighting with color, you'd use a loop to go over every cell in the row and test the color. so like
For Each cell In activeCell.entireRow.Cells
    if cell.interior.color = RGB() then 'insert rgb for highlighting color here
        'add to array
    end if
next

and then you'd pass the resulting array. and then after you combine the cells, use .delete xlShiftToLeft which will delete the cells and shift the remaining on the row to the left to fill in the blanks. (be sure to not have the cell with the combined data selected at that point.
edit
NOTE: the string returned by the function must be inserted into a cell ( Cells(rownum, colnum).formulaR1C1 = ) because if you try to use it outside of code you'll get an error
Answer: Give this a try:
Sub bigmac()
    Dim r As Range, rDel As Range
    Set r = Selection
    Dim N As Long
    N = r.Count
    Set rn = r(N)
    st = ""
    For i = 1 To N
        st = st & r(i).Value
    Next i
    r(1) = st
    Set rDel = Range(r(2), r(N))
    rDel.Delete shift:=xlToLeft
End Sub

Comment: Keep your edit, but replace **r(1)=st** with **r(1)=Trim(st)**.


How to join datasets with same columns and select one?

Question: I have two Spark dataframes which I am joining and selecting afterwards. I want to select a specific column of one of the Dataframes. But the same column name exists in the other one. Therefore I am getting an Exception for ambiguous column.
I have tried this:
d1.as("d1").join(d2.as("d2"), $"d1.id" === $"d2.id", "left").select($"d1.columnName")

and this:
d1.join(d2, d1("id") === d2("id"), "left").select($"d1.columnName")

but it does not work.
Comment: When you said _"but it does not work."_, what's the error/exception?
Answer:
I have two dataframes

val d1 = spark.range(3).withColumn("columnName", lit("d1"))
scala> d1.printSchema
root
 |-- id: long (nullable = false)
 |-- columnName: string (nullable = false)

val d2 = spark.range(3).withColumn("columnName", lit("d2"))
scala> d2.printSchema
root
 |-- id: long (nullable = false)
 |-- columnName: string (nullable = false)

which I am joining and selecting afterwards.
  I want to select a specific column of one of the Dataframes. But the same column name exists in the other one.

val q1 = d1.as("d1")
  .join(d2.as("d2"), Seq("id"), "left")
  .select("d1.columnName")
scala> q1.show
+----------+
|columnName|
+----------+
|        d1|
|        d1|
|        d1|
+----------+

As you can see it just works.

So, why did it not work for you? Let's analyze each.
// you started very well
d1.as("d1")
  // but here you used $ to reference a column to join on
  // with column references by their aliases
  // that won't work
  .join(d2.as("d2"), $"d1.id" === $"d2.id", "left")
  // same here
  // $ + aliased columns won't work
  .select($"d1.columnName")

PROTIP: Use d1("columnName") to reference a specific column in a dataframe.
The other query was very close to be fine, but...
d1.join(d2, d1("id") === d2("id"), "left") // <-- so far so good!
  .select($"d1.columnName") // <-- that's the issue, i.e. $ + aliased column

Answer: which spark version you're using ? can you put a sample of your dataframes ?
try this:
d2prim = d2.withColumnRenamed("columnName", d2_columnName)
d1.join(d2prim , Seq("id"), "left_outer").select("columnName")

Answer: This happens because when spark combines the columns from the two DataFrames it doesn't do any automatic renaming for you.  You just need to rename one of the columns before joining. Spark provides a method for this.  After the join you can drop the renamed column.
val df2join = df2.withColumnRenamed("id", "join_id")
val joined = df1.join(df2, $"id" === $"join_id", "left").drop("join_id")

Comment: Yeah, typo.  I fixed the missing equals.  Also, the accepted answer was edited to match this one after it was posted.


Problem 2.16 - Character theory by Isaacs

Question: Let $H\leq G$ and let $\chi$ be a (possibly reducible) character of $G$. Suppose $\chi$ vanishes on $G-H$. Assume that either $H=\{e\}$  or $G$ is abelian. Show that $[G:H]$ divides $\chi(1)$.
I have proved it partially, in the case when $H$ is the trivial subgroup. But I haven't been able to do the abelian case.
Thanks in advance!
Answer:
Lemma Let $H \le G$ and let $\phi$ be a (not necessarily irreducible) character of $G$ vanishing on $G-H$. Assume that either $H=1$ or $G$ is abelian. Then $|G:H| | \phi(1)$.

Proof Assume first that $H=1$. Now $|G|[\phi,1_G]=\sum_{g \in G}\phi(g)=\phi(1)$. Since $\phi$ is a character, $\phi(1) \neq 0$ and $[\phi,1_G]$ is a positive integer, it follows that $|G|$ divides $\phi(1)$. In fact, in this case $\phi=b\rho$, where $b=\frac{\phi(1)}{|G|}$ and $\rho$ is the regular character of $G$, see Exercise (3.8) of the same book.
Now assume that $G$ is abelian and $\phi\equiv0$ outside $H$. We can write $\phi=\sum_{\mu \in Irr(G)} a_{\mu}\mu$, with $a_{\mu}$ non-negative integers and not all equal to $0$. Note that the $\mu$ are of course all linear since $G$ is abelian. Hence their restrictions $\mu_H$ are also linear and irreducible. This implies that $\phi_H=\sum_{\mu \in Irr(G)} a_{\mu}\mu_H$ is the decomposition of $\phi_H$ as a sum of irreducible characters of $H$. Note that different $\mu's$ can be equal when restricted to $H$. So in this last sum some of the irreducible constituents may coincide. Put $\phi_H=\sum_{\lambda \in Irr(H)} b_{\lambda}\lambda$ with $b_{\lambda}$ non-negative integers. Fix such $\lambda$, then $\lambda=\mu_H$ for some irreducible constituent $\mu$ of $\phi$. Since $\phi$ vanishes off $H$, $$b_{\lambda}|H|=\sum_{h \in H}\phi(h)\overline{\lambda(h)}=\sum_{g \in G}\phi(g)\overline{\mu(g)}=|G|a_{\mu}$$So we see that each of the $b_{\lambda}=|G:H|a_{\mu}$ is hence divisible by $|G:H|$. Since $\phi(1)=\sum_{\lambda \in Irr(H)} b_{\lambda}\lambda(1)=\sum_{\lambda \in Irr(H)} b_{\lambda}$, we now see that $|G:H|$ divides $\phi(1)$, as wanted.$\square$
Note 1 A natural common generalization of the situation $H=1$ and $G$ is abelian is $H \subseteq Z(G)$. However, under these hypotheses the above result is not true. By the way, in this situation, owing to Lemmata (2.27)(c) and (2.29) of Isaacs' book, $\phi(1)^2=|G:H|[\phi,\phi]$, hence $|G:H|$ divides $\phi(1)^2$.
Here is a counterexample that shows that $|G:H|$ not necessarily divides $\phi(1)$. The character table of the quaternion group $Q$ of order $8$ looks as follows. Here $Q=\{\pm 1,\pm i, \pm j,\pm k \}$, where $i^2=j^2=k^2=-1, ij=k,jk=i,ki=j$. $Q$ has five conjugacy classes.
$$ \begin{array}{|c|c|c|c|}
\hline
&1& -1 & \{\pm i \} & \{\pm j \} & \{\pm k \} \\ \hline
1_Q & 1 & 1  & 1 & 1 & 1 \\ \hline
\chi_2 & 1 & 1 & 1 & -1 & -1 \\ \hline
\chi_3 & 1 & 1 & -1 & -1 & 1 \\ \hline
\chi_4 & 1 & 1 & -1 & 1 & -1 \\ \hline
\chi_5 & 2 & -2 & 0 & 0 & 0 \\ \hline
\end{array}
$$
So, $\chi_5$ vanishes off the center $Z(Q)=\{\pm 1\}$. But $|Q:Z(Q)|=4$ does not divide $\chi_5(1)=2$.
Note 2 The above lemma is being used in the proof of Theorem (3.13) of Isaacs' book.
Answer: Assume $G$ is abelian. Let $\psi_1,\psi_2,\ldots,\psi_m, m=[G:H],$ be the (1-dimensional) irreducible characters of $G/H$ viewed as characters of $G$ by precomposing with the projection $G\to G/H$.
Observe that as $\chi(x)=0$ whenever $x\notin H$, we have $\chi(x)\psi_j(x)=\chi(x)$ for all $x\in G$ and all $j=1,\ldots,m$. We take advantage of this as follows.
If $\chi_i$ is any of the irreducible characters (also 1-dimensional) of $G$, then
$$
\begin{aligned}
\langle \chi,\chi_i\rangle&=\frac1{|G|}\sum_{x\in G} \chi(x)\overline{\chi_i(x)}\\
&=\frac1{|G|}\sum_{x\in G} \bigg(\chi(x)\overline{\psi_j(x)}\bigg)\overline{\chi_i(x)}\\
&=\frac1{|G|}\sum_{x\in G} \chi(x)\bigg(\overline{\psi_j(x)}\overline{\chi_i(x)}\bigg)\\
&=\langle\chi,\chi_i\overline{\psi_j}\rangle.
\end{aligned}
$$
All the products $\chi_i\psi_j$ are themselves irreducible. Call the irreducible characters $\chi_i$ and $\chi_{i'}$ $H$-similar, if
$\chi_{i'}=\chi_{i}\psi_j$ for some $j$. This is an equivalence relation of the set $\hat G$ of irreducible characters of $G$ with each equivalence class containing $m$ characters. Let $D$ be a set of representatives of $H$-similarity classes. The above calculation shows that the inner product
$\langle \chi,\chi_i\rangle$ only depends on the $H$-similarity class of $\chi_i$.
This lets us conclude as follows
$$
\begin{aligned}
\chi(1)&=\sum_{\chi_i\in\hat{G}}\langle \chi,\chi_i\rangle\,\chi_i(1)\\
&=\sum_{\eta\in D} m\langle\chi,\eta\rangle\,\eta(1).
\end{aligned}
$$
This number is clearly a multiple of $m$.
Comment: Undoubtedly suitable Lemmas are in place, and this is overkill in details :-(. Alas, my copy of Isaacs is in my office, so I cannot check. Don't use the concept of $H$-similarity anywhere. I just cooked it up to do this :-)


Generalized linear model in R; what family to use?

Question: I'm trying to find out which family I need to use for a generalized linear model in R where the  outcome is continuous (Biotic indices like Shannon and water framework directive water quality measures) and the predictors are counts (families and feeding habits).
I found info for the other way around, but not for this scenario. I've been going through literature but cannot find the answer.
If it was the other way around, according to this https://www.statmethods.net/advstats/glm.html I should use Poisson.
Also tried to scan this document, but no answer: https://www.sagepub.com/sites/default/files/upm-binaries/21121_Chapter_15.pdf
Histogram of DV:
Comment: Have you tried just a normal distribution? There's no indication here that you need anything different. Your dependent variable is continuous and unbounded, so there's no need for Poisson, logistic, etc.
Comment: Also, the DV does not have to be normal to use the Gaussian family. It assumes the residuals are normal. The DV does have to be continuous or close to it.
Comment: @mkt Yes, I have. Only one of the tests the residuals did not come back as normally distributed. That's the reason for trying to explore further.
Comment: Linear models are robust to small deviations from some of the assumptions. If you're concerned about it, you could ask a new question with the figure that you're concerned about.
Comment: You say your outcome is continuous, that alone determines the family. But how continuous is your DV? Is it bounded?
Comment: @user2974951 Shannon is "Rarely greater than 4", some indices are actually scores from 0-1 with unlimited decimal places, and some are natural numbers that are theoretically without bounds but in my data don't exceed 100.
Comment: Can you post a histogram of your DV in your question?
Comment: @user2974951 Edited question. I guess this is what you mean with DV?
Comment: Yes, dependent variable DV = outcome, the plot that you posted is far from normal, so you will have to think of something else. It is also not Poisson distributed. A fractional logistic regression maybe.
Comment: @user2974951 Ah, ok. Yes, I know it probably wasn't Poisson, the predictors all are Poisson distributed though as they are count data.

I'll look into your suggestion. Thanks!
Answer: There's no indication here that you need anything other than a normal distribution. It's possible, but none of the information you present supports that. Your dependent variable is continuous and unbounded, so there's no need for Poisson, logistic, etc.


Convergence of infinite series of converge matrices.

Question: Let $A$ and $C$ two matrices where $\|A\|<1.$ I know that $ \lim_{k \rightarrow \infty} A^k = 0.$ I want to show that $B = \sum_{r=0}^ \infty (A^T)^rCA^r$ converges.
How to do this?
Thank you.
Comment: related: [Positive definite of infinite sum of matrices](http://math.stackexchange.com/questions/207174/positive-definite-of-infinite-sum-of-matrices/207178)
Answer: Hint: The matrix norm is subadditive and submultiplicative hence $\|B\|\leqslant\sum\limits_{r\geqslant0}\|(A^T)^rCA^r\|$ and, for each $r\geqslant0$, $\|(A^T)^rCA^r\|\leqslant\|C\|\cdot\|A^T\|^r\cdot\|A\|^r$. Can you take it from here?
Comment: This is my definition for convergence. If $ \lbrace A^t \rbrace$ is a sequence of matrices and if $G$ is a matrix which has the same dimension as $A.$ We say that $ \lbrace A^t \rbrace$ convergs to $G$ when $ \lim_{ t \rightarrow \infty} A^t = G.$
Comment: @did: It is not obvious to me. It seems we can only say $\|(A^T)^rCA^r\|$ approaches to zero when $r\rightarrow +\infty$. But it doesn't obviously imply the summation has a finite value.
Comment: @Shiyu: You know that $\|C\|$ is finite and $\|A^T\|\cdot\|A\|\lt1$ but you are not sure that the series written in my post converges? This is odd...
Comment: @Sulaiman: Indeed. And my hint shows how to bound the norm of the difference between any partial sum and the limit.
Comment: @did: hi there. The part that confuses me is this: $(A^T)^r C A^r$ converges to zero when $r$ approaches infinity, but the summation or integral may not. Take a probably inappropriate example: $1/x$ approaches to zero when $x\rightarrow \infty$, but $\int_{1}^{\infty}1/x \mathrm{d}x$ is not finite.
Comment: @Shiyu: I already answered to that, please refer to my previous comment. The appropriate analogy is that the series $\sum\limits_nx_n$ might diverge even though $x_n\to0$ (your point). What saves the day here is that one knows that $|x_n|\leqslant ca^n$ for some positive $a\lt1$, hence the series $\sum\limits_nx_n$ does converge.
Comment: @did: thanks for the explanation, I understand it now.
Comment: @Shiyu Wonderful.


How to deal with drastically different sample sizes (3 treatments)

Question: I have 3 treatments with different sample sizes. They are different enzymes for production of Butanol in industrial scale.
The first one has 60 replicates, the second has 30 replicates and the thrid with only 6 replicates. I tried running ANOVA followed by Tukey's Test, but I think it is not fair since the standard deviation is bigger for the treatment with small sample size.
I was wondering if there is a way in R to resample/bootstrap/reduce the first two treatments to a sample size of 6 and then, run ANOVA followed by Tukey's Test.
Anyone with advice or other suggestion?
Comment: Why is that unfair? This seems consistent with the small sample size, and is a feature, rather than a drawback, of the this procedure.
Comment: Because with a big deviation there isn't statistical difference between this treatment and the others. We didn't expect it since this is the treatment with best results in lab scales, but we have never conducted an experiment with bigger sample size before and it was not possible to increase the last group with more than 6 replicates. Also, we've heard that the small sample size interfere in ANOVA because of normality, but I do not know if it's right (I'm biologist trying to apply statistics when it is possible).
Comment: Can you explain more about the "we've heard" thing? It's pretty vague.  People hear lots of weird things with no clear provenance, from unnamed sources, and I'm somewhat mystified by what the actual claim could have been. What exactly was it that was said?
Comment: During college I got the idea that for statistics the bigger sample size, the better. Also, that is necessary groups with same variance and normal distribution for ANOVA. But then comes the real life it is not pratical. So, looking for solutions in forums, I found answers as "the problem does not lie in the difference between the sizes of the datasets but rather in the fact that one data set is very small" or "if you have very unequal sample sizes, you may wish to use bootstrapping instead since it doesn't make any assumptions at all about the distribution of the sample statistic".
Answer: In a traditional one-factor ANOVA with three treatment groups, one assumes that the three populations have equal variance. If sample sizes are hugely different, then the common variance is mainly estimated from the larger sample(s).
If you doubt that all three treatment groups have different variances, then that assumption seems inappropriate. However, there is a Welch version of the one-factor ANOVA that does not assume equal variances. (The main idea is somewhat similar to doing a Welch two-sample t test instead of a pooled two-sample t test.) See R documentation for 'oneway.test'.
Here is an example:
set.seed(626)  # for reproducibility of simulated data
x1 = rnorm(60, 100, 10);  x2 = rnorm(30, 100, 12);  x3 = rnorm(6, 120, 10)
x = c(x1, x2, x3)
boxplot(list(x1, x2, x3), varwidth=T, col="skyblue2")

Boxes above are of different sizes to reflect the different sample sizes among groups.
Here is output from the Welch ANOVA in R:
g = c(rep(1,60), rep(2,30), rep(3,6))
oneway.test(x ~ g)

        One-way analysis of means (not assuming equal variances)

data:  x and g
F = 28.035, num df = 2.000, denom df = 15.694,
p-value = 6.6e-06

Because of the very small P-value, it is clear that there are significant differences among the group population mean. [A traditional one-factor ANOVA would have had 93 denominator df; the lower denominator df seen here is characteristic of the Welch ANOVA, especially if population variances differ.]
There are various ways to do ad hoc pairwise tests among the three groups.
In this case Group 3 is significantly different from the other two.
With Bonferroni protection against false discovery of differences, we
should declare differences between pairs of treatments, if P-values are below $0.05/3 \approx 0.017.$
t.test(x1, x2)$p.val;  t.test(x1, x3)$p.val;  t.test(x2, x3)$p.val
[1] 0.1394103      # no sig dif btw Gps 1 & 2
[1] 8.800413e-05   # Gps 1 & 3 differ
[1] 0.0001181582   # Gps 2 & 3 differ

This page discusses the oneway.test in context.
Answer: You've done what I think most people would suggest doing.  That you have a small sample size is not really something you need to combat; you can either adequately power your experiments or you can deal with the consequences (unless you are prepared to take a Bayesian approach).  Anything else is, in my opinion, fishing for a rejection of the null on shakey ground.
Comment: The issue isn't just that the sample sizes differ. One is wise to question the wisdom of 'what most people would do' when one of the smaller samples has a noticeably larger variance than the others.


Disable backtrace

Question: I'm training on heap overflow exploit on my backtrack 5 laptop. However, backtrack seems to have a protection against these attacks. Here is what I get when i try to corrupt meta data of malloc's allocated chunks.
Starting program: /root/exploit/basicheap `python -c 'print "A"*1024+"\xff\xff\xff\xff"+"\x01\x02\x03\x04"'`
buf1=0x804b008 buf2=0x804b410
*** glibc detected *** /root/exploit/basicheap: double free or corruption (out): 0x0804b410 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(+0x6b591)[0xb7edf591]
/lib/tls/i686/cmov/libc.so.6(+0x6cde8)[0xb7ee0de8]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xb7ee3ecd]
/root/exploit/basicheap[0x80484ee]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xb7e8abd6]
/root/exploit/basicheap[0x80483f1]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:01 13377588   /root/exploit/basicheap
08049000-0804a000 r--p 00000000 08:01 13377588   /root/exploit/basicheap
0804a000-0804b000 rw-p 00001000 08:01 13377588   /root/exploit/basicheap
0804b000-0806c000 rw-p 00000000 00:00 0          [heap]
(ETC...)

Program received signal SIGABRT, Aborted.
0xb7fe2430 in __kernel_vsyscall ()

Is there a way to disable this protection? Is it handled by the kernel or set by gcc during compilation (i was hoping i could disable it with an option like -fno-stack-protector to remove stack overflow protection in gcc)?
Answer: The message is coming from glibc's implementation of free, which detects the heap corruption. It isn't a compile-time option in your program, and it isn't a kernel check.
Try:
MALLOC_CHECK_=0 /root/exploit/basicheap ...

The malloc(3) man page for glibc says that with that environment variable set to 0, "any detected heap corruption is silently ignored", so it may just ignore your heap corruption and continue running, but it might successfully crash instead.
Also see the M_CHECK_ACTION option of mallopt(3), which provides more detail on this checking code.

Disable backtrace


Comparing two samples with values form different distributions

Question: I came across the problem of comparing two samples children's.
For each child, I have age and BMI value, I also know if he sports or not.
I want to decide, if the children who sport have better BMI values that those who dont.
The problem is, that the children are of different ages and the BMI values are interpreted differently in different age. That means, I cannot really compare the BMI of 10-year old and 17-years old. However, the childrens are of different ages.
Is there an option how to compare the data? I could obviously pick only one age group, but this would decrease size of my data dramatically.
Thanks.
Comment: You might try using age as a covariant
Comment: @HEITZ What do you please mean by that exactly?
Comment: Suppose you were analyzing the difference in IQ between two groups of people who received various 'brain training' treatments (as a silly example). However, you also know that IQ covaries with age, so you'd like to remove the influence of age to obtain a more pure measure of the treatments.  You can add age as a covariate, thereby minimizing its influence.
Answer: You could do quantile normalization to correct for differing BMI ranges across age groups. Instead of using raw BMI, set the "healthy" value for each age according to whatever you think is appropriate, and then convert BMI to a percentage of this value. Now a value of 100% is healthy in all groups, but represents a different BMI value depending on age.
Alternatively, if your data is big enough, you can estimate the distribution of BMIs from the data itself. For each age (or age range), find the sample distribution, and then set each BMI value to the corresponding quantile. So, your minimum value of BMI in an age range becomes 0, the maximum becomes 100, and the median is 50.
Comment: Thank you for answering. I was thinking about something similar. However, how can I compare the data then? Is it OK to use for example t-test?


recognize an onclose event with OleVariant?

Question: I´m using a OleAutomation with Excel := CreateOleObject('Excel.Application');
to use the functions Excel.Replace and Excel.SaveAs. These functions are essential in my problem and I cannot leave them out. On the other hand I have to use an OleVariant type, which has no OnCloseEvent. Now my problem begins:

At first a small overview:
**procedure OpenExcel begins**

Excel := CreateOleObject('Excel.Application');
//Excel opens a template and replaces placeholders

**procedure OpenExcel end**;

Now Excel is open with all placeholders replaced. After this procedure the client can alter his sheet, correct mistakes, .. . Ongoing he wants to close Excel or save the Workbook.

And here starts my problem: I want to catch the moment, when the client closes Excel. If his document is saved, all data (some strings like path or color and integers like id´s placed in an object) will comitted to another programm named ELO (document archive) before the OleObject will be destroyed. But OleObjects can´t recognize a close or whatever.

Is there a workaround to solve this problem? Perhaps linking an object to the OleObject or the process itself to determine when Excel is closed by the client?
I looked up if there is a way provided by the \Ocx\Servers\excel200.pas but I didn't found anything. My co-worker advised I should look into the office folder and search for the excel .tlb-file, but it doesn't exsist.

IF THE PROBLEM ABOVE CANNOT BE SOLVED

If this isn´t possible do anyone know how I can use Excel.Replace and Excel.SaveAs with an object, which has a OnClose Event?
My current code for replacement is the following:
//for all sheets in the workbook
for iSheet := 1 to Excel.Worksheets.Count do
begin

  //activate the sheet
  Excel.Worksheets[iSheet].Activate;

  // this will be..
  sWhat := %First String%;
  //..replaced by..
  sReplacement := %Second String%;

  // warnings off (override message or if excel didn't find a sWhat)
  Excel.Application.DisplayAlerts := False;

  Excel.Cells.Replace(
    What          := sWhat,
    Replacement   := sReplacement,
    LookAt        := xlWhole,
    SearchOrder   := xlByRows,
    MatchCase     := False,
    SearchFormat  := False,
    ReplaceFormat := False
  );

  //warnings on
  Excel.Application.DisplayAlerts := True;
end;

The SaveAs method is similiar. It just sends a command which excel itself can handle like the Excel.Cells.Replace.
I hope the description of my problem is clear enough, my english isn't as good as I want it to be..
Thanks in advance!
Comment: You failed to mention what delphi version you are using and which office version...
Comment: Implement 'IAdviseSink' on a class and ['Advise'](http://msdn.microsoft.com/en-us/library/ms686573) your workbook. Voting to close as a duplicate of http://stackoverflow.com/questions/2880090/how-to-catch-a-moment-when-the-external-editor-of-tolecontainer-has-been-closed just instead of oleobjectinterface of ole container, retreive the ioleobject for your workbook.
Comment: Oh pardon. I use Delphi5 and Office2007 but it should also work for Office2003, that´s also a reason for the OleVariant. ( Tags edited :) )
Comment: http://www.delphigroups.info/2/3/991910.html even the objects TExcelApplication, TExcelWorkbook etc. from Microsoft in excel2000.pas have **no eventhandler** for OnClose.
Comment: That's over my head. I'm just programming with delphi since 3 month and I never touched interfaces. Nevertheless I will try to understand your given example and ask my instructor tomorrow, if anyone here in my company worked with interfaces :)
Answer: I just wanted to tell you that I didn´t solve this problem with late-binding but instead with early-binding.
For everyone with the same problem here is a possible solution:
uses excel97, excel2000 //order is important
..
var
  ExcelApp : TExcelApplication;
  ExcelWb: _WorkBook;
  ExcelSt: _WorkSheet;
  iLCID: Integer;

Open Excel, load a file, activate a sheet and connect to an OnWorkbookBeforeClose method
  // open excel
  iLCID := GetUserDefaultLCID;

  // create and connect excelapplication
  ExcelApp := TExcelApplication.Create(self);
  ExcelApp.Connect;

  // load file
  ExcelWb := ExcelApp.Workbooks.Open(
    ExtractFilePath(ParamStr(0))+'test.xlsx',
    emptyParam, emptyParam, emptyParam, emptyParam,
    emptyParam, emptyParam, emptyParam, emptyParam,
    emptyParam, emptyParam, emptyParam, emptyParam,
    iLCID
  );

  // Visible - off
  ExcelApp.Application.Visible[0] := false;

  // Starts excel on the first sheet
  ExcelSt := ExcelWb.Sheets[1] as _WorkSheet;
  ExcelSt.Activate(iLCID);

  // Visible - on
  ExcelApp.Application.Visible[0] := true;

  // Connect to the closemethod
  ExcelApp.OnWorkbookBeforeClose := WorkbookBeforeClose;

Replace something
var
  sWhat, sReplacement : String;
  iSheets : Integer;
begin

  // basic data
  sWhat := **STRING 1**;
  sReplacement := **STRING 2**;

  // Warnings off (Overridewarning)
  ExcelApp.Application.DisplayAlerts[iLCID] := False;

  // Replace for all sheets in a workbook
  for iSheets := 1 to ExcelApp.Application.Sheets.Get_Count do
  begin
    ExcelSt := ExcelWb.Sheets[iSheets] as _WorkSheet;
    ExcelSt.Activate(iLCID);

    ExcelApp.Application.ActiveWorkbook.Application.Cells.Replace(
      {What} sWhat,
      {Replacement} sReplacement,
      {LookAt} xlWhole,
      {SearchOrder} xlByRows,
      {MatchCase} False,
      {MatchByte} False
      );

   end;

  // warnings on
  ExcelApp.Application.DisplayAlerts[iLCID] := True;

Save your work
var
  oFileName, oFileFormat : OleVariant;
begin

  {
  Value = Constant in excel (Description)
  ------------------------------------------------------------------------------
  50   = xlExcel12 (Excel Binary Workbook 2007+ with or without macros, xlsb)
  51   = xlOpenXMLWorkbook (without macros Excel 2007+, xlsx)
  52   = xlOpenXMLWorkbookMacroEnabled (with or without macros Excel 2007+, xlsm)
  56   = xlExcel8 (97-2003 Format in Excel 2007-2010, xls)
         !!! in 2003 = xlNormal !!!
  ------------------------------------------------------------------------------
  }

  oFileName   := 'Filename';
  oFileFormat := 50;
  iLCID       := GetUserDefaultLCID;

  ExcelApp.Application.ActiveWorkbook.SaveAs(
    {Filename} oFileName,
    {FileFormat} oFileFormat,
    {Password} emptyParam,
    {WriteResPassword} emptyParam,
    {ReadOnlyRecommended} false,
    {CreateBackup} false,
    {AccessMode} 0,
    {ConflictResolution} false,
    {AddToMru} false,
    {TextCodepage} false,
    {TextVisualLayout} false,
    {LCID} iLCID
    );

BeforeClose method
 procedure WorkbookBeforeClose(Sender: TObject;
   var Wb, Cancel: OleVariant);
 var
   oTrue :OleVariant;
 begin

   ExcelApp.Application.Visible[0] := false;

   //Here comes your stuff when the user wants to quit excel

   oTrue := true;
   Cancel := oTrue;

   ExcelApp.Quit;
 end;

I hope this will help some people, who encounter a similar problem :)