How to merge dataframe in delta table involving insert, update and delete?

Question: I would like to populate delta table that contains some columns and one column has used as partition and other is "primary key" (gene). So, Dependend on the data it record must be inserted, updated or deleted, like this:
Delta table:

disease
gene
value

colon cancer
abn1
0.12

breast cancer
agt2
0.02

colon cancer
zn1t
0.69

Dataframe table with values that must be insert into the delta table:

disease
gene
value

colon cancer
abn1
0.13

colon cancer
sad3
0.56

colon cancer
wasr
0.78

colon cancer
gfvc
0.21

breast cancer
qwa2
0.12

breast cancer
cv4s
0.21

breast cancer
asxz
0.34

Expected Delta table:

disease
gene
value
expected

colon cancer
abn1
0.13
update

colon cancer
sad3
0.56
insert

colon cancer
wasr
0.78
insert

colon cancer
gfvc
0.21
insert

colon cancer
zn1t
0.69
delete

breast cancer
qwa2
0.12
insert

breast cancer
cv4s
0.21
insert

breast cancer
asxz
0.34
insert

breast cancer
agt2
0.02
delete

Do you have an idea to do it?
I thought of using Merge command but I didn't to resolve the delete condition. Another solution is to delete the records before and then to apply merge for insert and update, but in this case, is it necessaty to apply them in the same transaction? Is there another solition?
Comment: Are you using Databricks or open source Delta Lake? Can you also describe a logic not only by data (for example, I don't see `breast cancer/agt2` in the resulting table, but I see `colon cancer/zn1t` two times)
Comment: Hi! I'm using spark and delta lake in my local machine. The example about the data was wrong. I updated the data. In your case, `breast cancer/agt2` must be deleted and `colon cancer/zn1t` is not duplicated.
Answer: This kind of functionality is supported with the new WHEN NOT MATCHED BY SOURCE clause in the MERGE statement (doc).  It was just released on Databricks as part of the Databricks Runtime 12.1 and is slashed for release in upcoming version of OSS Delta - 2.3.0 (see corresponding PR1, PR2).
If you can't wait for a new release, then you can proceed with using normal merge for existing values only (WHEN MATCHED without WHEN NOT MATCHED), and then do right join between table and incoming data, filter out not matched data, and perform delete operation.
Comment: Unfortunately, I can't wait for the new release. I implemented the second solution, Alex.
Thanks! It worked your solution, Alex!


How can I merge columns in UI-grid?

Question: Is there any way to merge the columns of UI-grid to be appear as continuous row (without any column line in between). I have tried this
merge columns in ui grid
but this causes me loss of row data at row number number 1. Even more I want every alternate row to be merged.

Here is my Html

Here is my js code for grid

$scope.gridOptions = {
    enableColumnResizing: true,
    enableRowHeaderSelection: false,
    enableGridMenu: true,
    enableHorizontalScrollbar: 0,
    enableVerticalScrollbar: 2,
    enableColumnMenus: false,
    enableRowSelection: true,
    columnDefs: [
   {
       name: 'Code',
       field: 'Code',
   }, {
       name: 'Title',
       field: 'Title',
   }, {
       name: 'Visits',
       field: 'Visit',
   }, {
       name: 'UsedVisits',
       field: 'usedVisits',
   }, {
       name: 'Pending Visits',
       field: 'pendingVisits',
   }, {
       name: 'Available Visits',
       field: 'availableVisits',
   }, {
       name: 'Start Date',
       field: 'StartDate',
   }, {
       name: 'End Date',
       field: 'EndDate',
   }, {
       name: 'Status',
       field: 'Status',
   }
    ]
};

Please suggest me something,
Thank you
Comment: Hi, sameer
Do you want to merge column or just you want column to be appeared as continous columns without borders ?
Comment: any of two will work but i want every alternate row to be merged
Comment: Can you explain it with example, what i got is first and second row should  come as one row and third and fourth row should come as second row ?
Comment: yeah, I added foreach there and calculated odd and even number of row, but this is not working.
Comment: http://plnkr.co/edit/?p=preview this is original link
Answer: To implement it we can merge data while creating array for grid itself
using logic
 originally we have array which we merge to show in grid so that in grid we can get merged data
  $scope.myData = [{name: "1Abcd", age: "one", gender:2},
               {name: "2Tom", age: "two", gender:1},
               {name: "3Abcd", age: "three", gender:2},
               {name: "4Abcd", age: "four", gender:2},
               {name: "5Abcd", age: "five", gender:2},
               {name: "6Abcd", age: "six", gender:2},
               {name: "7Abcd", age: "seven", gender:2},
               {name: "8Abcd", age: "eight", gender:2},
               {name: "9Abcd", age: "nine", gender:2},

              ];

$scope.myDataNew =[]     ;

for(var i=0;i<(($scope.myData.length/2)+1);i++){
var tempObj ={};
if($scope.myData[i*2] && $scope.myData[i*2].name && $scope.myData[i*2+1] &&$scope.myData[i*2+1].name){
 tempObj.name =$scope.myData[i*2].name+$scope.myData[i*2+1].name ;
 }
 else if($scope.myData[i*2] && $scope.myData[i*2].name &&    !$scope.myData[i*2+1] ){
tempObj.name =$scope.myData[i*2].name;
 }
if($scope.myData[i*2] && $scope.myData[i*2].age && $scope.myData[i*2+1]    &&$scope.myData[i*2+1].age){
tempObj.age =$scope.myData[i*2].age+$scope.myData[i*2+1].age ;
}else if($scope.myData[i*2] && $scope.myData[i*2].age &&    !$scope.myData[i*2+1] )
{
tempObj.age =$scope.myData[i*2].age;
}

$scope.myDataNew.push(tempObj);
}

here is code pen for completed implementation
http://codepen.io/vkvicky-vasudev/pen/LRPNyL
If ant change required feel free to inform me

How can I merge columns in UI-grid?


Number of connected components

Question: Given a graph $G$ of $N$ nodes and $E$ edges, we construct new graph $G^{'}$ with $N^2$ nodes of type $(a,b)$. There's an edge between $(a,b)$ and $(a^{'},b^{'})$ in $G'$ iff we have an edge from $a$ to $a^{'}$ and $b$ to $b^{'}$ in $G$ .
We need to find the number of connected components in $G'$.
My work:
We can remove the isloated vertices by counting their contribution to answer, which would be $N^2-(N-isolated)^2$.
Now, I don't know how to move ahead but the answer is based on the number of bipartite and non-bipartite components in $G$, which I am not able to think about.
Comment: Note, the product you are using here is that $G^\prime = G\times G$.
Answer: I finally understood how no of bipartite components(say, $bip$) and other components(say, $oth$) come into picture.
Consider a node $(b1,b2)$ in $G'$. Here $b1,b2$ represenet nodes from 2 bipartite components of $G$. It's beautiful to note that all $(white,white)$ and $(black,black)$ nodes form 1 connected component, and all $(white,black)$ and $(black,white)$ form other connected component in $G'$. Therefore, we get total $2*bip^2$ components in $G'$.
Consider a node of type $(bipartite,other)$ or $(other,bipartite)$ in $G'$. Now, nodes formed by their product form a single connected component in $G'$. So we get their contribution as $2*bip*oth$.
Finally consider node of type $(other,other)$. Their contribution will be $oth*oth$ on similar grounds.
So final answer is $N^2-(N-isolated)^2+2bip^2+2.bip.oth+oth^2$

Number of connected components


Create an order for a specific customer

Question: I'm new to commerce, but I can't find a way to generate an order for a already existing customer via Admin Panel. Do I have to code that by myself or am I missing something?
I've tried to use Commerce Admin Advanced Order Module but this only seems to work with drupal users, not commerce customers.
Comment: No, just select the relevant existing customer as the order owner when you create it (commerce customers _are_ Drupal users, no difference there; if you look at the [schema for customer profiles](http://drupalcontrib.org/api/drupal/contributions%21commerce%21modules%21customer%21commerce_customer.install/function/commerce_customer_schema/7) you'll see `uid` is used, which is the Drupal user id for the profile)
Comment: Do you have it set up to create a new account or so you allow anonymous checkout only. If the latter, your profiles probably all relate to the anonymous user (uid 0)
Comment: Then something went wrong with my import. Because my customers aren't Drupal users. Thanks for your help.
Comment: Where can I set up that a new account is created for every customer? I'm working with Commerce Feeds, but can't get it to creating drupal accounts next to customers.
Comment: Just a clarification on the customer profile thing. Customer profiles are *not* users, they belong to a user, and that uid property is reflecting that. A customer profile is assigned to an existing user and a user might have multiple profiles.
Comment: Now I begin to understand that connection. I thought users and customers where the same and thought something went wrong with my import. The customer-import is kind of useless then, cause I can't do anything with customers at all :( need to generate drupal-users first, right? Damn thing.
Answer: The simplest way to do this would be to create the order that you want until the step that you want with your admin/webmaster/whatever role that has enough permissions and then, edit the order and change the owner.
If you create an order so the customer can pay it, you just send them the checkout url, as you changed the owner, they will have access to finish the checkout.
If you process the payment as well, you need an extra step of configuration, in order to send the customer a proper notification that the order was made. Rules is a good way to do this.

Create an order for a specific customer


Beginning a repeat with a tied note in guitar pro 6

Question: I'm trying to tab out a song in guitar pro 6 and I have a section that repeats.  The section begins with a tied note from the previous measure, then when it repeats I want the last note of the last measure to be tied to the first note of the repeat.
The problem is when I tried this, the last chord does not get tied to the start of the repeat, it just plays it like an eighth note and then mutes the tied half after the repeat.  An image is shown below.

The note I am talking about is the last chord on the 7th fret.  When the repeat goes through, it is not cleanly tied to the first chord the second time around.  It just cuts out the (7) chord at the start and continues.
Is there a way to make this work?
Answer: Sorry, this is not possible.
It is a problem that I reported years ago and they should fix it in the next version. In the meantime, I don't see any workaround except adding a text note to inform the reader that it's tied, but GP won't play it tied...
Comment: I have to try it when I get home to double check, but I think I tried this in the new version (Guitar Pro 7) and the issue is still there...
Comment: Yes. Still there. 24 Oct 2021. V7.5
Comment: yes, still there :(
Comment: Still a bug/issue as of 5/2023. They should really fix this.
Comment: Years later in GP8 this is STILL an issue UGHHH


Do any undergraduate theory textbooks explain Gregorian chant notation?

Question: When it comes to common-practice notation, basically every college theory textbook explains all of the basics. But I don't know of any undergraduate theory textbook that includes a discussion of chant notation; are there any? And if so, what are they?
(I know this question is dangerously close to "requesting external resources," which is off-topic, but I think it's sufficiently separate, since I'm seeking a question with a clearly defined answer that does not require a link to said external resource.)
Comment: What sort of chant? I guess you mean Gregorian, not Anglican, which is usually written in conventional staff notation for the 4-part harmony - the only thing that needs any explanation is the "pointing" in the text showing how the words fit to the music, but that is almost self-evident to anyone who knows what a bar line is for!
Comment: @alephzero Yes, I meant Gregorian chant; silly omission on my part.
Answer: A fairly comprehensive tutorial (arranged in 45 "lessons" - don't be put off by the fact that at the start it also summarizes conventional staff notation) is
https://media.musicasacra.com/books/basicgregorianchant_1960.pdf.
Comment: It should be pointed out that this tutorial only covers later (and modern) Gregorian notation, with square notes and a four line staff.  The original notation, in Gregory's time and up until about the thirteenth century, was unlined neumes.


Fazer uma consulta SQL com Entity Framework 4

Question: Como faço pra realizar uma consulta no banco usando Entity Framework 4 passando uma string guardada previamente dentro de uma StringBuilder.
O motivo é que a string de consulta SQL é gigante. Sei que não é uma boa prática,mas por enquanto terei que fazer assim por falta de tempo hábil.
Essa é a string SQL da consulta:
StringBuilder strSql = new StringBuilder();
strSql.AppendLine(string.Format("SELECT * FROM (SELECT TOP intRestante * FROM (SELECT TOP {0}", intTop))[... Continua, a string é gigante];

Em WebForms eu faria algo assim:
objCommand = new SqlCommand();
objCommand.Connection = conn;
objCommand.CommandTimeout = 600;
objCommand.CommandText = strSql.ToString();
objCommand.Parameters.Add("@Parametros", SqlDbType.NVarChar, 100).Value = "%" + strParametros + "%";
SqlDataAdapter adp = new SqlDataAdapter(objCommand);
adp.Fill(dt);

Gostaria de saber como fazer exatamente a mesma coisa, porém em Entity Framework.
Comment: Coloque o exemplo e um trecho do código isso pode ajudar a solucionar seu problema!
Comment: Se a `string` é muito grande, o correto é fragmentar a consulta única em várias consultas.
Comment: @JuniorDias Bom, então coloque a `string` toda aqui. Dar pra fazer, até dá, mas é péssimo usar desta forma.
Comment: Cigano Morrison Mendez  Eu poderia fazer assim, mas a string já está pronta e "querem" que eu a use.
Comment: @CiganoMorrisonMendez Eu já consegui aqui, usei o ctx.Database.ExecuteSqlCommand

Muito obrigado!
Answer: Para Entity Framework execução de comandos com query (que retorna de dados) , você precisa ter alguns tipos de dados definidos para o mapeamento do resultado da consulta.
Se você quiser resultados un-typed, eu sugiro que você use SqlConnection + DbCommand para executar a consulta e analisar o resultado via DbReader objeto.
Fonte: http://forums.asp.net/post/5367669.aspx


Can 2^n be calculated in less than n-1 successive multiplications?

Question: I have a question which pertains to the possibility of calculating 2^n, given any n, in less than n-1 successive multiplications.
What could be the best strategy which I could utilize to achieve the same operation by avoiding the task of doing n-1 multiplications? Can this be done in lesser multiplications?
If yes, then how?
-Thanks
Comment: And what representation for the output? You can compute the binary representation of `2^n` without any multiplications :-)
Comment: related: [Addition-chain exponentiation](http://en.wikipedia.org/wiki/Addition-chain_exponentiation), online tool to calculate [Shortest Addition Chains](http://wwwhomes.uni-bielefeld.de/achim/addition_chain.html).
Comment: In what language? Most of the programming languages have a `power(x, n)` function.
Comment: the language is not a concern.
the entire point is to avoid the usage of the exponential operator in most languages. However, I am more of a perl person. C is also fine.
Answer: Yes 2^n can be computed in Log(n) multiplication, this is known as Exponentiation by squaring.
Answer: For (2^n) and (n>=0) you might use bitwise shifting: (2^n) is (1 << n)


How to set the font size for cell.textLabel globally ( for all the tableView cells )

Question: Is there a way to set the font size of cell's textLabel globally for all the TableView instead of setting it for every cell in the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method?
Answer: Instead of setting a cell.textLabel.font to a specific font, set it to a UIFont variable. You can then change the value of the variable (use the same font family but vary the size) and call -reloadData on the table view to force an update. I just tried this with a simple app to select the font size by selecting a row in a UI table view and it works a treat.
Comment: But that doesn't prevent what I want: avoid setting the cell size every time a cell is created. I want something I can call when I create the table view and remove the `cell.texlabel.font` code. Maybe just a dumb question.
Comment: Fair enough - I thought you were wanting for a way to change the font size as opposed to permanently setting it. In that case, I would definitely go with @jrturton's suggestion.
Answer: You could override UITableViewCell and set the font size in initWithStyle:reuseIdentifier, after calling the super version.


Renderização JSF

Question: Como faço para renderizar os componentes do Richfaces.
Tenho um combobox e quando eu clicar em um item dele quero que renderize o meu formulário de acordo com o meu item.
Exemplos por favor.
Comment: Olá johnatan, bem vindo ao Stack Overflow. Para que possamos auxiliá-lo por favor complete sua pergunta com mais detalhes. Um exemplo concreto e auto-contido com *snipets* de código relevantes da *view* e dos *managed beans* envolvidos é bem vindo. Da maneira que você formulou sua pergunta (que na verdade não é uma pergunta, é um pedido por exemplos) o contexto ficou muito amplo e é muito difícil elaborar uma resposta objetiva.
Comment: Coloque também o que você já tentou fazer, suas dificuldades e os resultados obtidos até então.
Answer: Para atualizar a tela parcialmente, isto é, apenas um trecho dela, após uma ação via Ajax você pode usar o atributo update caso tenha um botão. Veja a documentação do Richfaces sobre isso.
Exemplo:
<a4j:commandButton value="update" reRender="infoBlock"/>
...
<h:panelGrid id="infoBlock">
    ...
</h:panelGrid>

No caso de querer executar uma atualização após a seleção de um item da combo, isso é possível através da tag <a4j:ajax>. Veja um exemplo oficial:
<h:form>
    <h:selectOneMenu value="#{selectsBean.currentType}" valueChangeListener="#{selectsBean.valueChanged}">
        <f:selectItems value="#{selectsBean.firstList}" />
        <a4j:ajax event="valueChange" render="second" execute="@this" />
    </h:selectOneMenu>
    <a4j:outputPanel id="second" layout="block">
        <h:selectOneMenu value="#{selectsBean.currentType}" rendered="#{not empty selectsBean.currentType}">
            <f:selectItems value="#{selectsBean.secondList}" />
        </h:selectOneMenu>
    </a4j:outputPanel>
</h:form>

Renderização JSF


Best way to access models children in ember

Question: What is the best/right way to access a model's children in a route?
Route Code:
this.store.find('Parent', params.parent_id).then(function(parent){
   //this works
   var a = parent._data.children.length;
   //this doesn't but feels like it should?
   var a = parent.get('children').length;
})

Model:
App.Parent = DS.Model.extend({
    ...
    children: DS.hasMany('child', {async: true}),
});

Answer: var a = parent.get('children').length;

Is probably returning a promise. You can check this by doing a console.log('children', parent.get('children'). You can resolve this promise before checking the length by:
var a;
parent.get('children').then(function (children) {
  // Children promise has been resolved
  a = children.length;
});


cxf-codegen-plugin port to Gradle

Question: I'm trying to replicate what this plug-in does in Gradle. If I execute:
./wsdl2java -encoding UTF-8 -d /src/target/generated-sources/cxf -fe jaxws21
-sn UserSoapServicePorts -faultSerialVersionUID 1 -xjc-Xannotate
-p http:... -p urn:... -p urn:... -p urn:... -p urn:h... -p urn:...
-p urn:... -p urn:...
-verbose /src/xmlTemp/user-soap-v1.wsdl

...then I get:
an 22, 2016 3:51:05 PM org.apache.cxf.wsdl11.WSDLServiceBuilder checkForWrapped
INFO: Operation {urn:stuff:wsdl:person:v1}doSomething cannot be unwrapped, input message must reference global element declaration with same localname as operation

As far as I can tell, though the lines are identical. Any ideas what might be wrong?
Answer: This answer is similar to the approach from Stefan K but works with Java 10 and Gradle 4.6 and does approximately the same as the Maven plugin cxf-codegen-plugin.
This solution builds upon the Blog post Generated Files in Gradle from mooregreatsoftware.com from the year 2013. It differs because

it avoids a build script dependency on commons-io:commons-io by implementing a very simple TeeOutputStream inline in Groovy
it is altered to work with Java 9, 10 and potentially 11.

One of the main motivations is JEP 320: Remove the Java EE and CORBA Modules which is scheduled for Java 11. There are ways to make this work with Java 9 and Java 10 by using things like --add-modules java.se.ee but JEP 320 states:

Since standalone versions of the Java EE technologies are readily available from third-party sites, such as Maven Central, there is no     need for the Java SE Platform or the JDK to include them.

There are two code listings here, the first is a more compact code that does the work. The second code listing is the same code but with    annotations and commented out transitive dependencies which you might want to override.
Shorter Version
plugins {
  id 'java'
  id 'project-report'
}

repositories {
  jcenter()
}

sourceCompatibility = 10
targetCompatibility = 10

configurations {
  wsdl2java
}

dependencies {
  compile 'org.apache.cxf:cxf-rt-frontend-jaxws:3.2.2'
  compile 'org.apache.cxf:cxf-rt-transports-http:3.2.2'

  compile 'javax.xml.ws:jaxws-api:2.3.0'
  compile 'javax.jws:jsr181-api:1.0-MR1'
  compile 'javax.xml.bind:jaxb-api:2.3.0'
  compile 'javax.activation:javax.activation-api:1.2.0'
  compile 'javax.annotation:javax.annotation-api:1.3'

  wsdl2java 'javax.xml.bind:jaxb-api:2.3.0'
  wsdl2java 'com.sun.xml.bind:jaxb-ri:2.3.0'
  wsdl2java 'com.sun.xml.bind:jaxb-xjc:2.3.0'
  wsdl2java 'com.sun.xml.bind:jaxb-core:2.3.0'
  wsdl2java 'com.sun.xml.bind:jaxb-impl:2.3.0'

  wsdl2java 'javax.activation:javax.activation-api:1.2.0'
  wsdl2java 'javax.annotation:javax.annotation-api:1.3'
  wsdl2java 'javax.xml.ws:jaxws-api:2.3.0'
  wsdl2java 'javax.jws:jsr181-api:1.0-MR1'

  wsdl2java 'org.apache.cxf:cxf-tools-wsdlto-core:3.2.2'
  wsdl2java 'org.apache.cxf:cxf-tools-wsdlto-frontend-jaxws:3.2.2'
  wsdl2java 'org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb:3.2.2'
}

def wsdl2java = task generateJavaFromWsdl(type: JavaExec) {
  String wsdl = 'src/main/resources/some.wsdl'
  String genSrcDir = "${projectDir}/build/generated-sources/cxf-ws"

  inputs.file wsdl
  outputs.dir genSrcDir

  classpath configurations.wsdl2java
  main "org.apache.cxf.tools.wsdlto.WSDLToJava"

  args '-encoding', 'UTF-8', '-d', genSrcDir, wsdl

  OutputStream baos = new ByteArrayOutputStream()
  errorOutput = new OutputStream() {
    void write(int b) {System.err.write(b); baos.write(b) }
    void flush() { System.err.flush(); baos.flush() }
    void close() { System.err.close(); baos.close() }
  }

  doLast {
  def str = baos.toString()
  if (str.contains('Usage : wsdl2java') || str.contains('WSDLToJava Error')) {
  throw new TaskExecutionException(tasks[name],
  new IOException('Apache CXF WSDLToJava has failed. Please see System.err output.'))
  }
  }
}
compileJava.dependsOn += wsdl2java
sourceSets.main.java.srcDirs = ['src/main/java', 'build/generated-sources/cxf-ws']

Commented Version
plugins {
  id 'java'
  id 'project-report' // really useful to find out what gets pulled in transitively
}

repositories {
  jcenter()
}

// works with 1.8, 9, 10 and should be working with 11.
sourceCompatibility = 10
targetCompatibility = 10

configurations {
  wsdl2java
}

dependencies {
  compile 'org.apache.cxf:cxf-rt-frontend-jaxws:3.2.2'
  compile 'org.apache.cxf:cxf-rt-transports-http:3.2.2'

  compile 'javax.xml.ws:jaxws-api:2.3.0'
  compile 'javax.jws:jsr181-api:1.0-MR1'
  compile 'javax.xml.bind:jaxb-api:2.3.0'

  //
  // You might have these already imported due to other dependencies, but
  compile 'javax.activation:javax.activation-api:1.2.0'
  compile 'javax.annotation:javax.annotation-api:1.3'

  // ===== Apache CXF dependencies for the command line generation of java files
  //
  // http://openjdk.java.net/jeps/320
  // this JEP lists out exactly which dependencies are required to avoid using
  // deprecated Java EE modules.

  //
  // JAXB dependencies that Apache CXF cxf-tools-wsdlto-databinding-jaxb uses directly
  // we list them here all so we have a single version 2.3.0 among all of them
  wsdl2java 'javax.xml.bind:jaxb-api:2.3.0'
  wsdl2java 'com.sun.xml.bind:jaxb-ri:2.3.0'
  wsdl2java 'com.sun.xml.bind:jaxb-xjc:2.3.0'
  wsdl2java 'com.sun.xml.bind:jaxb-core:2.3.0'
  wsdl2java 'com.sun.xml.bind:jaxb-impl:2.3.0'

  //
  // Other stuff that Apache CXF assume to be available from the JDK
  wsdl2java 'javax.activation:javax.activation-api:1.2.0'
  wsdl2java 'javax.annotation:javax.annotation-api:1.3'
  wsdl2java 'javax.xml.ws:jaxws-api:2.3.0'
  wsdl2java 'javax.jws:jsr181-api:1.0-MR1'

  //
  // This is the big lazy solution and it puts the whole jaxws-ri stack on the classpath
  // As this is just the isolated classpath for wsdl2java you might not care.
  // This might be useful when you have missing dependencies with the above reduceded
  // list of dependencies. the Gradle plugin "project-report" has a task "projectReport"
  // that can really help
  //wsdl2java('com.sun.xml.ws:jaxws-ri:2.3.0') {
    //
    // this dependency is broken in 2.3.0. This articaft is simply not on mavenCentral
    // or jcenter. It looks like the correct one would be
    // 'org.eclipse.persistence:commonj.sdo:2.1.1' but we are not in the postion
    // to change this. As we are not interested in any JPA integration anyways we
    // just skip it for now.
    //exclude group: 'commonj.sdo', module: 'commonj.sdo'
  //}

  wsdl2java 'org.apache.cxf:cxf-tools-wsdlto-core:3.2.2'
  wsdl2java 'org.apache.cxf:cxf-tools-wsdlto-frontend-jaxws:3.2.2'
  wsdl2java 'org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb:3.2.2'
}

//
// there is no real Gradle plugin here, we rather use Gradle's build in task JavaExec
// which is the Gradle way to call an external java program.
def wsdl2java = task generateJavaFromWsdl(type: JavaExec) {
  String wsdl = 'src/main/resources/some.wsdl'
  String genSrcDir = "${projectDir}/build/generated-sources/cxf-ws"

  inputs.file wsdl
  outputs.dir genSrcDir

  classpath configurations.wsdl2java
  main "org.apache.cxf.tools.wsdlto.WSDLToJava"

  // you can add any of the Apache CXF command line parameters here
  // http://cxf.apache.org/docs/wsdl-to-java.html
  args '-encoding', 'UTF-8', '-d', genSrcDir, wsdl

  // you can set jvmArgs as well. F.i. proxy
  //jvmArgs "-Dhttp.proxyHost=10.10.10.10", "-Dhttp.proxyPort=8080"

  OutputStream baos = new ByteArrayOutputStream()
  errorOutput = new OutputStream() {
    // extrem simplified TeeOutputStream to avoid dependency on Apache commons-io
    void write(int b) {System.err.write(b); baos.write(b) }
    // no need to call flush and close on a ByteArrayOutputStream, but lets be safe
    void flush() { System.err.flush(); baos.flush() }
    void close() { System.err.close(); baos.close() }
  }

  // We inspect the collected logging an throw an TaskExecutionException if necessary.
  doLast {
    String str = baos.toString()
    if (str.contains('Usage : wsdl2java') || str.contains('WSDLToJava Error')) {
      throw new TaskExecutionException(tasks[name],
        new IOException('Apache CXF WSDLToJava has failed. Please see System.err output.'))
    }
  }
}
// we hook the custom task wsdl2java into the Gradle tasks graph / life cycle
compileJava.dependsOn += wsdl2java

// usually we want to access the generated code in the main source set and IDE's
sourceSets.main.java.srcDirs = ['src/main/java', 'build/generated-sources/cxf-ws']

Comment: Best solution, work in java 11 that all packages javax.xml is not present. Improve config of dependencies to generate wsdl client.
Answer: Use
buildscript {
    ext {
        xjcVersion= '3.0.5'
        jaxbOutputDir = "$buildDir/generated/cxf"
        jaxb2BasicsVersion = '0.11.0'
    }
}

configurations {
    cxf
}

apply plugin: 'java'
apply plugin: 'eclipse'

sourceSets {
    main {
         java {
          srcDirs += "$jaxbOutputDir"
         }
    }
}

task wsdl2java(type: JavaExec) {
    ext {
         outputDir = file("$jaxbOutputDir")
    }
    systemProperties  = ['javax.xml.accessExternalSchema': 'file' , 'file.encoding':'UTF8']
    outputs.upToDateWhen { false }
    outputs.dir outputDir
    main = 'org.apache.cxf.tools.wsdlto.WSDLToJava'
    classpath = project.configurations.cxf
    args '-d', outputDir
    args '-fe', 'jaxws21'
    args '-client'
    args '-verbose'
    args '-validate'
    args '-mark-generated'
//  args '-xjc-X'
    args '-xjc-Xfluent-api'
    args '-xjc-Xts'
    args '-xjc-XhashCode'
    args '-xjc-Xequals'
    args '-b',"$projectDir/src/main/resources/jaxws-custom-bindings.xjb"
    args "$projectDir/src/main/resources/wsdl/myWsdl.wsdl"
    doLast {
         println "----- cxf jaxb2 files generated -----"
    }
}

 dependencies {
    cxf "org.apache.cxf:cxf-tools-wsdlto-core:$cxfVersion"
    cxf "org.apache.cxf:cxf-tools-wsdlto-frontend-jaxws:$cxfVersion"
    cxf "org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb:$cxfVersion"

    cxf "org.jvnet.jaxb2_commons:jaxb2-fluent-api:3.0"
    cxf "org.apache.cxf.xjcplugins:cxf-xjc-ts:$xjcVersion"

    cxf "org.jvnet.jaxb2_commons:jaxb2-basics:$jaxb2BasicsVersion"

    compile "org.apache.cxf.xjc-utils:cxf-xjc-runtime:$xjcVersion"
    compile "org.jvnet.jaxb2_commons:jaxb2-basics-runtime:$jaxb2BasicsVersion"
    compile 'commons-lang:commons-lang:2.6'
 }

compileJava.dependsOn wsdl2java

have fun.

cxf-codegen-plugin port to Gradle


How do I practice to create a finer tone?

Question: When I sing my voice produce more air than tone, as a result it sounds husky. How do I practice to create a finer tone? Also my voice is very timid, how do I practice to make it sound bolder?
Comment: Hi, can you explain a bit further what you mean by "timid" ?
Comment: Check out this question: http://music.stackexchange.com/questions/17/improving-breath-support
Answer: Take lessons from a professional voice teacher. You need constant feedback from a professional who can evaluate what you are doing and show you how to gradually improve it. Learning to sing is not something you can do by reading descriptions on web sites or in printed books.
Answer: The answer to your questions is the same, and that is breathing and breath support.  As said by Wheat, you need constant feedback by a professional singer who can correct you and help you get the feeling, because that's what it is.


How do we type in Telugu in android? Is it supported?

Question: Can we have Telugu typing in android? If so, how?
Does android support Telugu fonts directly?
Or do we use bitmap fonts?
Answer: Try this.
Indic version of Samsung phone supports most Indian language.
Answer: You need to add custom font to include telgu font, see the following guide to add support for custom font in your application:
Add custom font for complete android application
Comment: yes, [related](http://stackoverflow.com/q/3932951/1089811)
Answer: One can easily type in Telugu using multiling app and its Telugu plugin.
It works in almost all applications. Prior to Jelly bean, Android did not support Telugu fonts.
But now, they do support it.


Really simple question about a specific Cauchy sequence in a generic normed space.

Question: Context. Let $X = (X,\|\cdot\|)$ be a normed space and $R:(X,\|\cdot\|) \longrightarrow (\Bbb K^n , \|\cdot\|_\infty)$ a linear and topological isomorphism between $X$ and $\Bbb K^n$ (here, $\Bbb K \in \{\Bbb R, \Bbb C\}).$
Question itself. Take any Cauchy sequence $(x_k)_{k \in \Bbb N} \subset X.$ Thus, by definition of Cauchy sequence,
$$ \forall \epsilon >0, \exists N = N(\epsilon) \in \Bbb N\, : \, \forall n,m \in \Bbb N, \, n,m > N \Rightarrow \| x_n - x_m \| < \epsilon. $$
Now, one easily notes that
$$ \| R(x_n) - R(x_m)\|_\infty = \| R(x_n-x_m)\|_\infty \leqslant \| R \| \, \|x_n-x_m\| < \|R\| \, \epsilon. \quad (n,m > N) $$
Note that I used linearity of $R$, aswell as the fact that $R$ is continuous and thus bounded. And here urges my question:
I certainly can't say that $\|R\|\epsilon < \epsilon$ because this inequality is valid only when $\|R\| < 1.$ Normally, what people do is to define initially $\|x_n-x_m\| < \frac{\epsilon}{\|R\|}$ but again, this doesn't makes sense in my head because $\epsilon < \frac{\epsilon}{\|R\|}$ isn't valid for all values of $\|R\|$ (I am pretty sure an operator can have a norm between $0$ and $1$).
At the same time, my intuition is that the sequence $(R(x_k))_{k \in \Bbb N}$ is also Cauchy (in $\Bbb K^n$) but I am having some troubles with this $\epsilon$ thing... Any help would be apreciatted.
Comment: The reason we can define $\|x_n-x_m\| < \frac{\varepsilon}{\|R\|}$ initially is because what we *want to prove* is $$\forall \varepsilon >0, \exists N = N(\varepsilon) \in \Bbb N\, : \, \forall n,m \in \Bbb N, \, n,m > N \Rightarrow \| R(x_n) - R(x_m) \| < \varepsilon$$ however we *use* the $N\left(\frac{\varepsilon}{\|R\|}\right)$ that'd correspond to $$\forall \delta >0, \exists N = N(\delta) \in \Bbb N\, : \, \forall n,m \in \Bbb N, \, n,m > N \Rightarrow \| x_n - x_m \| < \delta$$ (I purposefully changed the name of the variable, because it's a "silent" variable)
Comment: @BrunoB So it's just like a change of variable in the original definition ?
Comment: Yes. Basically, the fact the original definition (for $(x_n)_n$) is true for all $\varepsilon$ means we're not tied to a specific one: even when we choose the $\varepsilon$ for $(R(x_n))_n$, we can still freely pick any ""$\varepsilon$"" in the original criterion, we're not tied to ours. Using different letters at first like I did in my first comment can help with the intuition to be fair.
Comment: I mean, as is, your statement is true, there's no conflict I don't think.
Comment: @BrunoB Thanks for your help. What do you think about this "formal" formulation: Let $\epsilon > 0$ be arbitrary/given and consider $\delta = \frac{\epsilon}{\|R\|} > 0.$ Then, by definition of *Cauchy* sequence, we can say $$ \forall \delta >0, \exists N = N(\delta) \in \Bbb N\colon \forall n,m \in \Bbb N, n,m > N \Rightarrow \|x_n-x_m\| < \delta = \frac{\epsilon}{\|R\|}.  $$ Does this look ok and clear for the reader? My only concern here is the $\forall$ quantificator for $\delta$ in the *Cauchy* sequence definition.
Comment: What do you think about this? Let $\epsilon > 0$ be arbitrary and define $\delta := \frac{\epsilon}{\|R\|} > 0.$ Thus, by definition of *Cauchy* sequence (using the $\delta$ we just defined), $$ \exists N = N(\delta) \colon \forall n,m \in \Bbb N, n,m > N \Rightarrow \|x_n-x_m\| < \delta = \frac{\epsilon}{\|R\|}. $$
Comment: It's perfect I think!
Comment: @BrunoB Furthermore, imagine this process goes on and on: from the Cauchy sequence $R(x_k)_k$ I can say it is convergent in $\Bbb K^n$ and thus it converges to some $\alpha$. Since $R$ is surjective, for some $x \in X$, we have $R(x) = \alpha$. This leads to: $$ \|x_n - x \|  = \| R^{-1} Rx_n - R^{-1} \alpha \| \leqslant \| R^{-1}\| \, \| Rx_n - \alpha \|.   $$ Since $(Rx_k)$ converges to $\alpha$, If we take $n$ big enough, $$ \| x_n - x \| \leqslant \| R^{-1} \|\epsilon.$$ Is it okay to use the same $\epsilon$ here or does it conflict with the previous one?
Comment: You should remove the $\forall \delta$ and say beforehand that you "set $\delta := ...$ in the definition of $(x_n)_n$ being Cauchy" or something like that, otherwise it'll be good yeah!
Comment: Thank you! If you want to elaborate a quick answer below so I can mark it as accepted, It would be my pleasure!
Answer: (You should rename the dimension of your spaces to something that's not $n$, $m$ or something already taken, or change those to something different from the dimension, by the way.)
To sum up what's been discussed in the comments between OP and me, and so that it leaves the Unanswered category:
There seemed to be some confusion around the use of $\varepsilon$ both as the tool for the proof of $(R(x_n))_n$ being Cauchy (where it is fixed) and as the name of the variable for the definition of $(x_n)_n$ being Cauchy (where it is a "silent" variable). The critical point is that the latter can be given any value and name independent from the former's, it does not have to be our fixed $\varepsilon$, and this allows us to pick "$\varepsilon \leftarrow \displaystyle\frac{\varepsilon}{\|R\|}$".
A good idea at first, at least to make things clearer to the reader and/or yourself, is to begin the proof like this:
Let $(x_n)_n$ be a Cauchy sequence in $X$. We want to prove that $(R(x_n))_n$ is Cauchy in $\mathbb{K}^d$, that is:
$$\forall \varepsilon > 0,\,\exists N(\varepsilon) \in \Bbb N\, : \, \forall n,m \in \Bbb N, \, n,m > N(\varepsilon) \Rightarrow \| R(x_n) - R(x_m) \|_\infty < \varepsilon$$
Let $\varepsilon > 0$ be fixed. Since $(x_n)_n$ is Cauchy, we have:
$$\forall \delta >0,\, \exists M(\delta) \in \Bbb N\, : \, \forall n,m \in \Bbb N, \, n,m > M(\delta) \Rightarrow \| x_n - x_m \| < \delta$$
Define $N(\varepsilon) := M\left(\displaystyle\frac{\varepsilon}{\|R\|}\right)$, which is possible because $\frac{\varepsilon}{\|R\|} > 0$. [insert proof of the rest]
Hopefully that cleared any doubt around the $\varepsilon$s.


8-ball call shot rules when more than one ball is scored

Question: If a player intends to score more than one ball in a single shot does he/she need to call all the balls he/she wants to score or just one of them?
I.e. I want to score ball 1 and 2 on a single shot, do I need to say I want to score ball 1 on pocket A and ball 2 on pocket B, or can I just call one of them and score both on the same play?
Answer: In the World Pool-Billiard Association rules of 8-Ball, you only call one ball and one pocket on each shot.  As long as that ball falls into that pocket, your turn continues.  If it does not, your turn ends and your opponent takes over.  Any balls that fall into pockets on your shot stay in the pockets.
If you intend to pocket two balls in one shot, you only need to call one for your turn to continue.
Keep in mind that there are different rules used for different tournaments.
From WPA Rules of Play, General Rules, 1.6 Standard Call Shot:

1.6 Standard Call Shot
  In games in which the shooter is required to call shots, the intended ball and pocket must be indicated for each shot if they are not obvious. Details of the shot, such as cushions struck or other balls contacted or pocketed are irrelevant. Only one ball may be called on each shot.
  For a called shot to count, the referee must be satisfied that the intended shot was made, so if there is any chance of confusion, e.g. with bank, combination and similar shots, the shooter should indicate the ball and pocket. If the referee or opponent is unsure of the shot to be played, he may ask for a call.
  In call shot games, the shooter may choose to call "safety" instead of a ball and pocket, and then play passes to the opponent at the end of the shot. Whether balls are being spotted after safeties depends on the rules of the particular game.

From WPA Rules of Play, Eight Ball, 3.7 Spotting Balls:

3.7 Spotting Balls
  If the eight ball is pocketed or driven off the table on the break, it will be spotted or the balls will be re-racked. (See 3.3 Break Shot and 1.4 Spotting Balls.) No other object ball is ever spotted.


"This page was last modified on" code not displaying

Question: I added the following code to my node.topl.php but nothing is displaying on my site. What am I missing?
<?php
if ($submitted) {
  echo 'This page was last modified on ' . date( "F j, Y",$node->changed);
} ;
?>

Comment: I recommend using drupal's format_date() function instead of date().
Answer: Perhaps that content type has "submitted by" information hidden.
Try just:
print 'This page was last modified on ' . date('F j, Y', $node->changed);

And clear cache at Admin > Config > Performance
Comment: Thank you David.

I've cindluded the following code just before the closing header tag in my node.tpl.php file

I've also cleared the cache but am not seeing the last modified line on my site :(

changed);?>
Comment: Can you include your whole node.tpl.php file in your question?
Comment: Ooops. Including the same line after the article closing tag makes the line display. However, how would I go about displaying this in the footer of each page instead? Including the homepage. At the moment the last updated line is not displaying on the homepage ...
Comment: Sorry, it is now displaying, but how do I make it display in the footer instead?
Comment: Is there a way for me to "Blockify" it?
Answer: I have a slightly different approach on this. Edit the page.tpl.php and add this:
<?php if (isset($node->changed)): ?>

    <time datetime="<?php echo date('Y-m-d', $node->changed); ?>">Page Updated: <?php echo date('m-d-Y', $node->changed); ?></time>

<?php endif; ?>


Necessary conditions for a matrix to have orthonormal eigenvectors?

Question: A symmetric matrix has orthonormal eigenvectors and real eigenvalues. However, there are many kinds of matrices that have orthonormal eigenvectors and complex eigenvalues (for instance, circulant matrices). What are the necessary conditions for a matrix to have orthonormal eigenvectors?
Comment: The product of a matrix with its Hermitian transpose will have orthonormal eigenvectors. SVD ...
Answer: The necessary and sufficient condition for a matrix to have A COMPLETE SET of
 orthonormal eigenvectors is that it be normal. A matrix $M$ is normal if and only if
$$ MM^*=M^*M$$
For real valued matrices, symmetric and skew symmetric are some examples. Orthogonal matrices (thank you littleO for the correction) are another example.
Comment: @littleO You are correct, those are also examples. I thought I was covering all the real but was wrong.
Comment: @littleO Those are normal matrices. Oh you mean they are not symmetric...


Auto Scrolling in struts project on jsp

Question: i am using struts framework along with jquery and there is  button. On click of that button action to save data is called if data is valid else error in top div is shown. But the problem is that its not scrolling to show user error and i want it to scroll to show user the error message.
I know that it can be solved using href='#' but it is already being used to call the action.
Answer: Your question doesn't really make it clear whether this validation happens client-side or if you're talking 'bout a response from the server, and you haven't shown any code, so I'm not sure where exactly you need to put the following to fit your existing implementation, but anyway you can bring an element into view like this:
document.getElementById("idofyourdivhere").scrollIntoView(true);

The parameter true should align the element to the top of the scrolling area; if you pass false instead it should align with the bottom.
I don't know if there's a jQuery method to do the same thing, but of course you can select the div with jQuery (you might already be doing so to set the error message) and then call the non-jQuery function - the following uses jQuery to set the error message and unhide the div (obviously this assumes it was hidden initially) before bringing it into view the non-jQuery way:
var yourDiv = $("#idofyourdivhere");
yourDiv.html("Your error message here").show();

yourDiv[0].scrollIntoView(true);

Comment: Can i do like this           $('#yourdiv').show().scrollIntoView(true);
Comment: You should be able to do `$(#yourdiv").show()[0].scrollIntoView(true);` - those jQuery methods return a jQuery object which in turn contains the individual elements that matched the selector. In your case you know that the first (and only) matching element is the right one, so select that element using `[0]` and then you can use regular (non-jQuery) DOM methods on it.

Auto Scrolling in struts project on jsp


Find out total months from tenure which contains both years and month as string in python

Question: I have a list which contains tenure let me show you  -
['5 mos', '1 yr 8 mos', '9 mos', '11 mos', '1 yr 1 mo']

Basically these are the all over tenure and thrown it into a lists
what I need is basically from that lists is - 58, so total tenure is 58 in months
Any help will be appreciated
Comment: What have you tried so far? Does the list always only ever contain strings of the form 'yr', 'mos' and 'mo'?
Comment: Sir I am still trying, it might be a complex way to solve, i have created two empty list, i.e yr = [] and mo = [], now iterating over every item of main list, and then will check if 'yr' is present with any digit then append only that didgit in yr else append in mo.
Comment: For now i have received 'yr', 'mos', and 'mo' so far
Answer: This can be simplified by assuming that 'year' starts with 'y' and anything else must indicate months. Therefore:
list_ = ['5 mos', '1 yr 8 mos', '9 mos', '11 mos', '1 yr 1 mo']

months = 0

for s in list_:
    t = s.split()
    for a, b in zip(t[::2], t[1::2]):
        n = int(a)
        if b.startswith('y'):
            n *= 12
        months += n

print(months)

Output:
58

Comment: Thanks a lot sir @Lancelot du Lac, hats off to the logic, :)
Answer: Using regex:
import re

l = ['5 mos', '1 yr 8 mos', '9 mos', '11 mos', '1 yr 1 mo']
total = 0
for i in l:
    m = re.search(r'(\d+)\s?mo(?:s)?', i) ## find digits before mo/mos
    m = m.group(1) if m else 0            ## m=0 if no matches
    y = re.search(r'(\d+)\s?yr(?:s)?', i) ## find digits before yr/yrs
    y = y.group(1) if y else 0            ## y=0 if no matches
    total += (int(m)+12*int(y))
print(total)

Result:
58

Comment: Thanks @ytung-dev, this one is also helpful
Answer: You can try and parse your list and addup your total months on specific keywords such as mos and yr.
Break down each item of your list into a list containing key words and values.
Assuming the initial list is well formated :
list_ = ['5 mos', '1 yr 8 mos', '9 mos', '11 mos', '1 yr 1 mos']
total = 0
for item in list_:
    string = item.split(' ')
    for i in range (len(string)):
        if string[i] == 'mos':
            total += int(string[i-1])
        if string[i] == 'yr':
            total += 12*int(string[i-1])

print(total)
# 58


Extract all substrings in string

Question: I want to extract all substrings that begin with M and are terminated by a *
The string below as an example;
vec<-c("SHVANSGYMGMTPRLGLESLLE*A*MIRVASQ")

Would ideally return;
MGMTPRLGLESLLE
MTPRLGLESLLE

I have tried the code below;
regmatches(vec, gregexpr('(?<=M).*?(?=\\*)', vec, perl=T))[[1]]

but this drops the first M and only returns the first string rather than all substrings within.
"GMTPRLGLESLLE"

Comment: Maybe you expect `MGMTPRLGLESLLE`, `MTPRLGLESLLE` and `MIRVASQ`?
Comment: No because I want the string to be terminated by *
Answer: You can use
(?=(M[^*]*)\*)

See the regex demo. Details:

(?= - start of a positive lookahead that matches a location that is immediately followed with:
(M[^*]*) - Group 1: M, zero or more chars other than a * char
\* - a * char
) - end of the lookahead.

See the R demo:
library(stringr)
vec <- c("SHVANSGYMGMTPRLGLESLLE*A*MIRVASQ")
matches <- stringr::str_match_all(vec, "(?=(M[^*]*)\\*)")
unlist(lapply(matches, function(z) z[,2]))
## => [1] "MGMTPRLGLESLLE" "MTPRLGLESLLE"

If you prefer a base R solution:
vec <- c("SHVANSGYMGMTPRLGLESLLE*A*MIRVASQ")
matches <- regmatches(vec, gregexec("(?=(M[^*]*)\\*)", vec, perl=TRUE))
unlist(lapply(matches, tail, -1))
## => [1] "MGMTPRLGLESLLE" "MTPRLGLESLLE"

Answer: This could be done instead with a for loop on a char array converted from you string.
If you encounter a M you start concatenating chars to a new string until you encounter a *, when you do encounter a * you push the new string to an array of strings and start over from the first step until you reach the end of your loop.
It's not quite as interesting as using REGEX to do it, but it's failsafe.
Comment: The string is the product of a loop. It is actually a list of similar strings I planned on looping over.
Answer: It is not possible to use regular expressions here, because regular languages don't have memory states required for nested matches.
stringr::str_extract_all("abaca", "a[^a]*a") only gives you aba but not the sorrounding abaca.
The first M was dropped, because (?<=M) is a positive look behind which is by definition not part of the match, but just behind it.
Comment: To include the M.....    regmatches(vec, gregexpr('M(?<=.).*?(?=\\*)', vec, perl=T))[[1]]

Extract all substrings in string


Prove that the moment condition fails for AR(1) process with autocorrelated error

Question: Consider the simple time series model: $y_t=\rho y_{t-1} + \varepsilon_t$ where $\varepsilon_t$ is autocorrelated. This results in that the moment condition, $E[y_{t-1}\varepsilon_t]=0$, does not hold, i.e. that $E[y_{t-1}\varepsilon_t]\neq0$.
How would you show that the moment condition does not hold?
Comment: (1) your formatting has resulted in an unreadable formula.  Please fix it.  (2) What do you mean by "that result"?  The unreadable formula or that $e_t$ is autocorrelated?
Comment: @whuber, I was just about to post my answer to this question.
Answer: Consider the univariate AR(1) model where the error term also follows an AR(1) process:$y_{t}=\rho y_{t-1}+\varepsilon_{t}$
$\varepsilon_{t}=\phi\varepsilon_{t-1}+v_{t},\quad v_{t}\sim\mathcal{N}\left(0,\:\sigma^{2}\right)$
In this case both $\varepsilon_{t}$ and $y_{t-1}$ depend upon $\varepsilon_{t-1}$ such that the moment condition, $E\left[\varepsilon_{t}y_{t-1}\right]=0$, is violated. To see this write:
$E\left[\varepsilon_{t}y_{t-1}\right]=E\left[\left(\phi\varepsilon_{t-1}+v_{t}\right)\left(\rho y_{t-2}+\varepsilon_{t-1}\right)\right]$
$E\left[\varepsilon_{t}y_{t-1}\right]=\phi\rho E\left[\varepsilon_{t-1}y_{t-2}\right]+\phi E\left[\varepsilon_{t-1}\varepsilon_{t-1}\right]+\rho E\left[v_{t}y_{t-2}\right]+\phi E\left[v_{t}\varepsilon_{t}\right]$
$E\left[\varepsilon_{t}y_{t-1}\right]=\phi E\left[\varepsilon_{t-1}^{2}\right]>0$
It should be clear that since $E\left[\varepsilon_{t}y_{t-1}\right]\neq0$ the OLS estimator, $\hat{\rho}_{OLS}$, will not be consistent.


SQL Server Parameter Table Values inside SQL query

Question: I made a function that takes a varchar (IP address) and returns table values (city, country, time_zone...)
ALTER function [dbo].[GQuery2](@ipAddress varchar(16))
 returns @t table (
    [country_name] [nvarchar](64) ,
    [region_name] [nvarchar](128) ,
    [city_name] [nvarchar](128),
    [latitude] [float],
    [longitude] [float] ,
    [zip_code] [nvarchar](30) ,
    [time_zone] [nvarchar](8)
 )
 as
 begin
    insert into @t ([country_name]
      ,[region_name]
      ,[city_name]
      ,[latitude]
      ,[longitude]
      ,[zip_code]
      ,[time_zone])
 select  [country_name]
      ,[region_name]
      ,[city_name]
      ,[latitude]
      ,[longitude]
      ,[zip_code]
      ,[time_zone]
 from [pcap].[dbo].ip2loc
 where ip_from = (
        select max(ip_from)
            from [pcap].[dbo].ip2loc
            where ip_from <= [dbo].IP2INT(@ipAddress)
            )
 and ip_to = (
        select min(ip_to)
            from [pcap].[dbo].ip2loc
            where ip_to >= [dbo].IP2INT(@ipAddress)
                )
    RETURN
 end

The problem is I can only call the function in this format:
 SELECT * FROM [dbo].GQuery2('220.127.116.11')

and it returns a new table
country_name    region_name city_name   latitude    longitude   zip_code    time_zone
NETHERLANDS NOORD-HOLLAND   AMSTERDAM   52.37403    4.88969 1089    +02:00

And I want to make a query like this (theoretically)
UPDATE DimLocation d,  [dbo].GQuery2(d.ip) g
SET d.city_name = g.city_name, d.country_name = g.country_name ....

The DimLocation table has the schema:
IP, country_name, region_name, city_name, latitude, longitude, zip_code, time_zone

The IP address has a value and the other columns are NULL and i need to pass the IP address from DimLocation to the function GQuery2(ip) to get the missing data
The question is how to work with table-valued functions in select statements?
Answer: Try Following query:
Update DimLocation
Set City_Name = g.City_Name,
    Country_Name = g.Country_Name,
    ....
From dbo.GQuery2(DimLocation.IP) g

Comment: nothing
Update pcap.dbo.DimLocation
Set city_name = g.city_name From dbo.GQuery2(d.ip) g

:(
The multi-part identifier "d.ip" could not be bound.
Answer: Your function should contain IP field also to join the function with DimLocation table otherwise the query will update all the records in DimLocation table Or you have to update single record at a time (ie. Where DimLocation.IP='192.168.0.1'). But, It is better to do practice that retrieved records should have a field that you can match with the parent table which you want to update.
If you are adding the IP field in your function then the query should be written like this.
Update DimLocation Set DimLocation.City_Name = f.City_Name, DimLocation.Country_Name=f.Country_Name,..
From DimLocation Inner Join dbo.GQuery2(DimLocation.IP) f On DimLocation.IP=f.IP

Thus, you can update all values in the DimLocation table with your created function in a single query.


Why is my reference not being compiled in Xamarin Windows Universal PCL?

Question: I have a Xamarin PCL that works successfully with Android. I followed the instructions to add a Windows Universal Project to the Solution found here:
https://developer.xamarin.com/guides/cross-platform/xamarin-forms/windows/getting-started/universal/
But I am having issues running it.
When I build my project x86 I get the warning:
warning : Method 'project.ctor()' will always throw an exception due to the missing method 'ImageSource.FromResource(string)'. There may have been a missing assembly.

Then when I run the code I get exception
Additional information: Method 'ImageSource.FromResource(string)' was not included in compilation, but was referenced in SturgisMainPage..ctor(). There may have been a missing assembly.

When I build my project x64 I get the same build warning, but the exception is
An exception of type 'System.NotImplementedException' occurred in App1.Interop.dll but was not handled in user code

Additional information: Arg_NotImplementedException

How do I make sure to compile the reference. The only reference I have is to the NuGet Package in the instructions which is Xamarin.Forms.
Answer: On the add reference step, I added the Xamarin 2.0 Nuget Package to the Universal Project, but my Portable Class Library project was set to 1.0. I updated my Portable Class Library Xamarin Nuget Package to 2.0 and then it ran just dandy.


unable to concat the output for multiple rows

Question: I have a dataframe which is like below

If i write a code like below
df.iloc[0]

And if i write code like below
df.iloc[3]

I want to concat all the df.iloc[0], df.iloc1, df.iloc2 untill whatever the max rows are are present. But with the help of for loop i'm unable to. Can anyone help me with this?
Comment: Please explain what do you mean by "until the max rows"? you mean until the last row?
Answer: Use concat with comprehension:
df1 = pd.concat((df.loc[i] for i in df.index))

Or:
df1 = pd.concat((df.iloc[i] for i in range(len(df.index))))


Bash control flow skips to else no matter what

Question: I'm trying to write a small script to switch branches for me. I have only ever written in bash once long ago. In the following code, the ifs and elifs are skipped, and no matter what I input as $1, it always skips to the else. Ive looked at various examples and nothing is working, though it should be.
#!/bin/bash

if [ "$1 " == "-p" ]
    then
        cd ui;
        git checkout p_4.1;
        cd ../services;
        git checkout p_4.1;
        cd ../application;
        git checkout p_4.1;
        cd ..;
elif [ "$1 " == "-b" ]
    then
        cd ui;
        git checkout b_.1;
        cd ../services;
        git checkout b_.1;
        cd ../application;
        git checkout b_.1;
        cd ..;
elif [ "$1 " == "-g" ]
    then
        cd ui;
        git checkout g_.1;
        cd ../services;
        git checkout g_.1;
        cd ../application;
        git checkout g_.1;
        cd ..;
elif [ "$1 " == "-j" ]
    then
        cd ui;
        git checkout j_.1;
        cd ../services;
        git checkout j_.1;
        cd ../application;
        git checkout j_.1;
        cd ..;
else
    echo "No Command Known!"
 fi

I have absolutely no idea why it isn't working.
Comment: You might want to look at `case $1 in ...` or `getopt` or `getopts`
Answer: The spaces inside the double quotes are significant, and all "$1 " should be "$1" (no trailing space).
Answer: You seem to have a space after each $1. I believe that is your problem.


Como Criar Um Componente Reutilizável no Angular

Question: Estou com um sistema onde todos os módulos possuem uma tela de listagem de registros padronizada com paginação. Adaptei um código de paginação que achei na Internet para fazer paginação sob demanda. No entanto, ao invés de repetir esse código em todas as telas de listagem gostaria de criar um componente para apenas ser chamado nessas telas. Faço isso da seguinte maneira:
Serviço Adaptado que faz a paginação

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class PagerService {

  getPager(totalItems: number, currentPage: number = 0, pageSize: number = 10) {
    // calculate total pages
    let totalPages = Math.ceil(totalItems / pageSize);

    // ensure current page isn't out of range
    if (currentPage < 0) {
      currentPage = 0;
    } else if (currentPage > totalPages) {
      currentPage = totalPages;
    }

    let startPage: number, endPage: number;
    if (totalPages <= 10) {
      // less than 10 total pages so show all
      startPage = 1;
      endPage = totalPages;
    } else {
      // more than 10 total pages so calculate start and end pages
      if (currentPage <= 5) {
        startPage = 1;
        endPage = 10;
      } else if (currentPage + 3 >= totalPages) {
        startPage = totalPages - 9;
        endPage = totalPages;
      } else {
        startPage = currentPage - 4;
        endPage = currentPage + 3;
      }
    }

    // calculate start and end item indexes
    let startIndex = (currentPage) * pageSize;
    let endIndex = Math.min(startIndex + pageSize - 1, totalItems - 1);

    // create an array of pages to ng-repeat in the pager control
    let pages = Array.from(Array((endPage + 1) - startPage).keys()).map(i => startPage + i);

    // return object with all pager properties required by the view
    return {
      totalItems: totalItems,
      currentPage: currentPage,
      pageSize: pageSize,
      totalPages: totalPages,
      startPage: startPage,
      endPage: endPage,
      startIndex: startIndex,
      endIndex: endIndex,
      pages: pages
    };
  }
}

Componente de Listagem

import { AppSettings } from './../../settings/app-settings';
import { PageEquipamento } from './../entity/page-equipamento';
import { Component, OnInit } from '@angular/core';
import AppHelper from '../../helper/AppHelper';
import { LoadingHugeComponent } from '../../loading/huge/loading-huge.component';
import { Title } from '@angular/platform-browser';
import { SharedDataService } from '../../services/SharedDataService';
import { Router, ActivatedRoute } from '@angular/router';
import { EquipamentosService } from '../services/equipamentos.service';
import { ToastrService } from 'ngx-toastr';
import { environment } from '../../../environments/environment';
import { Equipamento } from '../../entity/equipamento';
import { PagerService } from '../../services/pager.service';
import { Observable, of } from 'rxjs';
declare var $: any;

@Component({
  selector: 'app-listar-equipamentos',
  templateUrl: './listar-equipamentos.component.html',
  styleUrls: ['./listar-equipamentos.component.css'],
  preserveWhitespaces: true
})
export class ListarEquipamentosComponent implements OnInit {

  //Rotas
  private appHelper: AppHelper = new AppHelper();
  public loadingHugeComponent = LoadingHugeComponent;
  public listUrls;
  //Equipamento Selecionado
  public indexEquipamentoSelecionado: number;
  public nomeSelecionado: string;
  //Paginação
  pager: any = {};
  pagedItems: any[];
  //Page Equipamentos
  private subPageEquipamento;
  public pageEquipamento: PageEquipamento = new PageEquipamento();

  constructor(private titleService: Title, private sharedDataService: SharedDataService,
    private router: Router,
    private route: ActivatedRoute,
    private equipamentosService: EquipamentosService,
    private toastrService: ToastrService,
    private pagerService: PagerService
  ) {
    const allowed = ['listarEquipamentos', 'gravarEquipamento'];
    this.listUrls = this.appHelper.urlNotAllowed(allowed, environment.urls);

  }

  ngOnInit() {
    this.loadRegistrosPaginados();
  }

  ngOnDestroy() {
    this.subPageEquipamento.unsubscribe();
  }

  confirmaExcluirEquipamento(i: number) {
    this.indexEquipamentoSelecionado = i;
    this.nomeSelecionado = this.pageEquipamento.listaEquipamentos[i].nome;
    $('#modalLista').modal('show');
  }

  excluirEquipamento() {
    setTimeout(() => {
      this.equipamentosService.excluirEquipamento(this.pageEquipamento.listaEquipamentos[this.indexEquipamentoSelecionado].id).subscribe(
        resp => {
          this.toastrService.info(this.pageEquipamento.listaEquipamentos[this.indexEquipamentoSelecionado].nome, ' Excluido com sucesso!');
          this.pageEquipamento.listaEquipamentos.splice(this.indexEquipamentoSelecionado, 1);
          this.loadRegistrosPaginados();
        }, error => {
          this.toastrService.error('Não foi possível excluir');
        }
      );
    }, 900);
  }

  //Carrega os registros paginados
  loadRegistrosPaginados() {
    this.subPageEquipamento = this.equipamentosService.getEquipamentosPage(AppSettings.RESGISTROS_POR_PAGINA)
      .subscribe(resp => {
        this.pageEquipamento.listaEquipamentos = resp.content;
        this.pageEquipamento.totalElements = resp.totalElements;
        //Gera o HTML da Paginação
        this.pager = this.pagerService.getPager(this.pageEquipamento.totalElements, 1, AppSettings.RESGISTROS_POR_PAGINA);
        this.pagedItems = this.pageEquipamento.listaEquipamentos.slice(this.pager.startIndex, this.pager.endIndex + 1);
      });
  }

  //Método chamado pela paginação
  setPage(page: number) {
    this.subPageEquipamento = this.equipamentosService.getEquipamentosPage(AppSettings.RESGISTROS_POR_PAGINA, page - 1)
      .subscribe(resp => {
        this.pageEquipamento.listaEquipamentos = resp.content;
        this.pageEquipamento.totalElements = resp.totalElements
      });

    this.pager = this.pagerService.getPager(this.pageEquipamento.totalElements, page, AppSettings.RESGISTROS_POR_PAGINA);
    this.pagedItems = this.pageEquipamento.listaEquipamentos.slice(this.pager.startIndex, this.pager.endIndex + 1);
  }

}

HTML da Paginação

{{item.name}}

            Primeiro

            {{page}}

            Último

Usando essa lógica é possível adaptá-la para criar um componente reutilizável para todas a telas de listagem do sistema?
Obrigado
Comment: é só vc adicionar a tag  onde vc quer utilizar esse seu componente
Comment: Você quer componentizar o `pager`  ?
Comment: O problema que estou tendo é com o subscribe dentro do método setPage(), pois quando esse método é chamado pelo HTML eu recarrego a lista de equipamentos (this.pageEquipamento.listaEquipamentos) se eu colocar esse método no componente separado não poderei recarregá-lo...
Comment: Se você quer uma tabela componentizada dá uma olhada nesse meu exemplo:
https://stackblitz.com/edit/tabela-html?file=src%2Fapp%2Fapp.component.html Criei uma tabela que dá pra ser reutilizada de uma maneira bem simples utilizando o ng-template e vc pode adaptar pra deixar com paginação e controle de exclusão de itens e tudo mais...
Answer: André, aconselho você a criar um módulo (shared) e dentro desse módulo você criar todos os componentes que serão compartilhados com todo ou a maioria do sistema, por exemplo, na minha aplicação utilizo o módulo shared pra compartilhar mensagens de validações de erro.
Funcionaria mais ou menos da seguinte forma:
módulo shared possui os componentes listar-registros e validar-formulario
Depois para chamar em outros componentes é só você utilizar o selector do seu componente listar-registros.
Obs: não esqueça de exportar o módulo e importar caso seja necessário!
Comment: Entendi, mas o problema que eu estou enfrentando é no método setPage do novo componente que vou criar. Por exemplo, eu iria criar o componente paginação dentro da pasta shared, ok. No html desse componente eu colocaria o HTML que postei acima, contudo ele iria chamar o método setPage(), só que como a paginação é sob demanda eu faço uma nova requisição dentro desse método e como a lista de equipamentos está em outro Component não seria possível carregá-lo... Queria ver se tinha como resolver isso...
Answer: Tem muitas formas de escrever, e talvez seja difícil. Primeiramente, vou mais lhe dar alguns lembretes gerais:

Um serviço é um container de estado. Ele só possui dados e não possui nenhum template;
Um componente é um container de estado + um template html. Sendo que esse container de estado pode ser delegado a um serviço (quando o template acessa a variáveis do serviço);
O que torna um serviço especial é o seu comportamento de injeção de dependência; Um serviço tem o seu ciclo de vida controlado por onde você o coloca como "provider" (ler a seção de injeção de dependências da documentação).
O "providedIn: 'root'" injeta o serviço automaticamente como singleton (variavel global). Experimente tirar esse linha da anotação do serviço, vai dar erro. O erro só será solicionado quando você injetar o servico como "provider" em outro componente ou módulo. Ou seja: um serviço não é necessariamente um singleton, ele pode ser acoplado a qualquer coisa.

Se você colocar um serviço no providers de um componente ele é criado e destruído com esse componente. A mesma coisa se colocar no providers de um module. E também há o viewProviders, que torna o serviço disponível também pra todos os componentes filho.
Ok entendendo de como funciona a injeção de dependência, vamos ao seu componente:

Pense no seu componente como uma caixa preta. A responsabilidade dele é fazer paginação de QUALQUER COISA. Ou seja, regra número 1 é que ele não pode ter nenhuma regra de negócio específica da sua aplicação.
Pergunte até onde vai a responsabilidade do seu "componente" (não o componente angular, a "coisa" que você quiser criar). Você pode decidir, por exemplo, que seu "componente" não deve se preocupar com gerar HTML e CSS, mas seu consumidor é que deve cuidar disso. Responsabilidades maiores trazem menos flexibilidade, mas mais facilidade de uso. Responsabilidades menores trazem mais flexiblidade, mas menos coisa pronta.
Se o seu componente não for gerar html e CSS, ele pode ser um serviço que expõe variáveis e funções úteis pra um consumidor então os usarem em um componente. Exemplo: export: "página Atual", "próximaPágina()", "irParaPágina()". E o consumidor que decide se o coloca em um botão ou qualquer outra coisa.
No outro caso, ao criar componentes, o uso de @Input e @Output são chaves importantes pra desacoplamento. Por exemplo, você pode escrever um componente de paginação que não tem a responsabilidade de espeficificar COMO a página será atualizada. Este componente pode emitir um @Output quando se clica em um botão, daí o componente pai é que vai decidir o que fazer com esse evento. Desta forma, seu componente de paginação fica mais genérico, obedecendo melhor ao princípio de responsabilidade única.
Ambos o uso de Providers, Output ou Input remetem ao mesmo problema: Em qual componente devo guardar meu estado? Em qual componente deve ficar qual variável? No pai? No filho? Este é um problema essencial de todas as 3 frameworks famosas do momento. Aprendendo isso no Angular, vc de quebra aprende coisas importantes pra usar qualquer outra framework.


Spring Boot + Gradle - where to put environment configuration?

Question: I was working on a simple application in Spring Boot. It was developed locally (and it works) with:

Gradle,
H2 database with connection properties set in application.properties placed on project's root
Maven folders structure (src/main/groovy, src/main/resources, etc.)

Now it's the time when I'd like to deploy it to the Openshift, so I need to create an additional, production configuration with a MySQL settings, but I don't know where to put it and how to use it.
So my questions are:

What should I do to have two different configurations (development and production)?
Where to put the configuration files?
Do I have to change something in the build.gradle?
How to build the app with a development or production config?
How to run the app with a development or production config?
What are the best practices for creating multiple environment configurations?

I'm rather a frontend dev and all these backend stuff are not obvious for me, so please consider it in your answers.
This is the content of my current build.gradle
plugins {
    id 'org.springframework.boot' version '1.5.3.RELEASE'
    id 'java'
    id 'groovy'
}

jar {
    baseName = 'myproject'
    version =  '0.0.1-SNAPSHOT'
}

repositories {
    jcenter()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile("org.springframework.boot:spring-boot-starter-test")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile 'mysql:mysql-connector-java'
    compile("com.h2database:h2")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile('io.jsonwebtoken:jjwt:0.7.0')
    compile localGroovy()
}

Answer:
What should I do to have two different configurations (development and production)?

In your case, you can use a profiles to achieve it. You can read about it here. For each profile you can have specific application properties file (named application-%PROFILE_NAME%.properties, like application-prod.properties, the same is true for .yml configuration files) And you have to specify what profile yo use then you are starting your app via command line switch for example like so:
--spring.profiles.active=prod

Where to put the configuration files?

Just in the same place as your application.properties file.

Do I have to change something in the build.gradle?

No, you don't need to modify your build script. Since all specific configurations are needed for running your application, not for building.

How to build the app with a development or production config?

You don't need to build it with some specific configuration, just run it with it.

How to run the app with a development or production config?

As it was said earlier - just  specify what profile to use when starting the application.

What are the best practices for creating multiple environment configurations?

As for me, if you use a spring - to use profiles and profile specific configuration and bean-definitions.
Comment: You helped me a lot !
Answer: Create a separate application-dev.properties along side your existing application.properties files as outlined here to contain your h2 config https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-profile-specific-properties and then activate this when running in dev by passing in the following argument when starting the app --spring.profiles.active=dev you could do the same for production i.e. application-prod.properties and keep the common configuration in application.properties.
Comment: Where to put these config files?On project's root? Will they be included in the generated war?
Comment: Put them in `src/main/resources` then they will be included in the generated war / jar. If this is not what you want you can load a file from outside the artifact by setting spring.config.location.


issues in creating 301 redirects in Apache 2.4.3x using htaccess

Question: I have recently upgraded my website from http to https protocol.
I have added the following code to my .htaccess file to redirect all http traffic to https on my website.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Now when i search for articles on my website using google (which were previously indexed by google when the site was using http protocol.) and click on the search results it is redirected to  https://www.example.com.
For eg :
if i click on the http://www.example.com/my-article-1 (or type it in browser bar) it would redirect to https://www.example.com.
I would want to redirect all those http links to https
For eg :
if i click on the http://www.example.com/my-article-1 it should go to https://www.example.com/my-article-1
I tried creating 301 redirects in the .htaccess file
redirect  /my-article-1 https://www.example.com/my-article-1

I didnt work.The above code was added right below the first code in this question
How do i create a proper 301 redirect for all my webpages ?
I am using Linux hosting with Apache 2.4.33 and a Drupal 7 CMS running the website.
I have clean URLS Enabled in my Drupal CMS
I found out about an article in Drupal org about putting clean URLs and tried the following combinations
# Various rewrite rules.

<IfModule mod_rewrite.c>

   RewriteEngine on

 # Added by Me

 RewriteBase /

 #RewriteRule  ^/(.*)$ https://www.domain.in/serial-programming-tutorials  [R=301,L]

 #Above statement redirects to https://www.domain.in/

 #RewriteRule  ^serial-programming-tutorials$ https://www.domain.in/serial-programming-tutorials  [R=301,L]

 #Above statement gives "The page isn't redirecting properly" Error in Browser

 #RewriteRule  ^/serial-programming-tutorials$ https://www.domain.in/serial-programming-tutorials  [R=301,L]

 #Above statement redirects to https://www.domain.in/

Below is my .htaccess file.
#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\.(?!well-known).*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock))$|^#.*#$|\.php(~|\.sw[op]|\.bak|\.orig\.save)$">
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
  <IfModule !mod_authz_core.c>
    Order allow,deny
  </IfModule>
</FilesMatch>

# Don't show directory listings for URLs which map to a directory.
Options -Indexes

# Follow symbolic links in this directory.
Options +FollowSymLinks

# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php index.html index.htm

# Override PHP settings that cannot be changed at runtime. See
# sites/default/default.settings.php and drupal_environment_initialize() in
# includes/bootstrap.inc for settings that can be changed at runtime.

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
  php_flag magic_quotes_gpc                 off
  php_flag magic_quotes_sybase              off
  php_flag register_globals                 off
  php_flag session.auto_start               off
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_flag mbstring.encoding_translation    off
</IfModule>

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  <FilesMatch \.php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  </FilesMatch>
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # Added by Me

  RewriteBase /
  #RewriteRule  ^/(.*)$ https://www.domain.in/serial-programming-tutorials  [R=301,L]
  #Above statement redirects to https://www.xanthium.in/

  #RewriteRule  ^serial-programming-tutorials$ https://www.domain.in/serial-programming-tutorials  [R=301,L]
  #Above statement gives "The page isn't redirecting properly" Error in Browser

  #RewriteRule  ^/serial-programming-tutorials$ https://www.domain.in/serial-programming-tutorials  [R=301,L]
  #Above statement redirects to https://www.domain.in/

  # Set "protossl" to "s" if we were accessed via https://.  This is used later
  # if you enable "www." stripping or enforcement, in order to ensure that
  # you don't bounce between http and https.
  RewriteRule ^ - [E=protossl]
  RewriteCond %{HTTPS} on
  RewriteRule ^ - [E=protossl:s]

  # Make sure Authorization HTTP header is available to PHP
  # even when running as CGI or FastCGI.
  RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

  # Block access to "hidden" directories whose names begin with a period. This
  # includes directories used by version control systems such as Subversion or
  # Git to store control files. Files whose names begin with a period, as well
  # as the control files used by CVS, are protected by the FilesMatch directive
  # above.
  #
  # NOTE: This only works when mod_rewrite is loaded. Without mod_rewrite, it is
  # not possible to block access to entire directories from .htaccess, because
  # <DirectoryMatch> is not allowed here.
  #
  # If you do not have mod_rewrite installed, you should remove these
  # directories from your webroot or otherwise protect them from being
  # downloaded.
  RewriteRule "/\.|^\.(?!well-known/)" - [F]

  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  # uncomment the following:
  # RewriteCond %{HTTP_HOST} .
  # RewriteCond %{HTTP_HOST} !^www\. [NC]
  # RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  #
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  # uncomment the following:
  # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  # RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  # RewriteBase /

  # Pass all requests not referring directly to files in the filesystem to
  # index.php. Clean URLs are handled in drupal_environment_initialize().
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ index.php [L]

  # Rules to correctly serve gzip compressed CSS and JS files.
  # Requires both mod_rewrite and mod_headers to be enabled.
  <IfModule mod_headers.c>
    # Serve gzip compressed CSS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

    # Serve gzip compressed JS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

    # Serve correct content types, and prevent mod_deflate double gzip.
    RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
    RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]

    <FilesMatch "(\.js\.gz|\.css\.gz)$">
      # Serve correct encoding type.
      Header set Content-Encoding gzip
      # Force proxies to cache gzipped & non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
  </IfModule>
</IfModule>

# Add headers to all responses.
<IfModule mod_headers.c>
  # Disable content sniffing, since it's an attack vector.
  Header always set X-Content-Type-Options nosniff
</IfModule>

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domain.in/$1 [R=301,L]

Comment: The first rule you posted should already do what you require, so you may have a conflict with other directives. Please posted your entire `.htaccess` file. (Incidentally, the second rule you posted is a 302 redirect, not a 301. But you should always _test_ with 302s anyway to avoid caching issues.)
Comment: @MrWhite I have made a few changes and posted the .htaccess file
Answer: You have put the HTTP to HTTPS redirect in the wrong place. It needs to go at the top of your .htaccess file, not at the end.
By placing it at the end, the Drupal "front-controller" has already rewritten the request to index.php. The later HTTP to HTTPS redirect then converts this to an external redirect (in the next round of processing) and essentially redirects everything to the document root.
The order of (mod_rewrite) directives in .htaccess is important.
Comment: Thank You for your help ,It is now working perfectly.
Answer: The order of how the statements are posted is important to the functioning of the .htaccess file as pointed out by @MrWhite.
I have changed my htaccess file as shown below to solve the problem.
# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  #------------------------------------------------------------------#
  # Added by to redirect all http to https
  # Placing it here solved my problem
  #------------------------------------------------------------------#
      RewriteEngine On
      RewriteCond %{SERVER_PORT} 80
      RewriteRule ^(.*)$ https://www.domain.in/$1 [R=301,L]
  #-------------------------------------------------------------------#

  # Set "protossl" to "s" if we were accessed via https://.  This is used later
  # if you enable "www." stripping or enforcement, in order to ensure that
  # you don't bounce between http and https.
  RewriteRule ^ - [E=protossl]
  RewriteCond %{HTTPS} on
  RewriteRule ^ - [E=protossl:s]

 # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  # uncomment the following:
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Placing the below statement just below IfModule mod_rewrite.c (in .htaccess file)as shown solved all my problems
<IfModule mod_rewrite.c>
      RewriteEngine on

      #------------------------------------------------------------------#
      # Added by to redirect all http to https
      # Placing it here solved my problem
      #------------------------------------------------------------------#
          RewriteEngine On
          RewriteCond %{SERVER_PORT} 80
          RewriteRule ^(.*)$ https://www.domain.in/$1 [R=301,L]
      #-------------------------------------------------------------------#

Now
http://www.domain.in redirects to https://www.domain.in
and
http://www.domain.in/tutorial-1 redirects to https://www.domain.in/tutorial-1


How to filter in OData for a specific value inside

Question: In our Cosmos database, we have an attribute for a document that is an array of objects. The objects in this array have two attributes, Key and Value. So it's "a bit like" a IDictionary<string, string>.
Here is some example data:
{
  // other attributes
  // .....
  "Tags": [
    {
      "Key": "client",
      "Value": "Evil Corporation"
    },
    {
      "Key": "level1",
      "Value": "EUROPE"
    },
    {
      "Key": "level2",
      "Value": "UNITED KINGDOM"
    }
  ]
}

However, there are also objects in the database where level2, for example, does not exist, resulting in JSON like this:
{
  "Tags": [
    {
      "Key": "client",
      "Value": "Evil Corporation"
    },
    {
      "Key": "level1",
      "Value": "EUROPE"
    }
  ]
}

A user is able to select level2 filters through the UI so the application makes sure they are included. The user can also select filters and mark them as excluded, i.e. that he wants every result where a specific country is not present.
At first I created the following query in order to get all for a specific country:
&$filter=Tags/Any (c:c/Key eq 'client' and c/Value eq 'Evil Corporation') and (Tags/Any (c:c/Key eq 'level2' and c/Value eq 'UNITED KINGDOM')

I am having trouble with the query where I select every item where a specific country does not exist. I tried:
&$filter=Tags/Any (c:c/Key eq 'client' and c/Value eq 'Nestlé') and (Tags/Any (c:c/Key eq 'level2' and c/Value ne 'UNITED KINGDOM')

This now returns every item where level2 is not UNITED KINGDOM, however if a document does not have level2 configured at all, such as when there is no object with key=level2 in the document, then it's not returned.
So, basically, I need this query:
(Tags/Any (c:c/Key eq 'level2' and c/Value ne 'UNITED KINGDOM')` and combine it somehow with `OR Tags/Any (c:c/Key {IS NOT PRESENT}

and this is where I am stuck.
I don't know how to write this into ODATA. When I searched Google for a non-existent column and ODATA it only returns results for people having issues with ODATA not returning a specific column, but that's exactly what I want to do.
I tried to write this query:
and (Tags/Any (c:c/Key eq 'level2' and c/Value ne 'UNITED KINGDOM') or Tags/All (c:c/Key eq 'level2' and c/Value ne 'UNITED KINGDOM'))

which I got from https://stackoverflow.com/a/57405406/2823419
but it returns an error that it can't parse the query.
What function do I need to use?
Comment: Why are you doing this by hand instead of using eg EF Core's Cosmos provider? OData isn't SQL, nor a remote database access API. Some queries are impossible with OData while others are too hard to write
Comment: @PanagiotisKanavos Because I told my Product Owners that a specific feature they want will take some more time and extra effort because it's more complex than they think and then when I went on vacation they just implemented with outsourced colleagues in a hacky way. And surprise surprise, this hacky way now leads to a bug on production. And refactoring the whole feature will take too long and I need to quick fix this. Alternatively, I can omit this query and filter in the frontend, but I wanted to try to solve it through ODATA first. Is this not possible?
Comment: On the other hand, the document schema isn't optimal. A JSON object is already a dictionary, there's no need to have `Key` and `Value` tags. It looks like you tried to replicate an Entity-Attribute-Value schema in a document database, which simply doesn't need it. The whole point of a document DB like Cosmos is that you can write `{ 'client' : 'Evil Corporation', 'level1' : 'Europe'}`. Those levels are weird too. Nothing prevents you from nesting objects in JSON
Comment: @PanagiotisKanavos This is true, I also don't like how these tags are stored in our application, but this is also sth. that cannot be changed quickly now. Gladly this is a microservice and in our other microservices we have a different structure for these "tags", but this is what we are given at the moment.
Comment: Then your query can't be written quickly either. The schema is *very* wrong, so writing any kind of query for this will be very difficult. You're trying to use OData, an API level protocol that works on **entities**, to reconstitute those entities from attribute/value pairs. That's the job of the controller or query resolver *behind* an OData API.
Comment: Was this data migrated from a relational database using the EAV *anti*pattern to emulate document storage? That was a bad design from the start, and completely inappropriate now. You have a document database now, there's no restriction on how many attributes an object can have. As for a *hierarchy* of objects, which here is represented by `level1` etc, you can simply nest the objects
Comment: `Because I told my Product Owners that a specific feature they want will take some more time and extra effort because it's more complex than they think and then` no, it's because the data is wrong and what they ask *will cost them enormously in Cosmos bills*. This schema takes a lot more space and the overly complex queries it needs will eat up a lot of CPU. All of those will be charged against the product owner's budget. Is the PO ready to admit responsibility for the huge bill? Will *they* request the budget for more RUs to process the same traffic?
Comment: I have no knowledge why this data is written in this way or if it was in a different way before then. It was done by a freelancer which I was hired to supersede. According to my boss he wanted to try out cosmos db and went for it. However, I dont think the problem lies with the database system but more with the structure of the data.
Comment: Yeah, nesting also doesn't work in this case, when you select multiple countries you also have, right now, multiple `level2` filters in the document. It can be heavily improved.
Comment: So we have a small dataset only at the moment, so it shouldnt be too expensive at the moment. The API call returns like 20 items at max at the moment. I would maybe then add the filtering in the frontend as a quick fix and then refactor the schema and the implementation for the long run, so we can use it on production and implement it correctly while production works.
Comment: Instead of `heavily improved` say `the bill can be heavily reduced`. On the cloud, mistakes have a direct impact on the monthly bill and Cosmos is *not* cheap. That's far easier to explain to POs. `we can use it on production and implement it correctly while production works.` unfortunately, this will take longer than simply using the correct design. Querying an EAV table is really hard on a database using SQL and JOINs. In this case you're trying to perform that JOIN with OData. How much will *your* wasted time cost?
Comment: In any case, even just for experimentation, try using the EF Core provider, make the query you want and inspect the HTTP call it sends to Cosmos using eg Fiddler. I think EF Core 6 can also log the HTTP query itself. A `not exists` like that will be very difficult to pull off though. Every query will be as hard to write as this one
Comment: First of all, thanks for the extensive answers! I might have miscommunicated a bit, but solving it in the frontend should be fairly easy. We would send the ODATA query without the `level2` filters, so it's always getting for all countries. And then based on the filter selection in the frontend, we would filter the API response. Of course this leads to more data in the response and more response time etc. but this fix would be implemented in 2 hours. Then, while production works as expected, we can fix the design which will take 1 sprint.
Comment: We havent used EF Core in this project, because it has (had) some limitations with Cosmos DB that we required. https://learn.microsoft.com/de-de/ef/core/providers/cosmos/limitations

However, I can see that this list has been reduced, so we might be able to reevaluate this.
Comment: But still, the problem is, that this special `except this filter` is hacked in the frontend right now. THe backend does'nt even know that this functionality exists, because of the hacky way it was implemented. So we would need to open up some things there.
Comment: You forgot the network bandwidth bill. That's the greatest cost in all cloud bills. The cost of fixing code in production is a *lot* greater too.
Comment: You are absoloutely right that we should fix it correctly. I agree with you. But right now, production cannot be used, because on production this `level2` does not exist in any document. So we MUST implement a quick fix for this. We def. need to fix this correctly immedieatley, but we also need to make sure that production works today as expected.
Answer: Depending on your implementation, the OData specification has a Logical Negation operator: not(), it's usage is not explicitly documented in the spec but it is listed in 220.127.116.11 Operator Precedence
The usage of this would be to wrap the expression that you want to negate inside a not() function:
&$filter=Tags/Any (c:c/Key eq 'client' and c/Value eq 'Nestlé') and not((Tags/Any (c:c/Key eq 'level2' and c/Value eq 'UNITED KINGDOM'))
or if you simply wanted to exclude all records if any key had a value of 'UNITED KINGDOM' then you could more simply use this:
&$filter=not(Tags/Any (t:t/Value eq 'UNITED KINGDOM'))

NOTE:
not(any()) should produce the same results as all(field ne value) but an all() lambda requires evaluation of every single record, whereas any() we break out of evaluation at the first match. not(any()) should always produce the most efficient result, it is also more resilient to missing properties.


Save computation time with mgcv?

Question: Suppose we have a generalized additive model that is formulated as
gam(y~s(x,bs='tp',k=10),...)

I need to repeat the computation many times (e.g., 1000) for the same x but with different y. I would like to save the overhead setup time, so is there a mechanism with gam to obtain the basis functions, the model matrix and the penalty matrix once through eigen-decomposition in the case of thin plat splines, and then just directly feed them into s() somehow to all the other models?
Comment: Just wanting to confirm; you have multivariate $\boldsymbol{Y}$, where each column vector $\boldsymbol{y}$ is an observation of some variable at the same set of locations as the other response *and* the covariates? I.e. you have multiple response variable on the same set of observational units as the covariates, no missing values (or these have been dealt with before we get anywhere near fitting a GAM)?
Answer: Assuming the things I wrote in my comment on your question hold, then yes, I believe you can do this using the fit = FALSE in the call to gam(), and then modify the object returned to replace the response data, and then pass this object to gam() as argument G.
Here's an example:
## packages
library('mgcv')
library('gratia')
library('dplyr')

## simulate some data
set.seed(2)
N <- 400
SCALE <- 2
# Gu Wabha four term additive model
dat <- data_sim('eg1', n = N, scale = SCALE)

## fit a model as normal for comparison
b <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3),
         data = dat, method = 'REML')

## Re do what we just did but this time don't fit
G <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3),
         fit = FALSE, # <--- Not fitting
         data = dat, method = 'REML')

## simulate some new y given the original covariate values
## reusing some internal functions from gratia to evaluate
## the four functions of Gu & Wabha at the origin Xs
set.seed(1)
dat <- mutate(dat,
              y2 = gratia:::gw_f0(x0) + gratia:::gw_f1(x1) +
                  gratia:::gw_f2(x2) + gratia:::gw_f3(x3) +
                  rnorm(N, mean = 0, sd = SCALE))

## update the components of the model that appear to be
##  related to `y`
G$y <- G$mf$y <- dat$y2

## fit the model with new y
b2 <- gam(G = G)

This is the fit of the first model with the original y

and this is the fit with the second sample of response data

and the output from the models is slightly different, as it should be here as we simulated the same structural form for the second response but we added new Gaussian noise:
summary(b)

Family: gaussian
Link function: identity

Formula:
y ~ s(x0) + s(x1) + s(x2) + s(x3)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)  7.83328    0.09872   79.35   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
        edf Ref.df      F  p-value
s(x0) 3.021  3.753  6.234 0.000129 ***
s(x1) 2.843  3.529 69.711  < 2e-16 ***
s(x2) 8.020  8.741 86.424  < 2e-16 ***
s(x3) 1.001  1.003  4.244 0.040015 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.716   Deviance explained = 72.6%
-REML = 861.13  Scale est. = 3.898     n = 400

and for the model with the updated y
summary(b2)

Family: gaussian
Link function: identity

Formula:
y ~ s(x0) + s(x1) + s(x2) + s(x3)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   7.8718     0.0967    81.4   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
        edf Ref.df       F  p-value
s(x0) 3.027  3.759  13.690 9.95e-10 ***
s(x1) 3.778  4.662  79.603  < 2e-16 ***
s(x2) 7.463  8.412 101.660  < 2e-16 ***
s(x3) 1.000  1.000   0.003     0.96
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.763   Deviance explained = 77.2%
GCV = 3.8992  Scale est. = 3.7406    n = 400

You will see different behaviour if you various response are different things; here I wanted to check that I had found all the places where y was stored and replaced them all so I should get essentially the same fits here.
Comment: You're the wonderful guru! I didn't realize the existence of `G` in `gam`.
Comment: No similar trick exists for `gamm` and `gamm4`?

Save computation time with mgcv?


How can I print to a Lexmark X3550 printer using Ubuntu?

Question: I have a Lexmark X3550 printer and a computer running Ubuntu. Is there any hope in being able to print to this particular printer using Ubuntu? I am not familiar with CUPS. Is this an option?
Comment: If you ever want to replace your "paperweight" with a printer that supports linux/unix, you can search the [printer database](http://www.openprinting.org/printers) at OpenPrinting.org for information about how well printers are supported.
Answer: There are bad news for you, Lexmark driver for linux are absent and seems there isn't support for this printer in CUPS ...
Sorry but there's few chance to print with Lexmark X3550 from ubuntu or another linux OS for the moment ...