O que são AMD e CommonJS?

Question: Recentemente tenho ouvido falar bastante sobre Asynchronous Module Definition (AMD) e CommonJS. Parecem dois termos que estão na moda.
Li algumas coisas sobre, mas ainda estou confuso.
AMD e CommonJS são bibliotecas ou especificações?
Quem pode nos explicar de forma simples e prática o que são esses dois termos?
Comment: Acho que existem já algumas respostas sobre isto aqui. Seria interessante incluir Modulos Harmony talvez.
Comment: Pergunta relacionada (ou pelo menos minha resposta lá é relacionada!): http://pt.stackoverflow.com/questions/17343/an%c3%a1lise-e-projeto-em-javascript
Answer: AMD
É uma API javascript que define Módulos de forma que suas dependências possam ser carregadas de forma assíncrona. É muito útil em melhorar a performance de sites evitando o carregamento síncrono de scripts antes do conteúdo do restante do site.
Além de carregar vários arquivos JavaScript em runtime, também pode ser utilizado no desenvolvimento para manter os arquivos javascript encapsulados para vários javascripts diferentes funcionando como um import.
O RequireJS é uma implementação de AMD.
Utilizando RequireJs(AMD) com KnockOut por exemplo:
require(['knockout-x.y.z', 'appViewModel'], function(ko, appViewModel) {
    ko.applyBindings(new appViewModel());
});

indica que deve carregar or arquivos 'knockout-x.y.z' e 'appViewModel' antes de executar o código dentro da funcao
enquanto o arquivo appViewModel deveria ter
// Main viewmodel class
define(['knockout-x.y.z'], function(ko) {
    return function appViewModel() {
        this.firstName = ko.observable('Bert');
        this.firstNameCaps = ko.computed(function() {
            return this.firstName().toUpperCase();
        }, this);
    };
});

pois só funcionaria depois que a biblioteca knockout fosse carregada.
CommonJs
CommonJs é uma API com o objetivo de agrupar as necessidades de diversas aplicações javascript em uma única API, que funcione em diversos ambientes e interpretadores. Criando o conceito de se módulos que façam essas funções. E estes módulos podem ser carregados assincronamente com ferramentas AMD.
Dentre as funcionalidades oferecidas temos:

Definições Assíncronas
Promessas
Testes unitários

Este link trás um exemplo de como utilizar o CommonJs em conjunto com AMD utilizando curl.js e requirejs
Comment: A sua foi bem direta e clara, +1
Answer: Existe uma pergunta semelhante no SO, coloquei alguns trechos da reposta traduzida, acho bem difícil mas se por um acaso o link ficar offline pelo menos temos como nos orientar por essa resposta, espero que ajude.
RequireJS implementa a API AMD (fonte)
CommonJS é uma forma de definir os módulos com a ajuda de um exportações objeto, que define o conteúdo do módulo.
    // someModule.js
exports.doSomething = function() { return "foo"; };

//otherModule.js
var someModule = require('someModule'); // in the vein of node
exports.doSomethingElse = function() { return someModule.doSomething() + "bar"; }

CommonJS especifica que você precisa ter uma função para buscar as dependências, as exportações de variáveis para exportar conteúdo do módulo e alguns identificador do módulo que é usada para exigir que o dependências. CommonJS tem várias implementações, por exemplo Node.js
RequireJS implementa AMD, que é projetado para se adequar ao navegador, Aparentemente AMD começou como uma offspin de formato CommonJs Transportes e evoluiu em sua própria API de definição de módulo. Daí as semelhanças entre os dois. A novidade no AMD é a função de definir-que permite que o módulo para declarar suas dependências antes de ser carregada. Por exemplo, a definição poderia ser:
define('module/id/string', ['module', 'dependency', 'array'],
function(module, factory function) {
  return ModuleContents;
});

Então CommonJS e AMD são Javascript módulos de APIs que têm implementações diferentes, mas ambos vêm das mesmas origens. AMD é mais adequado para o browser, porque suporta o carregamento assíncrono de dependências de módulo. RequireJS é uma implementação da AMD, enquanto ao mesmo tempo tentando manter o espírito de CommonJS (principalmente nos identificadores de módulo). Para confundir ainda mais, RequireJS, sendo uma implementação AMD, oferece um invólucro CommonJS tão módulos COmmonJs quase pode ser diretamente importado para uso com RequireJS.
FONTE
Comment: Ficou engraçado o primeiro bloco de código traduzido...
Comment: Então se eu entendi corretamente, RequireJS é uma biblioteca javascript que implementa a especificação AMD. Me deparei com AMD e CommonJS justamente por causa do RequireJS.
Comment: @bfavaretto obrigado novamente, não tinha percebido que estava traduzido o código. já arrumei.
Comment: @GuilhermeJSantos pelo que entendi, sim!

O que são AMD e CommonJS?


Show that $2^a + 1 $ is divisible by 3 if a is odd.

Question: I understand that this question has been asked before, but I was wondering if I could get clarification in understanding the accepted answer by @Hagen von Eitzen. (Sorry no plagiarism here is intended, just want to clarify my understanding):

If $k=2m$, then $2^k=4^m≡1^m\pmod 3$ and if $k=2m+1 $
then $2^k=2⋅4^m≡2⋅1^m\pmod 3$

I understand each step of this answer, except how it relates to the question of $2^a + 1$ being divisible by 3?
From my understanding of the definition of modular congruence, the last part of the answer is the same as $ 3|(2 \cdot 4^m - 2 \cdot 1^m)$.
This seems clear to me with the coprime cancellation rule - but I don't see how to go from this step to concluding that $2^a + 1$ is divisible by 3 when a is odd?
I would greatly appreciate it if someone could give me an explanation in 'plain english'?
Many Thanks!!
Comment: Since $1^m = 1$, you get $2^{2m+1}+1 \equiv 2\cdot 1^m + 1 \equiv 2+1 \equiv 0 \pmod{3}$.
Comment: $3|(2^a+1)\Leftrightarrow 2^a+1\equiv0\bmod3\Leftrightarrow 2^a\equiv2\bmod 3\Leftrightarrow a~\rm odd$.
Answer: For the second, when $k$ is odd, $$3\mid (2 \cdot 4^m - 2 \cdot 1^m) \iff 3\mid (2\cdot 4^m - 2) \iff 3\mid (2(4^m - 1))$$
Can you show that $3\mid 4^m - 1$? (See the case of even $a$: $2^k=4^m≡1^m\equiv 1(\mod3)$, so $4^m - 1 \equiv 1 - 1\equiv 0 \pmod 3$.
Put differently, for odd $a$:
$$2^a + 1 \iff 2^{2m+1} + 1 \equiv 2\cdot 1^m + 1 \equiv 2 + 1 \equiv 0 \pmod 3$$
Comment: Exactly. $2^a + 1$ is indeed congruent to $0$, mod 3, so $3$ divides $2^a + 1 - 0 = 2^a + 1$, for *odd* a.
Comment: Many thanks for explaining each step, your answer is very helpful and clear. Can I just clarify: is it correct that that the congruence operator can be treated like an equality? So what I read from your last line is that since $2^{2m+1} + 1 $ is congruent to $2 \cdot 1^m + 1 $ and that is congruent to 3 which is obviously congruent to 0, then we have that $2^a + 1$ is congruent to 0, so divisible by 3?
Answer: I will give an outline.
Let the statement be
$$P(a) =2^a  + 1$$
The statement becomes true for  $a= 1$
Let it be true for some odd integer $k$ so that $$P(k) \equiv 0 \ (\mathrm{mod}\ 3)$$
For $k+2$, (the next odd integer)
if it evaluates to be true that
$$P(k+2) - P(k) \equiv 0 \ (\mathrm{mod}\ 3)$$
then,
$$\begin{align} P(k+2)-P(k) &= 2^{k+2}-2^k \\& = 3  \cdot 2^k \end{align} $$
which is true and by applying induction you can prove it.


Can I use bottom up, middle out, or top down approaches with fabletools:reconcile?

Question: I have been learning how to use the very handy fable package (along with forecast, fabletools, etc.) and I have looked at fpp2 and fpp3 in the processes. fpp2 chapter 10 talks about hierarchical forecasting and the bottom up, middle out, and top down methods in which you forecast one level of a series and aggregate / disaggregate the series up and / or down. This is done with the hts and forecast packages.
fpp3 talks about the fable package but I dont see (apologies if I missed it) a section talking about forecasting hierarchies. What I have found thus far is that fable forecasts all the series in a hierarchy together as opposed to the older approach of forecasting one level. And you can use reconcile to... well reconcile these with each other. I've looked for more explanation and examples but the only ones I've found use reconcile with min_trace like this:
if (requireNamespace("fable", quietly = TRUE)) {
library(fable)
lung_deaths_agg <- as_tsibble(cbind(mdeaths, fdeaths)) %>%
  aggregate_key(key, value = sum(value))

lung_deaths_agg %>%
  model(lm = TSLM(value ~ trend() + season())) %>%
  reconcile(lm = min_trace(lm)) %>%
  forecast()
}

So my questions are:

Are there other more in depth resources I'm missing for forecasting using fable?

Specifically a list of all the reconciliation methods and how they should be used?

Can you use something like bu, mo, td reconciliation with reconcile?
Are approaches like min_trace considered better in all respects than bu, mo, td approaches and so I should just not worry about it?

Thanks very much for any help anyone could offer!
Answer: Hm. Unfortunately, ?fabletools::reconcile gives a very rudimentary help page. I am not privy to the internals, but what I can tell you may already be helpful.
I strongly suspect that min_trace implements an optimal reconciliation approach which, yes, typically performs better than bottom-up, top-down and middle-out. It looks like FPP3 does not have the relevant chapter yet, so I would recommend Chapter 10 in FPP2, especially section 10.7.
Specifically, the flavor that min_trace gives is probably optimal reconciliation through trace minimization (Wickramasurya, Athanasopoulos & Hyndman, 2019, JASA - yes, the latter two are the authors of FPP). That paper also references a number of earlier papers on optimal reconciliation, e.g., the original one by Athanasopoulos et al. (2009, IJF), with a corrigendum by Athanasopoulos et al. (2015, IJF), and the one by Hyndman et al., (2011, CS&DA).
These papers and the FPP2 section should give you a very good foundation to understand what is happening, even in the absence of thorough documentation. Alternatively, you could work with the older hts package for hierarchical time series, which implements almost the same functionalities (for now).


How to check if MySQL server is working or not?

Question: I have installed Webuzo on my unmanaged VPS. I am not able to install any applications, since it is giving me errors such "Unable to connect to MySQL server". But through terminal, the MySQL status is running.
Can anybody help how to troubleshoot?
Comment: I think it unlikely you'll get much help here. Professional environments [almost never use these sorts of "stacks"](http://serverfault.com/q/453617/126632) to deploy web applications; they are generally designed for developers and enthusiasts, people at the very end of the long tail, and people who don't actually know how to administer a web site.
Comment: `But through terminal, the MySQL status is running` <- How have you determined this? [You need to describe things with some level of detail that would be useful to a person who knows nothing about your environment](http://meta.serverfault.com/questions/3608/how-can-i-ask-better-questions-on-server-fault)
Comment: I remember installing it one by one. Not through LAMP or Webuzo.
Answer: Many ways to do it - in your terminal:
sudo service mysql status
or
ps aux | grep mysql
What you're facing is probably authentication failure or database misspell.
Did you try logging in with same creds via Terminal?
mysql -u <username> -p <database-name>
Hope it helps :)
Comment: Also check to what IP address the daemon is bound. Maybe you're using the wrong one and that is the reason for the failure?
Answer: You can check the MySQL service status as follows :
`Root > service mysqld status
or
Root > ps aux | grep mysql
or
// Is MySQL listening to the required port
Root > lsof -i :3306`
You can check the status of the MySQL service from the Webuzo Enduser Panel >> Services Menu.
Guide : http://webuzo.com/wiki/Restart_services
As for your error "Unable to connect to MySQL server", are you able to create databases from the Webuzo Enduser Panel ?
Guide : http://webuzo.com/wiki/How_to_Create_and_Manage_MySQL_Databases
Did you change the MySQL root users' password ?
Password for the MySQL root user is in the file /var/webuzo/my.conf
If the MySQL service is running, try accessing the MySQL server from the terminal.
Hope it helps \m/
Comment: Correct first command is [sudo] service mysql status
Answer:
lsof -i :3306 a

and

mysqladmin processlist
Answer: ps uxa | grep mysqld
If there is output, your mysqld is active. (Although it can be yet unreachable, but that will be your next question soon)
Answer: Default MySQL server port is 3306, if it's running then you'll have to check for the right port being used:
# netstat -vulntp |grep -i mysql

If no results returned then you'll have to check your MySQL log.
Answer: "process is running" is not same as "service is available" for everywhere.
check your detail logs on both client and server side to find error detail, and check service connection status by manual connection:
$ mysql ...

from DB server locally, and from client.
I don't know about Webuzo. it's just general answer.


The only closed subscheme of an affine scheme is the scheme itself?

Question: I was recently reading this excerpt from Mumford's Red Book. It concerns showing that every closed subscheme of an affine scheme $\text{Spec }R$ is determined by an ideal $R$. The individual steps themselves don't seem too hard, but once I realized what he was actually proving I became very confused. He defines the inclusion morphism $f: Y \longrightarrow \text{Spec }R$ where $Y$ is a closed subscheme of $\text{Spec }R$. He then proves, in the second paragraph of the excerpt I linked above, that $f$ is surjective. I originally thought this was a typo, but it seems to be the genuine conclusion of his argument. How is this possibly? How is the inclusion of a closed subscheme of an affine scheme surjective? That would mean that every closed subscheme of an affine scheme is homeomorphic to the whole affine scheme itself. That surely can't be the case, can it? It seems that either it is a mistake, or I have hugely misunderstood something. Knowing me, it's the latter.
Note also for those not familiar with the older terminology, Mumford uses the term "prescheme" in the same way modern authors use the term "scheme", and reserves that term for those preschemes which are separated.
Comment: He only proves f is surjective when A is the zero ideal.
Comment: @Jake Where does he use the fact that $A$ is the zero ideal? Or even suggest that?
Comment: He explicitly assumes A=(0) in the proof. He shows f factors as $Y \to \operatorname{Spec} \left( {R/A} \right) \to \operatorname{Spec} \left( R \right)$ and so what is left is to prove $Y \to \operatorname{Spec} \left( {R/A} \right)$ isomorphism. Since ${\mathcal{O}_Y}$  is just ${\mathcal{O}_{\operatorname{Spec} R}}/\mathcal{Q}$, he reduces to proving the case where A=(0).
Answer: $\DeclareMathOperator{\Spec}{Spec}$
The morphism $f: Y \rightarrow X$ is a closed subscheme of $X = \Spec R$.  This means that the underlying space of $Y$ is a closed subset of $X$, the underlying map of $f$ is inclusion, and $f^{\#}: \mathcal O_X \rightarrow f_{\ast} \mathcal O_Y$ is a surjective morphism of sheaves.  In Mumford's notation, $\mathcal Q$ is the kernel of the morphism $f^{\#}$; it is a sheaf of ideals of $\mathcal O_X$.
In particular, $A := \mathcal Q(X)$ is the kernel of the ring homomorphism $f^{\#}(X)$ going from $\mathcal O_X(X) = R$ to $f_{\ast}\mathcal O_Y(X) = \mathcal O_Y(Y)$.  So by the first isomorphism theorem, there exists a unique ring homomorphism $\phi: R/A \rightarrow \mathcal O_Y(Y)$ such that $\phi \circ \pi = f^{\#}(X)$.  It is injective.
A homomorphism from a ring into the global section of a scheme, corresponds bijectively to a morphism from that scheme to the spectrum of the ring.  Therefore, the morphism of schemes $g: Y \rightarrow \textrm{Spec}(R/A)$ corresponding to the ring homomorphism $\phi$, is the unique morphism of schemes such that $i \circ g = f$, where $i: \textrm{Spec}(R/A) \rightarrow X$ is the morphism of schemes corresponding to $\pi$.
Mumford wants to show that $g$ is an isomorphism of schemes.  In particular, $Y$ will be affine, and the morphism $g$ will basically be the morphism coming from the projection onto a quotient ring.  There are two things you can check about $g$:

1 .  The map on global sections $g^{\#}(X)$ is injective: this map is just $\phi$, which we know is injective.
2 .  $g: Y \rightarrow \textrm{Spec}(R/A)$ is a closed immersion.  The underlying map is inclusion (since this is the case for $f$ and $i$), and since $f^{\#} = (i \circ g)^{\#} = i_{\ast}(g^{\#}) \circ i^{\#}$ is surjective, so is $i_{\ast}(g^{\#})$, hence so is $g^{\#}$.

Thus $\textrm{Spec}(R/A)$ becomes your new $X$, and $g$ becomes your new $f$, and you have reduced to showing that $f$ is an isomorphism of schemes in the special case where the map on global sections is injective.
Comment: I was wondering if you could elaborate a bit on why $i_{*}g^{\#}$ being surjective means that $g^{\#}$ is surjective? Surely the direct image functor doesn't reflect surjections in general?
Comment: It does not in general.  But in this case, $i$ is the inclusion of a closed set $Z_0 = \textrm{Spec}(A/I)$ into $X$.  In this special case, $i_{\ast}$ is a faithfully exact, faithful functor from the category of sheaves on $Z_0$ to that of sheaves on $X$.  The essential image is those sheaves whose stalk at $x \in X - Z_0$ is zero, and a quasi-inverse of $i_{\ast}$ is $i^{-1}$.  Mumford basically says all this in the section before this theorem.  And for our purposes, what we need is that $i_{\ast}$ sends surjective morphisms to surjective morphisms and conversely.
Comment: Ahh, of course, it has a right adjoint given by the extension by zero as you describe. Since it is also a right adjoint itself, exactness follows. I'll read up to convince myself of the faithfullness part, but thanks!

Edit: Sorry, I meant compactly supported sections, not extension by zero.
Comment: It's easy to prove directly that if $i_{\ast}(\alpha)$ is surjective, then so is $\alpha$, by checking surjectivity at the stalks.  This is because $(i_{\ast}F)_x = F_x$ for all $x \in Z_0$, and $0$ if $x \not\in Z_0$.


Can I share an HTML player?

Question: I am trying to share a custom HTML/JavaScript player in Facebook. Is it possible?
I have tried with
    <meta property="og:video" content="https://***/player.html">
    <meta property="og:video:type" content="text/html">
    <meta property="og:video:secure_url" content="https://***/player.html">
    <meta property="og:video:width" content="500">
    <meta property="og:video:height" content="500">

What I want to do is a system like the Twitter player cards. I wish to have my player embed in Facebook in an iframe (like Twitter). This way I can have a custom skin for my player and control it the way I want.
The code above is working if I link an MP3 file in secure_url & video but not when I link the player (example of link: https://***/player.html)
When shared on Facebook I have my link in a "video" element with the source set to my link.
Comment: No you can't. Only flash is possible
Comment: Thanks,
for some reason my "Hello" was skiped .. Sorry about that.
Comment: @WizKid just sow thinglink.com and they do have a sharing with an iframe withing facebook. Tags on the page use the "og:video:type" -> "text/html"

I can't find anything on that in the facebook documentation. Any idea ?
Answer: well, youtube and soundcloud use html players for sharing. "https://www.youtube.com/embed/xPR-Ej-ENbk". So it should be possible, I am working on the same issue here, but when rendered on facebook am getting a div with class name "me-cannotplay", and am still trying to figure out if this something related to getting white listed by facebook or if there is something wrong with the html player i am using.
Comment: We are testing a html5 feature with some sites like youtube and soundcloud.
Comment: Hey, still looking for a solution just sow https://www.thinglink.com/
When you a share something you've done it display in an iframe. I tried to do the same (tags) but i get 'me-cannotplay" and no iframe ..

So it's possible but i cannot find any doc on it ...
Comment: Thanks, Is there a way to apply for it ?
Comment: Yup am also still working on it, but i got delayed because looks your player needs to be hosted over https (Secure protocol), otherwise it doesn't load. I tried using a player that is hosted on another site just for the testing, but i  got a link to download the file instead, am not sure what is the problem. When I get a chance to work on this I will repost here if I find a good solution
Comment: hi Khudairy, were you able to find a solution yet?
Comment: @RiteshKsheersagar, well we did everything as suggested by facebook ... at the end when sharing something it rendered like it is video, but then when you try to play it it gets replaced with a download link!. I am not sure of the reason, is it that we are not using streaming (we are just playing the file as is), or is it that only certain sites are allowed to render the player on facebook! not sure. Tried contacting some people at Facebook but with no response. If I every have updates I will post them here.
Answer: As @WizKid said, a simple answer is that you just cannot embed any javascript in facebook story.

Can I share an HTML player?


Unable to see adoptopenjdk-8-hotspot in java --version

Question: I have installed adoptopenjdk
apt search adoptopenjdk | grep installed

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

adoptopenjdk-8-hotspot/buster,now 8u242-b08-2 amd64 [installed]

But when I do :-
$ java -version
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Debian-1deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Debian-1deb10u1, mixed mode, sharing)

I don't see it in the above output.
What am I missing?
Comment: Have you tried `which java`? Are the newly installed binaries in your path? Do the conflict with currently installed version?
Answer: I was mistaken. I had to do :
sudo update-alternatives --config java

and choose the adoptopenjdk.  Then, I had to do:
java -version

to see the newly installed java.


Number Theory: Prove that for any $n\exists k$ such that $n\mid\phi(k)$.

Question: I think I've proven this homework problem, but I'm not sure if my proof is correct:
Given an integer $n$, prove that there exists at least one $k$ for which $n\mid \phi(k)$. (Where $\phi$ is the Euler-phi function).
Proof
Let $n=p_1^{a_1}p_2^{a_2}\cdots p_r^{a_r}$.
Note that $\phi(n)=n(1-\frac{1}{p_1})(1-\frac{1}{p_2})\cdots(1-\frac{1}{p_r})$.
Now, let $k=n^t$, some $2\leq t\in\mathbb{N}$. Then, $k=p_1^{ta_1}p_2^{ta_2}\cdots p_r^{ta_r}$. So,
$\phi(k)=n^t(1-\frac{1}{p_1})(1-\frac{1}{p_2})\cdots(1-\frac{1}{p_r})=n^{t-1}\phi(n)=n^{t-1}m$, since $\phi(n)=m\in\mathbb{Z}$.
Clearly, $n\mid n^{t-1}$, so we have $n\mid\phi(k)$ if $k=n^t$ for any $2\leq t\in\mathbb{N}$.
Comment: looks good - just one little adjustment -  the condition required is $t \gt 1$ rather than $t \in \mathbb{N}$
Comment: Thank you very much, just made the adjustment.
Answer: Looks good to me. Were there any doubts you had that motivated you to ask for verification?
Comment: It's just that the theorems I used to prove it were all from former sections, so I felt like since this question was in a later section, I must have to use one of the new theorems.
Comment: Well looking at your proof now are there any of the new theorems which encompass parts of the argument you just made?
Comment: It doesn't seem that way. But I'm glad I was able to prove it using simpler theorems anyway.


Custom module library not detected

Question: I am writing a custom module to load the crossfilter.js library in Drupal 7. I have followed what I believe are the right steps to doing that when using the Libraries module API.
However when I run drush libraries-list all I get for my library is 'not detected'
Below is my sample code. I intend to load version 1.3.7 of the library and already I have a directory called crossfilter and I have the crossfilter.js and crossfilter.min.js files in that directory.
What could I possibly be doing wrong?
function crossfilter_libraries_info() {
$libraries['crossfilter'] = array(
  'name' => 'Crossfilter JS',
  'description' => 'Crossfilter JS integration for Drupal',
  'download url' => 'https://github.com/square/crossfilter/archive/master.zip',
  'vendor url' => 'http://square.github.io/crossfilter/',
  'version arguments' => array(
      'file' => 'crossfilter.min.js',
      'pattern' => '/version="(\d+\.\d+\.\d+)"/',
   ),
  'files' => array(
      'js' => array('crossfilter.min.js'),
    ),
  'variants' => array(
      'source' => array(
          'files' => array(
              'js' => array('crossfilter.js')
            ),
        ),
    ),

);
return $libraries;

}
Comment: This code looks fine to me. Can you confirm the files are at /sites/libraries/crossfilter/*.js? You could also try to reinstall the module with devel module. Perhaps Drupal has not found the hook yet.
Comment: Did you mean /sites/all/libraries/crossfilter/*.js? I do have the files in place and still getting the same error. Let me try the devel approach.
Answer: Most likely your version regex ist wrong. According to the source code, the version string looks like this:
crossfilter.version = "1.3.7";

The regex pattern needs to account for the whitespace around the equal-sign. I'd probably write it like this
'pattern' => '/crossfilter\.version\s*=\s*"(\d+\.\d+\.\d+)"/',

Comment: That was the gotcha plus the file. I can pick the version from crossfilter.js and not crossfilter.min.js.

Custom module library not detected


Include title and href in images from Array of Objects

Question: I have a map (background image) on a Canvas, and "markers" in some cities (images duplicated from an Array of Objects and included in Canvas by drawImage ()).
Now I have to include href and title attributes in these markers. The data is also in the same Array of Objects.
The code so far:
var mkr = [
        {markerX: 222, markerY: 9, mkrTitle: "t1", mkrAction: "http://www.google.com"},
        {markerX: 210, markerY: 93, mkrTitle: "t2", mkrAction: "http://www.google.com"},
        {markerX: 122, markerY: 82, mkrTitle: "t3", mkrAction: "http://www.google.com"},
        {markerX: 103, markerY: 190, mkrTitle: "t4", mkrAction: "http://www.google.com"},
        {markerX: 96, markerY: 209, mkrTitle: "t5", mkrAction: "http://www.google.com"},
        {markerX: 122, markerY: 762, mkrTitle: "t6", mkrAction: "http://www.google.com"}
    ]

    var x = [];
    var y = [];
    var title = [];
    var action = [];

    Object.keys(mkr).forEach(function(key) {

      var valX = mkr[key]["markerX"];
      var valY = mkr[key]["markerY"];
      var valT = mkr[key]["mkrTitle"];
      var valA = mkr[key]["mkrAction"];

      x.push(valX);
      y.push(valY);
      title.push(valT);
      action.push(valA);

      var c = document.getElementById("mCanvas");
      //EDIT:
      var cLeft = c.offsetLeft;
      var cTop = c.offsetTop;
      //
      var ctx = c.getContext("2d");
      var img = document.getElementById("marker");
      ctx.drawImage(img, val, val2);

      //EDIT:
    c.addEventListener('click', function(event) {
                valX = event.pageX - cLeft,
                valY = event.pageY - cTop;
                console.log(x, y);
                mkr.forEach(function(img) {
                    if (valY > img.top && valY  img.left && valX < img.left + img.width) {
                        ctx.fillText = mkr.valA;
                        window.location.href = mkr.valA;
                    }
                });

            }, false);

    });

And the HTML:

<canvas id="mCanvas" width="295" height="809"></canvas>
<canvas id="mapCanvas" width="600" height="600"></canvas>

I can retrieve the data from the Array, but I can not include them as image attributes. My intent is to add click event on each image (markers) that I have over the map, using the data from the "mkrAction" item.
EDIT:
As suggested, I have included the addEventListener code to try it, but simply it didn't work. Nothing happens, neither error on console... Where am I doing wrong?
Comment: Why use `Object.keys()` on an array? `mkr.forEach` will suffice
Comment: Titus, it's not a real map, just an image with some effects. But I think that your example above will be what I need.
Comment: haim770's suggestion is a good one, just note that the object passed to the function will be the object at the index itself instead of a key. You can also obtain canvas context once outside the loop. For text you can use fillText(). Though, there is not really a question in the question...
Comment: What do you mean by "include them as image attributes" ? You're not creating HTML `img` elements, you're drawing the images on the canvas.

If you want to respond to click and hover events on those markers (the images drawn on the canvas) you'll have to set events listeners to the canvas and check the pointer position to see if it is over one of the markers.
Comment: haim770 yes, I can change using forEach, but would it change the way to solve the problem? If so, I could edit the code above...
Comment: For the href just add a click listener to your image/canvas or where you want to be triggered (not really clear from the question)
Comment: Titus, Can I use the data of positions that I already have to find the point to call the event? May you give me some example of it?
Comment: Yes you can use the position data because you're using it when you draw the images, beside the position you also need the images' size. Here is an example of responding to clicks on shapes drawn on a canvas http://stackoverflow.com/a/9880302/1552587
Comment: Beside the click implementation in that example you'll also need to do something similar for hover events to draw the markers' title.
Comment: If you're dealing with maps and markers you should take a look at the [Google Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/)
Answer: Probably you need something like this...
NOTE: I used two different markers so you can notice that is working.
Edited: I modified the code to make every element clickable. You will get an alert with the name of the element.

window.onload = function() {
  mkr = [
        {markerX: 10, markerY: 80, mkrTitle: "t1", mkrAction: "http://www.google.com"},
        {markerX: 210, markerY: 93, mkrTitle: "t2", mkrAction: "http://www.google.com"},
        {markerX: 122, markerY: 82, mkrTitle: "t3", mkrAction: "http://www.google.com"},
        {markerX: 190, markerY: 190, mkrTitle: "t4", mkrAction: "http://www.google.com"},
        {markerX: 96, markerY: 209, mkrTitle: "t5", mkrAction: "http://www.google.com"},
        {markerX: 23, markerY: 262, mkrTitle: "t6", mkrAction: "http://www.google.com"}
  ]

  var x = [];
  var y = [];
  var title = [];
  var action = [];

  var c = document.getElementById("mCanvas");
  var elemLeft = c.offsetLeft;
  var elemTop = c.offsetTop;
  var ctx = c.getContext("2d");
  var img = document.getElementById("marker");

  mkr.forEach(function(key) {
    var valX = key["markerX"];
    var valY = key["markerY"];
    var valTitle = key["mkrTitle"];
    var valAction = key["mkrAction"];

    x.push(valX);
    y.push(valY);
    title.push(valTitle);
    action.push(valAction);

    var c = document.getElementById("mCanvas");
    var ctx = c.getContext("2d");
    var img = document.getElementById("marker");
    ctx.drawImage(img, valX, valY);
  });

  // Add event listener for `click` events.
  c.addEventListener('click', function(event) {
    var x = event.pageX - elemLeft,
      y = event.pageY - elemTop;

    // Collision detection between clicked offset and element.
    mkr.forEach(function(element) {
      if (y > element["markerY"] && y < element["markerY"] + 100 &&
        x > element["markerX"] && x < element["markerX"] + 100) {
        alert('clicked on element: ' + element["mkrTitle"]);
      }
    });

  }, false);
};

<canvas id="mCanvas" width="400" height="400"></canvas>

<canvas id="mapCanvas" width="600" height="600"></canvas>
Comment: Teocci, sorry I didn't understand... My issue is to include event click, using the data inside the "mkrAction" as link for each image on the Canvas. All of the images must be the same.
Comment: All these 6 elements are clickable now


How to have different URLs for microsites?

Question: First of all, thanks for anyone bearing with me with this issue. I know that I really should start looking into how Apache settings work etc., but first of all, I would like to get this working. (Plus points for anyone recommending good Apache learning material, right? ;) )
I'm working on a Drupal 6 site running on Apache where several users (around 120) will have content which will act as a microsite. I have defined a content type for this purpose, used ThemeKey to switch to another theme only on those nodes etc.
I would like to be able to serve any of those nodes on a different domain (e.g. microsite.com) than the main site (e.g. mainsite.com). What should I do to "redirect" (sorry if I'm using any wrong terms here) the new domains to the right place? I would like to keep the new URL for the new pages (so it would not occur as mainsite.com/microsites/microsite, but microsite.com in the address bar).
[I've heard that it would be a bad idea to serve the same microsite with two different URLs from a SEO viewpoint - so that's another issue I should consider, but I have no idea on how I should address this...]
Comment: Have a read through these points: http://drupal.org/node/43816
Comment: Multisite is not appropriate for using a single database to serve up multiple domains.
Comment: For the SEO issue check out [the canonical URL tag](http://www.seomoz.org/blog/canonical-url-tag-the-most-important-advancement-in-seo-practices-since-sitemaps). Edit: actually I'm not sure it will help across domains (would be interested if anyone can clarify:).
Comment: Confirmed, see bottom of http://www.google.com/support/webmasters/bin/answer.py?answer=139394.
Answer: This is what the Domain Access module is for.  Essentially, it allows you to run multiple Drupal sites out of the same database, and share content.
Sending particular pieces of content to different domains is rather easy; a new tab shows up on edit panels.
It integrates nicely with Panels, Views, and other modules that use cTools, as domain rules show up as selection criteria.
For the Apache side, you need to configure it so that your multiple domains point to the same DOCROOT.  How this is done depends on how you are running your sites.  If you are using virtual hosts, then you set up additional ServerAlias settings for your <VirtualHost>


nested CV for parameter importance

Question: I was wondering whether you can help me sort out some confusion I have about using nested cross validation (i.e. inner + outer cv loops) in a ML analysis.  I am happy to share some code, but I think that my question is more conceptual, so I'll try to keep it short.
I have a large data set with ~600 different binary predictors and a binary outcome. My goal is not to build a prediction model (we are likely missing a lot of important predictors, which are currently unknown), but rather use the model to identify important variables in the dataset that are most strongly associated with the outcome. The database has ~7000 unique rows, and the prevalence of the outcome is about 9%.  I am comparing several ML algorithms, but for simplicity I'll focus on xgboost for now.
What I've done so far is the following:

Shuffle the data and create a 20/80 split. Use the 80 for training and the 20 for testing.
Run a 5-fold cross validation on the training to tune the hyperparameters using a large grid search.
Choose the best set of hyperparameters based on the minimal average loss function (log loss) across the cv's.
Train the model on 80% of the data (i.e. all the validation data from the initial split) using the chosen hyperparameters.
Assess model performance on the remaining 20% (again, the focus of our analysis is really on finding the most important predictors, not on developing a prediction model. That said, it'd be nice to get some sense of model performance).
Finally, run the model again using all available data (i.e. 100%, including both initial splits), and use some metrics to assess variable importance.

So here are my specific questions:

I understand that when the same cross-validation process is used for selecting the hyperparameters as well as for assessing model performance, the performance score can be overly optimistic, which is why nested-cv is warranted. However, is this still true in cases when you leave some of the data completely untouched during the model building process (such as in my case above, where 20% were left out for validation - i.e. never touched by the model beforehand)?

When using nested-cv, the hyperparameters and the choice of variables can differ somewhat across the outer loops. So as opposed to the non-nested approach above where after the (inner) cv you're left with a specific set of hyperparameters that are then used to train a single model, the nested-cv repeats this process for each outer loop. My guess is that it can be reassuring if the same set of variables is selected each time, since that would indicate that the algorithm leads to stable results. But is there a formal way to combine the variable importance data from the different outer cv's together to get one unified variable 'importance' score, similar to what one can obtain from a single run of the model? Or is the nested-cv really meant solely for evaluation of model performance, and should not be used in cases when the primary goal is to identify a set of important predictors?

Thanks so much for your help!
Answer:
If you leave some data completely untouched during training and validation, and evaluate on it, there is apparent reason of optimism; unless you violate some inherent assumptions (e.g. time-series CV needs to respect the chronological order)
Ideally, any feature importance calculation should be accompanied with bootstrapping. So, the overall procedure is run several times with bootstrapped dataset, the feature importances calculated with their error bars associated (mean, std etc.). But, I admit that this can be sometimes pretty expensive. Cross validation is a cheaper alternative, however it's not the same.

nested CV for parameter importance


Help me understand the chord progression in Tatsuro Yamashita's 'Sparkle'

Question: I'm trying to understand/analyze 'Sparkle' (1982) by Tatsuro Yamashita. Funky stuff begins at 0:50.
The song is in Emaj (I think), and here's the chord progression I'm looking at (take it easy with my enharmonic spelling):

|  AMaj7    |  AMaj7    |  g#m7(#5)  |  g#m7(#5)  |
|  AMaj7    |  AMaj7    |  g#m7(#5)  |  g#m7(#5)  |
|  a#m7(#5)  |  am6      |  E/G#     |  amM7     |
|  am6      |  a#m7(b5)  |  F#9      |  B6/9sus4  |

Now, I can understand some of the stuff that is happening, like the first 8 bars is just 'IV' going to a stylish inversion of the 'I'. Since g#m7(#5) is practically the same thing as E(add9)/G#, if I'm not mistaken.
Then we see the first thing I couldn't understand, this a#m7(#5) going to the borrowed minor 'iv' [am6].

What is this a#m7(#5) chord? What's the relationship with the chords being played before and after? Even if I see this chord being an inversion of the F#maj chord, I can't really see where this chord comes from... and goes to.

Right after this am6 chord, we go back to the 1st inversion of 'I' [E/G#], and get hit with 'iv#7' [amM7].

I believe the 'I' [E/G#] acts like a dominant for the next chord that is 'iv#7' [amM7], but where does this chord come from?

And then, we go back to the borrowed minor 'iv' [am6], and another movement I don't understand comes here: from the am6 we go to a#m7(b5), which I believe is just an F#9 without the F# in the bass, because right next to it we have a complete F#9, being a secondary dominant to the last chord B6/9sus4.

Now, I said "I don't understand", because I was wondering... Does every chord need preparation? Like, can we throw a secondary dominant anywhere (just like this song, iv > V/V > V > IV > I), or am I missing something?
Comment: For what it's worth, I feel like m7#5 chord symbols are more often than not a sign that something's wrong with the sheet music! Here it's not incorrect, but it might be better described with an inversion for a different root - I'll try an answer, this is hard to explain in comments.
Answer: Yes, it's in E. The chords have many notes in them, which might make it harder to understand the progression in terms of something more familiar. I recommend trying to find a country/polka reduction with simplified chords, just basic triads stripped of bass inversions and sevenths, ninths etc. (I wrote this from the top of my head, not checking on an instrument, please report errors)
(I wrapped the chords in underscores to prevent this site's "smart" automatic guitar chord diagram generator from making this completely unreadable. :/ )
<code>|  _A_          |  _A_         |  _E_         |  _E_         |
|  _A_          |  _A_         |  _E_         |  _E_         |
|  _F#_         |  _Am_        |  _E_         |  _Am_        |
|  _E_          |  _C#m_       |  _F#m_       |  _Bsus4_     |
</code>
Then work from this bare-bones version towards something closer to the original. First, split the chords to triad + bass inversion:
<code>|  _A_          |  _A_         |  _E/G#_      |  _E/G#_      |
|  _A_          |  _A_         |  _E/G#_      |  _E/G#_      |
|  _F#/A#_      |  _Am_        |  _E/G#_      |  _Am_        |
|  _E/B_        |  _C#m/A#_    |  _F#m_       |  _A/B_       |
</code>
Then add sevenths, ninths, sharp and flat this and that. There are many of those used in this song. But it's just small detail texture - there's a hierarchy of importance, level of detail, so to speak. First you find out what country you're in, then what city, then what city block.
E/G# works as a I chord here, it's just a bass inversion. Similarly for F#/A#, in each chord the bass is where it is in order to have a smoothly stepping bass motion, e.g. A# - A - G# - A - B bass movement.
Maybe "F#9/A#" would describe the third-last chord better. Or maybe someone would look at it as A# half-diminished. The thing with harmony is, it is the sum of its parts, and all interpretations are right in a way, BUT there's one note that's more important than all the other notes and that's the tonic, your harmonic center point. In understanding harmonic progressions, you have to know where you are in relation to a tonic, and that's what you were already doing. If you know the set of sounding notes, one way to gain "understanding" is to simply stop analyzing and just play the tune. Then play it in different keys. When you've played long enough and can reproduce the harmony progression in any key and in any other context, then in many ways you "understand" it, and you don't have to be able to label it with fancy theoretic names.
If you're thinking how I could tell, or why I said it's E/G# and not some G#m something, that's just from experience. It sounded like E/G#, and the whole progression consists of idiosyncratic changes for this genre. If you can hear that the bass is G# and you're not sure what basic simple chord could best represent the harmony, guess something and test the hypotheses. If you play a G#m there, does it sound closer to the record than if you play an E? But anyway, it comes with practice. Listen, transcribe, play, make variations, play in different keys.
Answer:

What is this a#m7(#5) chord? What's the relationship with the chords being played before and after? Even if I see this chord being an inversion of the F#maj chord, I can't really see where this chord comes from... and goes to.

Seems like you've got a solid grip on the first few bars of the section, so I'll skip over that. And yes, I'd say E major is the best choice of key by far here. That's a good start! So what is A#m7#5 doing in E major? Well, first of all, I would point out that it is rare for a minor chord to be played with its fifth raised, since that modification ends up making the chord enharmonic to an inversion of a major triad, and so if that sonority arises, I think the most likely scenario is that the chord is an inversion of a major chord. In other words, I would steer clear of m#5 as a label unless it's really the only sensible chord symbol.
So let's ignore the symbols and just try to put a finger on what this chord is even doing here. For starters, one of the most obvious things to notice is the A# in the bass, which isn't in the key of E at all. What's that doing there? Well, it's not part of any chord in E, but it does look and sound a lot like it wants to go towards the note B (yes, that means A# is the correct spelling rather than Bb).
It doesn't go there, but let's pretend that it does for a second. Typically, this A# in the bass is either the third of an F# chord (V/V, a secondary dominant) or the root of a diminished chord (viidim/V). These chords are predominant chords that set up a move to the dominant, and they move the bass up by half-step to get to the dominant note. This is even supported by the melody, which runs up to an F# as though landing on the supertonic chord. So that's one way this chord could be rationalized in the key of E - it's some kind of secondary chord pointing to the dominant.
However, clearly here we don't end up on the dominant at all; instead we arrive at Am6 (actually, upon close listening there's no E note in the chord, only an Eb/D#, so it's really a diminished seventh chord instead, but that doesn't end up changing its function in this case). In this case, you could look at the A# chord as a substitution for the IV chord, Amaj7. In fact, the only difference between A# half-diminished 7 and A major 7 is the note A being sharped. If you replace the A# chord with an A major chord, the progression makes sense as a minor plagal cadence that ends up going to the inverted I chord.
This is a common chord substitution in jazz harmonies, and that kind of city pop uses those kinds of progressions often (footnote 1). Or alternatively, this is also similar to the IV V iii vi progression that a lot of Japanese popular music uses, just change the IV and the V is replaced by any chord that has the same function of going to iii (in this case, iii is also replaced by I in first inversion). However you slice it, the idea is that the A# chord is really a substitution for the normal IV chord. This is the same kind of chord progression that "Christmastime is Here" by Vince Guaraldi uses, if you're looking for another example in context. So this is still a predominant chord, it's just in the context of a minor plagal cadence instead of a normal authentic cadence.
(footnote 2)
So now we have a good idea of what this chord is doing harmonically in the chord sequence. I'd say now that it's best written as either A# half-diminished 7th add flat 13th (which makes the function a bit more obvious but is a bit clunky - just stick to A# half-dim 7 for clarity), or as F#9/A# (much cleaner, but is it really an F# chord?).

I believe the 'I' [E/G#] acts like a dominant for the next chord that is 'iv#7' [amM7], but where does this chord come from?

Well, if we're considering the above chords, it made the most sense for E to be the I chord, so perhaps instead it's better to recognize that A is the IV of E. At least that way, we have another common minor plagal sound which would fit right into the music so far. The only issue I have with that is that it's a weird place to put Am(maj7), it doesn't feel very resolved going to the next chord. It doesn't continue the descending bassline that the previous three chords established, either.
I had to go and listen to the song from the beginning to get a better picture of what the structure of the song was, and I realized that the A# chord starts a new prechorus section. That immediately tells me that this Am(maj7) chord is in the middle of a section, so it makes more sense in context to play such a restless chord there to keep momentum. By the way, I don't think this song EVER lands on the tonic chord in root position, and that would make a jarring iv(maj7) chord all the more appropriate to avoid any strong cadential resolutions.
So my theory on the Am(maj7) chord is that it's simply an interesting chord to get away from the I in a semi-logical way while also not committing hard to a resolution. Notice that it is followed up by a C#m7 chord in third inversion (the Am6 in the question's chord chart is completely incorrect on that one) which immediately begins another chromatic walkdown - that's technically a tonic function chord like E6 would be, but this song really doesn't want the audience to get comfortable on the I chord. For another example, "God Only Knows" by the Beach Boys does some similar things with inversions and avoiding the I to avoid strong harmonic resolutions.

[...] another movement I don't understand comes here: from the am6 we go to a#m7(b5), which I believe is just an F#9 without the F# in the bass, because right next to it we have a complete F#9, being a secondary dominant to the last chord B6/9sus4.

The chord chart in question is incorrect again; after that A# chord is an F#m9 chord instead, just part of a regular ii V progression. So this makes a bit more sense; now the descending bassline idea that started with the C#m7/B is aimed squarely at the note A. True to form, the song jumps down to F#m instead, but that's a simple substitution for the subdominant chord that the audience expects. This progression wouldn't work as nicely if it were a secondary dominant there, in my opinion, since that A# half diminished chord needs to go somewhere and F#7 is just too similar to feel like motion.
B6/9(sus4) is the big honkin' V chord, obviously, and note that it retreats back down onto the IV every time instead of going to the I. No strong resolutions here, which is clearly a stylistic choice.

Now, I said "I don't understand", because I was wondering... Does every chord need preparation? Like, can we throw a secondary dominant anywhere (just like this song, iv > V/V > V > IV > I), or am I missing something?

That will depend heavily on context, genre, and a lot of other factors. It's generally true that for most chords in any functional harmony setting the placement matters a bit - I iii ii iii V is not a very convincing chord progression, for example. I wouldn't say it's necessary to have a complete reasoning behind every single chord in every song, but more often than not there are useful patterns to observe and analyze in when and where different chords appear in music.
And it never hurts to double-check the lead sheet before analyzing, there were some errors that could trip people up pretty easily in this question. You can save yourself a headache or two when playing it, and analysis will probably make more sense as well if you've got the right chords!

Tatsuro Yamashita has even cited jazz, big band, and soul as influences, and the same kind of progressions can be found in the music of his wife Mariya Takeuchi.

There's a whole thing about negative harmony that basically makes the case that the minor plagal cadence is of equal strength to the authentic cadence because perfect fifths invert to perfect fourths and some crazy stuff like that, if you're looking for some extra rabbit-hole spelunking research.
Comment: This explanation was spectacular, thank you so much and sorry for the chord chart mistakes, I tried to figure it out by myself. I'm still scratching my head around that a#ø7 substituting the Amaj7, and, later, that minor major 7 chord as well. Can you recommend me any materials/books where I can learn more about 'chord substitution in jazz harmonies' and 'negative harmony'?


Copying mounted/used big file

Question: Do you know any Linux app which is able to copy mounted/used file? Similar behaviour to rebuilding RAID1 array - you can use master drive, while the second is rebuilding/mirroring content from the master drive.
I have 500GB file which is mounted and I would like to copy it without unmounting...
Answer: I understand that snapshot is not sufficient for you, because you need to have a copy from a recent point in time.
The industry name for the functionality that you require is Continuous Data Protection (CDP). Hope that it helps. This is relatively new technology for me, and I cannot really recommend any solution that "just works" for any arbitrary file on Linux.
Answer: A simple
<code>dd if=/dev/sdb1 of=/home/backup/disk.bak
</code>
should do the trick.
For mounted (device) files, you should definitely do a sync before you start the copy. Once dd runs, there is no guarantee that changes made to the filesystem are in the backup.
Before you start using the backup file, you should run fsck on the file
Comment: Thank you for answer, but as you mentioned, using dd doesn't guarantee consistent copy. Somehow RAID1 rebuilding mechanism does the trick, and I am looking for something similar.
Comment: ok, are you talking about an already running system, or a system you are planning? because if you are just planning it you could use lvm and snapshots

Copying mounted/used big file


how to contribute body of modal in bootstrap 3?

Question: The requirement-My applicaiton has a button which when clicked a modal is supposed to pop-up where there will contain some data.
Architecture-I want the modal data to be contributed from some another application(some url),through a php file.How can this be done?

What I have tried-In the php file i have placed
<?php echo '

        <button type="button" class="close" data-dismiss="modal"
            aria-label="Close">
            ×
        </button>

Modal title

...

        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>

In the html I am using this

        Launch Modal

Answer: Place your HTML code, as follows:

inside your Echo.
<?php echo ' HERE

UPDATED:

    Launch Modal

<?php echo '

        <button type="button" class="close" data-dismiss="modal"
            aria-label="Close">
            ×
        </button>

Modal title

...

        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>

'; ?>

Comment: I updated my answer. pls see that and it works in my localhost page. if it doesn't work, perhaps, you forgot to add bootstrap links
Comment: I saw you give a link inside the caller. you can change it into button instead of  if you need to redirect to an external page, then you don't need bootstrap modal
Comment: correct me if I am wrong but that is exactly what I am doing in the current scenario and its not working
Comment: thanks it works,what I did is along with your solution I punched @khanmizan solution.Together it works fine.However I have to chose only one best ans,so I would choose urs considering the efforts.Thanks :)
Answer: place the modal html in your html, and fetch modal content data dynamically through ajax call from server. and add that data to modal before displaying


Bootstrap javascript wordpress issue data-toggle="collapse"

Question: I'm having an issue with a project.
This is the first wordpress blog I do, the idea was the html site www.humantools.com.mx and build a blog for it www.humantools.com.mx/blog I have a weird problem, when loged the class="navbar-toggle collapsed" data-toggle="collapse" in the navbar works well, in the site it works well...
when I log out,  the nav item that normally brings the colapssed menu links to "#"
this is odd, I'm really hitting my head with this, please help, I'm adding the css and the header code, if you need anything else please let me know.

HEADER
<?php

  /**

  * The Header template for our theme

  *

  * Displays all of the  section and everything up till

  *

  * @package WordPress

  * @subpackage Twenty_Thirteen

  * @since Twenty Thirteen 1.0

  */

  ?>

  <html <?php language_attributes(); ?>>

  <meta charset="utf-8">

  <meta http-equiv="X-UA-Compatible" content="IE=edge">

  <meta name="viewport" content="width=device-width, initial-scale=1">

  <meta name="description" content="">

  <meta name="author" content="">

  <link rel="icon" href="http://www.humantools.com.mx/img/favicon.png">

  <title>Human Tools</title>

  <link href="http://www.humantools.com.mx/dist/css/bootstrap.min.css" rel="stylesheet">

  <link href='http://fonts.googleapis.com/css?family=Titillium+Web:200,400,300,700,600' rel='stylesheet' type='text/css'>

  <link href="http://www.humantools.com.mx/style.css" rel="stylesheet">

  <meta charset="<?php bloginfo( 'charset' ); ?>">

  <meta name="viewport" content="width=device-width">

  <title><?php wp_title( '|', true, 'right' ); ?></title>

  <link rel="profile" href="http://gmpg.org/xfn/11">

  <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">

  <?php wp_head(); ?>

  <?php echo ''.PHP_EOL; ?>

    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">

      Menú

    </button>

Quiénes
Somos

Soluciones
para Empresas

Outsourcing
de Nómina

Procesamiento
de Nómina

Info &
Contacto

Preguntas
Frecuentes

Aviso de
Privacidad

Blog

CSS
/*
Theme Name:HumanTools.
Theme URI: www.humantools.com.mx
Description: Human Tools blog.
Version: 1.0
Author: Raul Salazar
Author URI: www.bybrave.com
*/
body {
  padding-top: 70px;
  padding-bottom: 0px;
  font-family: 'Titillium Web', sans-serif;
}

.home {
    margin-bottom: 50px;
}

.interior {
    margin-bottom: 50px;
}

h1 {
  font-family: 'Titillium Web', sans-serif;
  text-align: left;
  text-decoration: none;
  font-size: 55px;
  font-weight: 200;
}

h2 {
  font-family: 'Titillium Web', sans-serif;
  color: #0876bb;
  text-align: left;
  text-decoration: none;
  font-size: 24px;
  font-weight: 400;
}

h3 {
    font-size: 40px;
    margin: 15% 0% 9% 0%;
}

h4 {
    font-size: 26px;
    margin-top: -5px;
}

.img-responsive {
    width: 100%;
}

.faq-divider {
    color: #adadad;
    margin-top: 30px;
    margin-bottom: 0px;
}

NAV STARTS
         .navbar {
          min-height: 78px;
}

.navbar-inverse {
    background-color: #212121;
}

.navbar-nav>li>a {
    padding-top: 10px;
    padding-bottom: 10px;
    line-height: 120%;
}

.nav>li {
    margin-top: 15px;
    margin-bottom: 15px;
    border-left: solid 1px #0876bb;
    border-spacing: 10px;
    padding: 0 15px;
}

li {
    font-size: 12px;
}

.navbar-toggle {
    margin-top: 20px;
}

.navbar-inverse .navbar-nav>.open>a, .navbar-inverse .navbar-nav>.open>a:hover,        .navbar-inverse .navbar-nav>.open>a:focus {
    background-color: #212121;
}

.dropdown-menu {
    background-color: #888;
    border-radius: 0px;
    box-shadow: none;
    min-width: 150px;
}

.dropdown-menu>li>a {
    color: #FFF;
}

.dropdown-menu>li>a:hover {
    color: #FFF;
    background-color: #0876bb;
    margin: 0 0 0 0;
}

.navbar-nav>li>.dropdown-menu {
    margin-top: 15px;
}

NAV ENDS
/* blog */
div .date {
margin: 40% 0px 0px 55%;
font-size: 18px;
}

.blog6 { max-height:100%;
max-width:100%;
}
.contenidoblog {
    text-align: justify;
    font-size:1.2em;
}
.tag {
font-size:16px;}
.bluetag {
    color: #0876bb;
font-size:16px;
}

.masblog { font-size:18px; text-transform:capitalize;
margin-bottom:30px;}

.sidebar {margin-top: 10%; }
/*end blog*/
/* CUSTOMIZE THE CAROUSEL
-------------------------------------------------- */

/* Carousel base class */
.carousel {
  height: 440px;
  margin-bottom: 60px;
}
/* Since positioning the image, we need to help out the caption */
.carousel-caption {
  z-index: 10;
  text-align: left;
  text-shadow: none;
  top: 40px;
  left: 5%;
}

/* Declare heights because of positioning of img element */
.carousel .item {
  height: 440px;
  background-color: #0876bb;
  background-image: url(img/slide-01.jpg);
  background-repeat: no-repeat;
  background-position: center;
}
.carousel-inner > .item > img {
  min-width: 1024px;
  height: 440px;
  vertical-align: middle;
}

.carousel-control {
    height: 510px;
}

/* CUSTOMIZE QUOTES
-------------------------------------------------- */
.quotes {
   margin-top: -10px;
}

hr {
    color: #adadad;
    margin-top: 40px;
    margin-bottom: 40px;
}

.quote {
    border: solid 1px #adadad;
    border-radius: 15px;
    margin-bottom: 50px;
    padding: 30px 30px;
}

#quote-img {
    position: absolute;
    top: 30px;
    left: 5px;
    width: 29px;
    height: 29px;
    background-image: url('img/quote-left.png');
    background-repeat: no-repeat;
}

#quote-img2 {
    position: absolute;
    top: 30px;
    right: 5px;
    width: 29px;
    height: 29px;
    background-image: url('img/quote-right.png');
    background-repeat: no-repeat;
}

#quote-img3 {
    position: absolute;
    bottom: 27px;
    left: 50px;
    width: 36px;
    height: 25px;
    background-image: url('img/quote-corner.png');
    background-repeat: no-repeat;
}

/* CUSTOMIZE INTERIORS
-------------------------------------------------- */

.blue {
    color: #0876bb;
}

.grey {
    color: #888888;
    margin-left: -15px;
    margin-bottom: 10px;
    margin-top: -20px;
}

.subheading {
    font-size: 18px;
    font-weight: 400;
    padding-top: 30px;
}

.contenido {
    text-align: justify;
}

ul {
    list-style-type: none;
    padding: 0px;
    margin: 20px 0 20px 0;
}

ul li.bullet-01 {
    background-image: url(img/bullet-01.jpg);
    background-repeat: no-repeat;
    background-position: 0px 22px;
    padding: 15px 0 15px 40px;
    font-size: 13px;
    text-align: justify;
}

ul li.bullet-02 {
    background-image: url(img/bullet-02.png);
    background-repeat: no-repeat;
    background-position: 10px 22px;
    padding: 15px 0 15px 40px;
    font-size: 13px;
    text-align: justify;
}

ul li.bullet-a {
    background-image: url(img/bullet-a.png);
    background-repeat: no-repeat;
    background-position: 0px 14px;
    padding: 15px 0 15px 40px;
    font-size: 13px;
    text-align: justify;
}

ul li.bullet-b {
    background-image: url(img/bullet-b.png);
    background-repeat: no-repeat;
    background-position: 0px 14px;
    padding: 15px 0 15px 40px;
    font-size: 13px;
    text-align: justify;
}

ul li.bullet-c {
    background-image: url(img/bullet-c.png);
    background-repeat: no-repeat;
    background-position: 0px 14px;
    padding: 15px 0 15px 40px;
    font-size: 13px;
    text-align: justify;
}

.img-responsive {
    margin-top: 30px;
}

/* CUSTOMIZE FORM
-------------------------------------------------- */

.form-control {
    background-color: #eaeaea;
    box-shadow: none;
    border-radius: 0px;
    height: 50px;
    border: none;
}
.btn {
    background-color: #0876bb;
    border-radius: 0px;
    border: none;
    margin-right: -15px;
    padding: 20px 30px;
}

/* CUSTOMIZE FOOTER
-------------------------------------------------- */

.footer {
  position: relative;
  bottom: -31;
  width: 100%;
  /* Set the fixed height of the footer here */
  height: 75px;
  background-color: #212121;
}

.f1 {
    font-size: 11px;
    padding: 30px 0 20px 25px;
    color: #fff;
    font-weight: 200;
    letter-spacing: .5px
}

.f1 a {
    color: #fff;
}

.f1 em {
    color: #0876bb;
}

.text-mutted {
    font-size: 11px;
    color: #888;
        padding: 30px 0 20px 0px;
}

@media (max-width: 990px) {
    #quote-img3 {
        bottom: -23px;
    }

    .f1 {
    padding: 20px 0 0 0;
    width: 60%;
    }
}

@media (max-width: 700px) {

    .copyright {
        margin-top: 130px;
    }

    .f1 {
    padding: 20px 0 0 0;
    width: 100%;
    }
}

function mbe_wp_head(){
    echo ''.PHP_EOL;
}

#respond {
background: #ffffff;
padding:10px;
margin-top:-15%;
}

/* Highlight active form field */

#respond input[type=text], textarea {
  -webkit-transition: all 0.30s ease-in-out;
  -moz-transition: all 0.30s ease-in-out;
  -ms-transition: all 0.30s ease-in-out;
  -o-transition: all 0.30s ease-in-out;
  outline: none;
  padding: 3px 0px 3px 3px;
  margin: 30px 1px 3px 0px;
  border: 1px solid #DDDDDD;
}

#respond input[type=text]:focus, textarea:focus {
  box-shadow: 0 0 5px rgba(81, 203, 238, 1);
  margin: 5px 1px 3px 0px;
  border: 1px solid rgba(81, 203, 238, 1);
}

#author {
font-family: Lobster, "Lobster 1.4", "Droid Sans", Arial;
font-size: 16px;
color:#1d1d1d;
letter-spacing:.1em;
}

#url  {
color: #21759b;
font-family: "Luicida Console", "Courier New", "Courier", monospace;
}

#submit {
font-family: Arial;
color: #ffffff;
font-size: 20px;
padding: 10px;
text-decoration: none;
border:0px;
border-top: 2px solid #0992e6;
background: #0773b5;
}

#submit:hover {
  background: #0869a4;
    border-top: 0px;
  border-bottom: 2px solid #0992e6;
text-shadow: 0px;
color:#cecece;
}

#commentform > p.logged-in-as {margin-bottom: 20px;}

Answer: These 3 files are returning a 404. You can see these buy opening up the JavaScript console in your browser.

http://www.humantools.com.mx/prueba/dist/js/bootstrap.min.js
http://www.humantools.com.mx/prueba/assets/js/docs.min.js
http://www.humantools.com.mx/prueba/assets/js/ie10-viewport-bug-workaround.js

The most important file is bootstrap.min.js which needs to be included. You should include bootstrap in your project like this - make sure that you have it in the directory you say you have: https://github.com/pjhampton/BigBooty/blob/master/lib/framework/enqueue.php
Comment: in my header i have then in a different directory http://www.humantools.com.mx/dist/js/bootstrap.min.js :/

and I have them in that directory, anyway I added the directory and loaded a copy of the files there and it got fixed, but would like to understand why this is happening.
Comment: You would really want to locate the bootstrap.min.js file at the bottom of the DOM. It wasn't working first of all because it could not read the files.
Comment: oddly enough I got it to work... I basically went through an extensive troubleshooting.

thanks for the comment, it did helped a lot :)


LSI RAID: Write cache policy affects read performance?

Question: I have a server with a LSI MegaRAID SAS 9260-4i controller, RAID-5 with 3 x 2 TB disks. I did some performance testing (with iozone3) and the numbers show clearly that the write cache policy affects the read performance as well. If I set the policy to WriteBack I get about 2x the read performance in comparison with WriteThrough. How could the write cache affect the read performance?
Here are the details of the setup:
megacli -LDInfo -L0 -a0

Adapter 0 -- Virtual Drive Information:
Virtual Drive: 0 (Target Id: 0)
Name                :
RAID Level          : Primary-5, Secondary-0, RAID Level Qualifier-3
Size                : 3.637 TB
Is VD emulated      : Yes
Parity Size         : 1.818 TB
State               : Optimal
Strip Size          : 512 KB
Number Of Drives    : 3
Span Depth          : 1
Default Cache Policy: WriteThrough, ReadAhead, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteThrough, ReadAhead, Direct, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy   : Disabled
Encryption Type     : None
Bad Blocks Exist: No
Is VD Cached: No

With WriteBack enabled (everything else is unchanged):
Default Cache Policy: WriteBack, ReadAhead, Direct, Write Cache OK if Bad BBU
Current Cache Policy: WriteBack, ReadAhead, Direct, Write Cache OK if Bad BBU

Some numbers from iozone3:
 WriteThrough:
                                                    random  random
      KB  reclen   write rewrite    read    reread    read   write
 2033120      64   91963   38146   144980   139122   11795   21564
 2033120     128   83039   90746   118660   118147   21193   33686
 2033120     256   78933   40359   113611   114327   31493   51838
 2033120     512   71133   39453   131113   143323   28712   60946
 2033120    1024   91233   76601   141257   142820   35869   45331
 2033120    2048   58507   48419   136078   135220   51200   54548
 2033120    4096   98426   70490   119342   134319   80883   57843
 2033120    8192   70302   63047   132495   144537  101882   57984
 2033120   16384   79594   29208   148972   135650  124207   79281

 WriteBack:
                                                    random  random
      KB  reclen   write rewrite    read    reread    read   write
 2033120      64  347208  302472   331824   302075   12923   31795
 2033120     128  354489  343420   292668   322294   24018   45813
 2033120     256  379546  343659   320315   302126   37747   71769
 2033120     512  381603  352871   280553   322664   33192  116522
 2033120    1024  374790  349123   289219   290284   43154  232669
 2033120    2048  364758  342957   297345   320794   73880  264555
 2033120    4096  368939  339926   303161   324334  128764  281280
 2033120    8192  374004  346851   303138   326100  186427  324315
 2033120   16384  379416  340577   284131   289762  254757  356530

Some details about the system:

Ubuntu 12.04
64 bit
Kernel 3.2.0 (3.2.0-58-generic)
Memory was limited to 1 GB for the test
iozone3 version 397-2
Partition used for the test:
/dev/sda4 /var ext4 rw,relatime,user_xattr,barrier=1,data=ordered 0 0
Comment: I would have expected otherwise - if write-cache is disabled there should be more read-cache available.
Answer: By using a writeback cache, you are saving disk IOPS.  The controller can batch up smaller writes into one big write.
Thus, there are more IOPS available for reads.
This assumes that the tests are concurrent.  If a given test is only reads or only writes this won't matter.
Comment: I would assume that iozone does not mix writes/reads when doing the read test. Also, a simple read test shows similar results, see also my comment to the answer of alxgomz.
Comment: I wouldn't assume anything...but your simple read test does seem like good evidence.
Answer: What filesystem is this test run on?
What comes to mind is atime. If your filesystem is mounted with atime option or missing no/relatime mount option you will get a write for every read.
(atime means recording last access time for files)
It might be helpful if you post the output of
mount

and specify on which device you did the tests.
Comment: The test was run on /var: mount output: /dev/sda4 on /var type ext4 (rw) /proc/mounts output: /dev/sda4 /var ext4 rw,relatime,user_xattr,barrier=1,data=ordered 0 0
Comment: ok, relatime should not affect the reads here. I would try with noatime, just to be sure. But I guess there is something else involved.
Comment: Yes, I'll try noatime, but I think it's something else, too. Nevertheless a good idea to think about filesystem options, thanks!
Comment: @tlo try to `sync` before doing the read-tests, too.
Answer: write-back policy do have effects on red performances when using tests like iozone because those benchmark tools measure read performance by reading data they have written previously.
hence when iozone starts read tests, some data still lies in the cache hence making the read throughput a lot higher. this is regardless of the size of files as the raid adapter has no knowledge of files, or even filesystems. All it knows are IOs and blocks.
keep in mind iozonr I'd an fs benchmark tool and thug totally abstracts hardware. maybe using -J/-Y you could mitigate effects of write back policy and get an idea of your read performance... or use a true HDD bench tool (hdparm?)
Comment: I did a quick test with hdparm: Without write-back I get around 140 MB/s with write-back I get > 300 MB/s. A simple dd read-test (from existing data, so data that was not written within the last minutes/hours) gives similar results.
Answer: The most obvious reason is because the reads are coming from the cache, rather than the disk itself. Remember that with WriteBack, the written data is held in the cache, until the RAID controller gets a chance/decides to write it to the disk. However it makes sense that if the same data is read (or anything that it still holds in it cache) then it uses the cache to retrieve the data, rather than indulge in relatively expensive disk reads.
Comment: I can't really believe this because the controller has 512 MB Cache and iozone is testing with 2 GB file size. Also, a simple dd test of partitions which were not touched in days show similar results.
Comment: Yes, I hadn't spotted that. You would expect that with a file size larger than the cache size, that it would effectively revert to WriteThrough mode
Answer: It is likely that as the file is being written it is also being written as on continuous block on the disk.
One thing the previous solutions don't take into account is the difference between how write-back and write-through commands are handled on the controller.
Write-Back means when the controller receives a command, it immediately tells the OS handler that it was "ok", and to give the next one. Write-Though waits for each individual command to report a success before processing the next query.
As a result commands are queued faster. Then the Read-Ahead setting of the Array will start populating the cache with a continuous stream of data.
You can see that Read-Ahead with the faster command queuing is helping quite a bit, if you look at the very small percentage differences between the Random Write and Random Read events which mostly remove the Read-Ahead boost especially at the smaller chunk sizes.
Another thing that can affect the performance is the slice size and block size for how many different heads are involved in each read or write operation.


How to get total minutes to display as Xhrs, Xmin?

Question: I'm taking a total number of minutes and am trying to calculate total hrs & minutes.
If you do:
<code>$elapsed = "6476"; // Trying to get 107:56 (107 hours, 56 min)

if ($elapsed > 60) { $format = "i:s"; }
if ($elapsed > 3600) { $format = "H:i:s"; }

$showdiff = gmdate($format, $elapsed);
</code>
The problem with this is it doesn't work for calculations above 23hrs 59min.
So, you can do simple division:
<code>$elapsed = $elapsed / 60; // total hours
</code>
Only then you will get a fraction (in this case, 107.933333333). I need to keep this as hours and minutes. Any suggestions?
Comment: Do you want to show zeros (i.e. 0 hours or 0 mins) or strip them from the string?
Answer: You should be able to use division (as you've stated) and modulus division to accomplish what you want.
<code>$hours = floor($elapsed / 60);
$minutes = round(($elapsed / 60) % 60);

echo $hours . "hrs " . $minutes . "min";
</code>
Comment: Could this be expanded to seconds?
Comment: Change `$minutes` to `$minutes = floor(($elapsed / 60) % 60)` and add `$seconds = round($elapsed / (3600)) % 60);`.  Note that your initial input of 6476 is in minutes, so you will have to change this value to seconds for this to work.  The `3600` comes from 60 seconds per minute * 60 minutes per hour.
Comment: One last thing... I noticed if the minutes are an even number (ie 72 even hours), the seconds get messed up because the minutes returns a single 0 instead of 00. I tried adding a ,2 at the end of minutes round but it didnt work.
Answer: you could try
<code>$elapsed = $elapsed / 60; // total hours (107.933333333)
$parts = explode(".", $elapsed); // split 107.93333 into 2 parts using the . as a separator
$minutes = $parts[1] // $parts[0] is 107, this will be the .9333
$minutes = $minutes * 60 // = 55.99...
$minutes = round($minutes); // round 55.9999 up to 56
$hours = $parts[0];

echo "$hours hrs $minutes mins";
</code>
probably could be written a bit better but my excuse is I'm tired :)
That should give you an idea though and let you do what you need to.


Creating a raw InnoDB disk in Ubuntu 10.04 with LVM

Question: I'm trying to create a 2TB raw partition for MySQL/InnoDB to use on one of my LVM's.
I created the raw disk:

Disk /dev/mapper/g0-sql: 2190.4 GB, 2190433320960 bytes
255 heads, 63 sectors/track, 266305 cylinders, total 4278190080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Then added the newraw command to my.cnf:

innodb_data_home_dir=
innodb_data_file_path=/dev/dm-1:2000Gnewraw;

When I restart mysql, I get a permission denied:

111204 14:43:43 [Note] Plugin 'FEDERATED' is disabled.
111204 14:43:43  InnoDB: Initializing buffer pool, size = 68.0G
111204 14:43:48  InnoDB: Completed initialization of buffer pool
111204 14:43:48  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name /dev/dm-1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.

I assumed this was Apparmor, so I added the following to /etc/apparmor.d/usr.sbin.mysqld:

/dev/dm-1/ r,
/dev/dm-1/** rwk,

I've also chowned /dev/dm-1:

# ll | grep dm-1
brw-rw----  1 mysql mysql   252,   1 2011-12-04 11:48 dm-1

But the error continues.
How do I get this sucker to work?
edit:
/dev/mapper/g0-sql is symlinked to /dev/dm-1, both are chowned to mysql
Answer: I'm guessing a little, but can your problem be in your apparmor profile?
you're referring to /dev/dm1/ as if it were a directory, which is a file (block device)
I will suggest trying /dev/dm-1 rwk in your profile ...
btw. are you aware that usage of raw innodb tablespace is generally not advised?
Comment: Ha! That did it! Why is it not advised? http://dev.mysql.com/doc/refman/5.5/en/innodb-raw-devices.html
Comment: it is mostly because modern filesystems are fast enough, that raw device performance gain is marginal and you lose some of the comfort of using files. as far as i was able to find any advice on this topic, in most cases it seems best practice to use file per table in InnoDB.
Comment: (http://www.fromdual.ch/mysql-performance-tuning-key 359n states this as last resort, 359l recommends fpt, http://goo.gl/EF1Uv doesen't recommend it either)


Domain Controller time is incorrect

Question: I have a domain controller running in VM on Hyper-V, the time seems to be steadily getting faster, over the X-mas period it's 5 faster, which seems odd!
I know how to change the time and I belive we setup an NTP server on the DC and ensured time-sync was turned off on Hyper-V.
I don't really want to keep setting the time. Is there a reason why the time is fast?
Comment: 5 what faster? 5x? 5 days? 5 seconds?
Comment: I have already asked a similar question once before (see below)

http://serverfault.com/questions/92617/domain-controller-time-is-7-minutes-fast

What I would like to know is why it's fast again?
Comment: Ha ha, yes sorry, 5 minutes faster
Answer:
I know how to change the time and I belive we setup an NTP server on the DC and ensured time-sync was turned off on Hyper-V.

Virtual Machines can't track time. You may want to try setting up the DC up as an NTP client. This blog might be useful.
http://www.aperture.ro/index.php/2009/01/windows-time-sync-hyper-v-enabled-domain-controller-dilemma/
The guy waffles for a bit, but scroll down and you will get the necessary registry entries. This KB article seems a bit more authorative.
http://support.microsoft.com/kb/223184
There is also a Technet article on configuring a DC to use NTP:
http://technet.microsoft.com/en-us/library/cc784553(WS.10).aspx
As for why this happens, VMware has a writeup about timekeeping with VMs (not HyperV, but the concepts still apply).
http://www.vmware.com/pdf/vmware_timekeeping.pdf
Comment: UPDATE: It does seem to have updated time today, I think it maybe updating monthly? Any idea's how to increase the update frequency, I did registry updates to set the NTP server.
Comment: I followed the steps in the links and it worked lovely, however it seems to be drifting again. It appears that it isn't polling regularly or at all anymore. Any idea's?

I am also using time.windows.com! Should I use a stratum 2 server on ntp pool?
Comment: How much is it drifting?
Comment: It's 5 minutes slow now. Don't know how much it's drifting by each day as I haven't been in the office for a while.
Comment: Is the VM server under heavy load?
Comment: Not really the host is running maximum at any time 4 VM's; 1x File Server, 1x DC (70 users, 40 computers, Routing & Remote Access) 1x Messaging Server and 1x Server hosting our bespoke software which is hardly doing anything. I'm considering syncing time from the host and having the host get time from an external NTP server? How do I go about removing the NTP client setup from your answer from my VM'ed DC?
Comment: w32tm /config /syncfromflags:NO
Answer: With VM's you always want the host to sync the guests, it's the only reliable way.
I realise this can create an infinite loop if the hosts are member servers of the domain, but every workaround I've tried (VMware server in my case) doesn't actually solve the problem.
If you run a good monitoring system (eg, Nagios) consider checking clock skew against the global NTP pool, or a reliable *nix based system (that's not a VM itself) running the NTPD package.
Comment: I think you or your advisor is confusing the local clock within the vm to the clock of the hardware server.  You only want to not sync with the parent OS if you are syncing with an external non vm source.
Comment: I've been advised not to sync the guests with the hosts. I take it you use the local clock of the hosts or do you use an NTP server on the hosts?

My hosts aren't domain members.
Comment: NTP server on the hosts which sets the local clock.
Comment: This answer may have been appropriate when written, but it is not best practice today.  VMware recommends using ntp in guests, as does Red Hat for KVM guests.  Dunno about hyper-v though.
Answer: VMs never keep accurate time (meaning they always have bad virtual CPU stats too), the only way to make sure they're accurate enough is to have them sync with a physical clock. This can be done either by syncing with the host and having all the hosts time correct via NTP or via having the VMs get their time via NTP with frequent checks - either method works but the former is probably the easiest.
Answer: All the prior answers seem reasonable, but let me add this.
Indeed, timekeeping inside a VM is a problematic issue, which brings up multiple possible solutions.

Set up another DC on an iron box, and have that be the authoritative time source
Set your VM DC to sync time from an external source more frequently - say every 10 minutes. Registry reference in this KB: 816042
Even simpler, use something like an Atomic Clock sync tool on the DC, and set its frequency to 10-15 minutes
Another question on Serverfault had a similar problem, and ruled out the hardware clock by running the same VM in VMware Server, and found that the problem lies with Hyper-V.
Answer: Is there a reason you can't sync to an external source, such as one of the Internet time services? If you're having such a problem with drift just sync hourly, or whatever other period you feel might be suitable.
Answer: Globally we have the same problem under VMWare, it's due to the CPU Time synchronisation.
In fact you need to set up your Guess parameters under Hyper-V to be sync with your Host CPU clock frequency.

Domain Controller time is incorrect


Tf-idf vectorizer has whitespaces in feature words with char_wb?

Question: I use
singleTFIDF = TfidfVectorizer(
    analyzer='char_wb',
    ngram_range=(4,6),
    stop_words=my_stop_words,
    max_features=50
).fit([text])

And wonder why there are whitespaces in my features like 'chaft '
How can I avoid this? Do I need to tokenize and preprocess this myself?
Answer: Use analyzer='word'.
When we use analyzer='char_wb', vectorizer pads the white space because it won't tokenize with respect to words; it tokenizes with respect to characters.
According to documentation for the analyzer argument:

analyzer{'word', 'char', 'char_wb'} or callable, default='word'
Whether the feature should be made of word or character n-grams. Option 'char_wb' creates character n-grams only from text inside word boundaries; n-grams at the edges of words are padded with space.

Look at the following example:
from sklearn.feature_extraction.text import TfidfVectorizer
corpus = [
    'This is the first document.',
    'This document is the second document.',
    'And this is the third one.',
    'Is this the first document?',
]
vectorizer = TfidfVectorizer(
  analyzer='char_wb',
  ngram_range= (4,6))
X = vectorizer.fit_transform(corpus)
print([(len(w),w) for w in vectorizer.get_feature_names()])

[(4, ' and'), (5, ' and '), (4, ' doc'), (5, ' docu'), (6, ' docum'),
(4, ' fir'), (5, ' firs'), (6, ' first'), (4, ' is '), (4, ' one'),
(5, ' one.'), (6, ' one. '), (4, ' sec'), (5, ' seco'), (6, ' secon'),
(4, ' the'), (5, ' the '), (4, ' thi'), (5, ' thir'), (6, ' third'),
(5, ' this'), (6, ' this '), (4, 'and '), (4, 'cond'), (5, 'cond '),
(4, 'cume'), (5, 'cumen'), (6, 'cument'), (4, 'docu'), (5, 'docum'),
(6, 'docume'), (4, 'econ'), (5, 'econd'), (6, 'econd '), (4, 'ent '),
(4, 'ent.'), (5, 'ent. '), (4, 'ent?'), (5, 'ent? '), (4, 'firs'), (5,
'first'), (6, 'first '), (4, 'hird'), (5, 'hird '), (4, 'his '), (4,
'ird '), (4, 'irst'), (5, 'irst '), (4, 'ment'), (5, 'ment '), (5,
'ment.'), (6, 'ment. '), (5, 'ment?'), (6, 'ment? '), (4, 'ne. '), (4,
'nt. '), (4, 'nt? '), (4, 'ocum'), (5, 'ocume'), (6, 'ocumen'), (4,
'ond '), (4, 'one.'), (5, 'one. '), (4, 'rst '), (4, 'seco'), (5,
'secon'), (6, 'second'), (4, 'the '), (4, 'thir'), (5, 'third'), (6,
'third '), (4, 'this'), (5, 'this '), (4, 'umen'), (5, 'ument'), (6,
'ument '), (6, 'ument.'), (6, 'ument?')]

Notice:

the output/features include ' this' (padded at the start by an extra space that is not there in the original text; the sentence starts with 'This')
the output/features include 'ment. ' (padded at the end by an extra space that is not there in the original text; the sentence ends with 'document.')
the output/features do not include 'is the', because that n-gram crosses a word boundary, but the 'char_wb' analyzer only creates n-grams "inside word boundaries"
Comment: Isee. But i want to use ngrams. I also don't know how the defaults for preprocessing like tokenization is for analyzer=char? I get also punctuation. Can I use a custom preprocessing with analyzer=char_wb?
Comment: I see. wouldn't it be tough for models to learn from char encoding? Can you add some context of the usage, in your question. we can still use the ngrams with word tokenizing. Ofcourse we can customize preprocessor and then use char_wb for tokenization
Comment: If we remove the space, it would loose the word ending. Good approach could be just remove the punctuations.
Comment: Thanks. I feel using ngrams you need to preprocess most on your won while with 'word' most of the things is done by default. What would be the right way to preprocess and usng char_wb afterwards? Shall I do this with a custom tokenizer or  within a custom preprocessing? I want to do stemming and need to remove the stop words by my own as with char_wb they are not removed by default!
Comment: Ok. But I think you can increase results when removing those "duplicates" with whitespace? Also, using ngrams(4,6) gets you a lot of similiar tokens like:[' inl', ' inla', ' inlan', ' vor', 'aft ', 'anwa', 'eis ', 'haft', 'haft ', 'inla', 'inlan', 'inland', 'land', 'nlan', 'nland', 'nwar', 'reis', 'reis ', 'rtsc', 'schaf']
Comment: Any comments @AI_Learning ?
Comment: Those are still different features according to the char ngram logic, since `haft` could a sub word and `haft ` could be a complete word


Parse HTML and Read HTML Table with Selenium Python

Question: I am converting some of my web-scraping code from R to Python (I can't get geckodriver to work with R, but it's working with Python). Anyways, I am trying to understand how to parse and read HTML tables with Python. Quick background, here is my code for R:
doc <- htmlParse(remDr$getPageSource()[[1]],ignoreBlanks=TRUE, replaceEntities = FALSE, trim=TRUE, encoding="UTF-8")

WebElem <- readHTMLTable(doc, stringsAsFactors = FALSE)[[7]]

I would parse the HTML page to the doc object. Then I would start with doc[[1]], and move through higher numbers until I saw the data I wanted. In this case I got to doc[[7]] and saw the data I wanted. I then would read that HTML table and assign it to the WebElem object. Eventually I would turn this into a dataframe and play with it.
So what I am doing in Python is this:
html = None
doc = None
html = driver.page_source
doc = BeautifulSoup(html)

Then I started to play with doc.get_text but I don't really know how to get just the data I want to see. The data I want to see is like a 10x10 matrix. When I used R, I would just use doc[[7]] and that matrix would almost be in a perfect structure for me to convert it to a dataframe. However, I just can't seem to do that with Python. Any advice would be much appreciated.
UPDATE:
I have been able to get the data I want using Python--I followed this blog for creating a dataframe with python: Python Web-Scraping. Here is the website that we are scraping in that blog: Most Popular Dog Breeds. In that blog post, you have to work your way through the elements, create a dict, loop through each row of the table and store the data in each column, and then you are able to create a dataframe.
With R, the only code I had to write was:
doc <- htmlParse(remDr$getPageSource()[[1]],ignoreBlanks=TRUE, replaceEntities = FALSE, trim=TRUE, encoding="UTF-8")
df <- as.data.frame(readHTMLTable(doc, stringsAsFactors = FALSE)
With just that, I have a pretty nice dataframe that I only need to adjust the column names and data types--it looks like this with just that code:
NULL.V1 NULL.V2 NULL.V3 NULL.V4
1                                   BREED    2015    2014    2013
2                   Retrievers (Labrador)       1       1       1
3                    German Shepherd Dogs       2       2       2
4                     Retrievers (Golden)       3       3       3
5                                Bulldogs       4       4       5
6                                 Beagles       5       5       4
7                         French Bulldogs       6       9      11
8                      Yorkshire Terriers       7       6       6
9                                 Poodles       8       7       8
10                            Rottweilers       9      10       9

Is there not something available in Python to make this a bit simpler, or is this just simpler in R because R is more built for dataframes(at least that's how it seems to me, but I could be wrong)?
Comment: most important advice - always add url to your data. Every page is different and we have to see HTML to give any advices.
Comment: Hi @furas, I would have added it but it's a private URL. I know this makes it difficult. Would it be helpful for me to create a similar matrix in my post?
Comment: I'll look for something similar on a public site and update my post tonight, thanks @furas
Comment: I haven't been able to do any comparisons to R because I can't get RSelenium to work now. Basically, what I have done to get the data I want is parse the column headers to a dict with blank values and then append the values with another parse. Then save it as a dataframe. It seems like with R I was able to just reference an html table location like I explained above and it was almost already in a dataframe format. I'll leave this question open and clarify/answer this question when I can get RSelenium to work again--when there is an update to RSelenium.
Comment: as I said before: add in question some example data/HTML (it not have to be link but simple HTML/text) which you want to parse. R and Pandas are not identical so it may need different solution, and every page is different so every page/example may need different solution. It doesn't matter how you do it in R, most important are data which you have - we have to see it.
Comment: I came across this blog which helped me out a bit: [link](https://chihacknight.org/blog/2014/11/26/an-intro-to-web-scraping-with-python.html). The html referenced at: [link](https://www.akc.org/reg/dogreg_stats.cfm) is similar to the html code I'm looking at. I followed the steps of the blog to create a dataframe. This is where I wish I had RSelenium running so that I could show the comparison.
Comment: @furas, I hope my updated question is helpful. If not, let me know what else I could do to make it better. Thanks.
Answer: Ok, after some hefty digging around I feel like I came to good solution--matching that of R. If you are looking at the HTML provided in the link above, Dog Breeds, and you have the web driver running for that link you can run the following code:
tbl = driver.find_element_by_xpath("//html/body/main/article/section[2]/div/article/table").get_attribute('outerHTML')
df  = pd.read_html(tbl)
Then you are looking a pretty nice dataframe after only a couple lines of code:
In [145]: df
Out[145]:
[                                  0     1     2       3
 0                             BREED  2015  2014  2013.0
 1             Retrievers (Labrador)     1     1     1.0
 2              German Shepherd Dogs     2     2     2.0
 3               Retrievers (Golden)     3     3     3.0
 4                          Bulldogs     4     4     5.0
 5                           Beagles     5     5     4.0
I feel like this is much easier than working through the tags, creating a dict, and looping through each row of data as the blog suggests. It might not be the most correct way of doing things, I'm new to Python, but it gets the job done quickly. I hope this helps out some fellow web-scrapers.
Comment: `import pandas as pd`
Answer: tbl = driver.find_element_by_xpath("//html/body/main/article/section[2]/div/article/table").get_attribute('outerHTML')
df  = pd.read_html(tbl)

it Worked pretty well.
Answer: First, read Selenium with Python, you will get basic idea of how Selenium work with Python.
Than, if you want to locate element in Python, there are tow ways:

Use Selenium API, you can refer Locating Elements
Use BeautifulSoup, there is nice Document you can read
BeautifulSoupDocumentation


Normal closure of a radical extension is radical

Question: I'm struggling to understand the proof that the normal closure of a radical extension of fields is also a radical extension, which is crucial since it allows us to work with radical and normal extensions (and thus, in characteristic 0, with radical Galois extensions).
The proof I'm reading is lemma 4.17 in Rotman's Advanced Modern Algebra, pp. 211-212, which I attach at the end of this message.
The definition Rotman uses is the following: an extension $F\subset F(u)$ is pure if there exists $m \geq 1$ such that $u^m\in F$. An extension $F\subset K$ is radical if there exists a tower (which I like to call radical tower) $$F=K_0\subset K_1\subset \dots \subset K_t=K$$ such that $K_i\subset K_{i+1}$ is pure for all $i$.
What I'm struggling to prove is: if $F\subset K$ is a radical extension, and $N$ is the normal closure of the extension, then $F\subset N$ is a radical extension.
Since I find Rotman's proof confusing (and not convincing), I have rewritten the proof. It might seem longer in appearance, but the first part of the proof (the one that troubles me) was unsatisfying. Let $m_{\alpha,F}$ denote the minimal polynomial for an element $\alpha$ over $F$.
What I ask is:

1) Is my rewriting of the proof correct?
2) Is this what's behind the argument of Rotman, or is there another, more simple way of reading it?

Rotman's proof seems shorter, but I don't understand when he says "it follows that $E=k(\sigma(u_1),\dots,\sigma(u_t):\sigma \in G)$": what are those $u_i$?
Here's my rewriting:
Let $F\subset K$ be a radical extension. There exist $u_1,\dots,u_t$ such that $$F\subset F(u_1)\subset F(u_1,u_2)\subset \dots \subset F(u_1,\dots,u_t) = K$$ is a radical tower. Let $E$ be the normal closure of $F\subset K$. I claim that$$E=F\left(\\{\sigma(u_i): \sigma \in \text{Gal}^E_F, i=1,\dots,t\\}\right)$$
Indeed, $$E=\text{Split}_F\left(m_{u_1,F} \dots m_{u_t,F}\right)=F(\{\text{roots of }m_{u_1,F} \dots m_{u_t,F}\})$$
Since the Galois group of a polynomial acts transitively on its roots, $\{\text{roots of }m_{u_i,F}\}=\{\sigma(u_i):\sigma \in \text{Gal}_F(m_{u_i,F})\}$. Let us see that is also equals $\{\sigma(u_i):\sigma \in \text{Gal}^E_F\}$.
$(\subset)$: We can extend every $\sigma\in \text{Gal}_F(m_{u_i,F})$ to $\tilde{\sigma}\in \text{Gal}_F^E$ by the theorem of extension of a polynomial to its splitting field, by taking the polynomial $m_{u_1,F} \dots m_{u_t,F}\in F[X]$.
$(\supset)$: If $\sigma\in \text{Gal}^E_F$, then $\sigma$ restricts to an $F$-isomorphism $F(u_i)\to F(\sigma(u_i))$, then (corollary 1.9 p.236 of Hungerford)  $u_i$ and $\sigma(u_i)$ must be roots of the same irreducible polynomial in $F[X]$. This proves that $\sigma(u_i)$ is a root of $m_{u_i,F}$.
Let $B_i=F\left(\{\sigma(u_j):1\leq j\leq i,\sigma \in\text{Gal}^E_F\}\right)$. What we just proved is that $E=B_t$. To see that $F\subset E= B_t$ es radical, we use induction on $t$, and this part of Rotman's proof is satisfying to me.
Below is Rotman's proof.
Comment: I think he should have said that $u_1, \ldots, u_t$ are elements of $B$ such that for each $i = 1, \ldots, t - 1$ some power of $u_{i + 1}$ is contained in $F(u_1, \ldots, u_i)$. Your proof looks good. I think you just needed to write out the details for yourself, which is good!
Comment: @Dylan: What puzzles me is that if all the details I wrote out are necessary, then I think the author should have been a bit more verbose on the proof...
Comment: I must say I'm a bit surprised by the lack of answers to this question. It shouldn't take too long to answer for somebody comfortable with Galois theory.
Comment: What would you like to see in such an answer? It looks like both you and Rotman have correct proofs, and for me it's hard to imagine a shorter argument!
Comment: The one problem I have with what Rotman is saying here (and I could be missing something) is that you might have repeated $p_i$ in part (i), e.g. for $\mathbf{Q}(\sqrt[4]{2}, i\sqrt[4]{2})$.
Answer: I think that both you and Rotman have the same argument in mind. Here's another way of looking at this.
Let $B$ be a finite extension of $k$, and let $\sigma_1, \ldots, \sigma_s$ be the distinct embeddings over $k$ of $B$ into an algebraic closure $B^a$ of $B$. I claim that a normal closure of $B/k$ is the compositum $E = (\sigma_1B) \cdots (\sigma_sB)$. If $B$ is given as $k(\alpha_1, \ldots, \alpha_n)$ then $\sigma_iB = k(\alpha_1^{\sigma_i}, \ldots, a_n^{\sigma_i})$, and we have rules like $k(\alpha)k(\beta) = k(\alpha, \beta)$. Each of the $\sigma_i$ will extend to an element of $\operatorname{Gal}(E/k)$, and your result follows.
Of course, you need to prove that $E$ really is normal over $k$, and minimal among such extensions containing $B$. But that's not too hard, and conceptually I think this is nice.