zend_http_client browser caching issue

Question: I'm trying to access an https site by passing the username and password into the code, however, the website is denying me access due to 'browser caching issue', can someone help please? here is the code:
<code>$client = new Zend_Http_Client();

$client->setUri('https://www.example.com');
$client->setParameterPost(array(
    'username' => 'username',
    'password' => 'password'
));

$client->request(Zend_Http_Client::POST);
$response = $client->request();

echo $response->getBody();
</code>
Comment: Can you share the error in more detail
Comment: The error is from the client site, it is just not recognizing the credentials.
Answer: Why are you calling <code>$client->request()</code> twice? You probably should call it one.
In addition, the reason could be specific to the site (you did not specify which site it is). For example, many sites implement some kind of CSRF protection token or other security measure which will require you to first GET the log-in page, grab some hidden field value from it and re-send it in the log-in POST request. This is quite typical and I suggest you use Chrome developer tools, Firebug or a similar tool to manually submit the log-in form from your browser, and check which other form values are sent on log-in beyond just the username and the password.
Comment: This is the site https://www.lib.uts.edu.au/auth/login?service=https%3A%2F%2Fwww.lib.uts.edu.au%2Fgoto%3Fqurl%3Dhttp%253a%252f%252fclients1.ibisworld.com.au%252freports%252fau%252findustry%252fkeystatistics.aspx%253fentid%253d116%26_casCheck%3Dtrue#
I tried using firebug but I couldn't pin point which other fields I need to pass, your help is much appreciated.
Comment: The credentials I'm using are the 'student Id' and 'password'
Answer: I sorted out the problem, the code is supposed to work but the site has a security hash that prevents me from accessing it that way.
Comment: You can most likely still work around the problem by extracting that hash using DOM (or if you have to a regex), and sending it in the next request.

zend_http_client browser caching issue


Adding checkbox in admin table display

Question: I'm trying to add a checkbox column in the admin table part of my module.
The idea is to add checkboxes at the beginning of each row, like in the normal admin content management form.
My table is build in a form function with the following code :
function myform_admin_form($form, &$form_state) {

$query = db_select('form_xml', 'f');
$query->join('form_xml_status', 's', 's.id = f.id');
$query->join('users', 'u', 'u.uid = f.uid');
$result = $query
        ->condition('s.status', 'todo', '=')
        ->fields('f')
        ->fields('u', array('name'))
        ->execute()
        ->fetchAll();

$header = array(
array('data' => t('ID')),
array('data' => t('Name')),
array('data' => t('User')),
);

foreach($result as $key){
$rows[] = array(
array('data' => t($key->id)),
array('data' => t($key->name)),
array('data' => t($key->user))
);
}

$form['table'] = array(
'#type' => 'tableselect',
'#header' => $header,
);

$output = theme('table', array('header' => $header, 'rows' => $rows));
$output .= $form;

return $output;

}

My tableselect doesn't display at all, but "Array" appears at the bottom of the table. Is it possible to add checkboxes in a table like this ?
Comment: and the question is...?
Answer: Although there's actually no question, I've noted the last part of your code should look like:
<?php

$form['table'] = array(
  '#type' => 'tableselect',
  '#header' => $header,
  '#options' => $rows,
);

return $form;

Comment: Oops, I forget the question... The problem is that I'm returning the theme table and I try to also return a form.
Comment: I guess you mean neither of both ways works for you. Please update the OP and add the code you are using to load the form, ie. hook_menu(), drupal_get_form()...
Answer: I have worked on some similar script using Drupal 8 version I was working on some same sort of code where I wanted to output a listing of nodes after form submit and the listing should have checkbox in each row.
$form['mytable'] = array(
    '#type' => 'table',
    '#title' => 'List of Nodes',
    '#header' => ["Checkbox","Title","Author"],
);

$nids = \Drupal::entityQuery('node')
        ->condition('status', 1)
        ->execute();
$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);
$nids = array_keys($nodes);

// Add input fields in table cells.
$i=0;
foreach($nids as $nid)
{

  $node = \Drupal\node\Entity\Node::load($nid);
  $contenttitle=$node->title->value;
  $receivername = $node->getOwner()->getDisplayName();
  \Drupal::entityManager()->getStorage('node')->resetCache(array($nid));

    $form['mytable'][$i][''] = array(
                                        '#type' => 'checkbox',
                                        '#return_value' => $nid,
                                    );

    $form['mytable'][$i]['Title'] = array(
                                        '#type' => 'label',
                                        '#title' => t($contenttitle),
                                    );
    $form['mytable'][$i]['Author'] = array(
                                        '#type' => 'label',
                                        '#title' => t($receivername),
                                    );
    $i++;
}
// Add a submit button that handles the submission of the form.
$form['actions']['submit'] = [
                                '#type' => 'submit',
                                '#value' => $this->t('Submit'),
                            ];
return $form;

Hope that Helps.

Adding checkbox in admin table display


Trying to break up a Flask form into "chunks" with pagination

Question: I initially had one long Flask form on a single web page, but now I want to break up that form into smaller chunks and iterate through those chunks with pagination buttons. I'm just a bit confused on how to approach this.
So far, I've created separate form classes and html templates for these different "chunks", but I'm unsure how to tie it all together in the main app.py script. I was going for a dynamic routing approach, but I don't think I'm doing it correctly. Any suggestions?
Form class:
from flask_wtf import FlaskForm
from wtforms import StringField, TextField, SubmitField, IntegerField, SelectField, validators

class InputForm1(FlaskForm):

    stack_name = StringField('STACK NAME', validators=[validators.required()])
    resource_cfn_tmpl_deploy_bucket = SelectField('PIPELINE DEPLOYMENT BUCKET', validators=[validators.required()])
    key_pair = SelectField('KEY PAIR', validators=[validators.required()])
    start_point = SelectField('START POINT', validators=[validators.required()], choices=[("", "---"), ("", "fastq"), ("", "bam"), ("", "hdof"), ("", "gvcf"), ("", "vcf")])
    qc = SelectField('QC', choices=[("", "---"), ("","BAM"), ("","VCF")])

class InputForm2(FlaskForm):

    input_uri = StringField('INPUT BUCKET', validators=[validators.required()])
    output_uri = StringField('OUTPUT BUCKET', validators=[validators.required()])
    ref_uri = SelectField('REFERENCE BUCKET', validators=[validators.required()])
    user_assets_uri = StringField('USER ASSETS BUCKET', validators=[validators.required()])

class InputForm3(FlaskForm):

    target = StringField('TARGET')
    package_name = StringField('PACKAGE NAME', validators=[validators.required()])
    license_name = StringField('LICENSE NAME', validators=[validators.required()])

class InputForm4(FlaskForm):

    cohort_prefix = StringField('COHORT PREFIX', validators=[validators.required()])
    build = SelectField('BUILD', validators=[validators.required()], choices=[("", "---"), ("","GRCh38"), ("","GRCh37")])
    ome = SelectField('OME', validators=[validators.required()], choices=[("", "---"), ("", "wgs"), ("", "wes")])

class InputForm5(FlaskForm):

    cloudspan_mode = SelectField('CLOUDSPAN MODE', choices=[("", "---"), ("", "validation"), ("", "qc")])
    project_id = StringField('PROJECT ID')
    zone = StringField('ZONE')
    cloud_file = StringField('CLOUD FILE')

    submit_final = SubmitField('Execute Pipeline')

pipeline_1.html: (I also have pipeline_2.....pipeline_5.html, with the different inputs as defined in the above Form class)
{% extends 'layout.html' %}

{% block body %}

        <form method="POST" action="">
            {{ form.hidden_tag() }}
            <fieldset class="form-group">

                <legend class="border-bottom mb-4">Pipeline Input</legend>

                    {{ form.stack_name.label(class="form-control-label")}}
                    {{ form.stack_name(class="form-control form-control-lg") }}

       {{form.resource_cfn_tmpl_deploy_bucket.label(class="form-control-label") }}
form.resource_cfn_tmpl_deploy_bucket(class="form-control form-control-lg") }}

                    {{ form.key_pair.label(class="form-control-label") }}
                    {{ form.key_pair(class="form-control form-control-lg") }}

                    {{ form.start_point.label(class="form-control-label") }}
                    {{ form.start_point(class="form-control form-control-lg") }}

                    {{ form.qc.label(class="form-control-label") }}
                    {{ form.qc(class="form-control form-control-lg") }}

Previous

1

2

3

4

5

Next

            </fieldset>

        </form>

{{ error }}

{% endblock %}

app.py: (current attempt, I know this is incorrect, but this is where I'm stuck)
# Import the Flask app
from flask import Flask, url_for, render_template, request, flash, redirect
from math import ceil
from datetime import datetime
from user_input import InputForm1, InputForm2, InputForm3, InputForm4, InputForm5
import json
import subprocess
import os
import sys
import boto3

app = Flask('pipeline-ui')
app.config['S3_CLIENT'] = boto3.client('s3')
app.config['EC2_CLIENT'] = boto3.client('ec2')

app.debug = True

@app.route('/<page_num>', methods=['GET', 'POST'])
def pipeline(page_num):

    if request.method == "POST":
        if page_num == 1:
            form = InputForm1(request.form)
            return redirect('/2')
        if page_num == 2:
            form = InputForm2(request.form)
            return redirect('/3')
        if page_num == 3:
            form = InputForm3(request.form)
            return redirect('/4')
        if page_num == 4:
            form = InputForm4(request.form)
            return redirect('/5')
        if page_num == 5:
            form = InputForm5(request.form)
            return redirect('results')
    return render_template('pipeline_{}.html'.format(page_num), title='Pipeline Input', form=form)

Comment: I'll point two problems I think I see out (but actually I think there are more and this is complicated routing): 1) `return render_template('pipeline_{}.html'.format(page_num), title='Pipeline Input', form=form)`, here `form` is not defined in the case of `GET`. 2) you have no action endpoints defined for your form: `action=""` try `action="{{ url_for('app.pipeline', page_num=X ) }}"`
Answer: Remember that there's no state between requests so, everything else correct, you need a way to store the data of each step for the next one.
If you can't store the data of each step in a database, you might consider reordering the form so that each step could make sense as a commit to the database.
If you don't use a database (or a file) or you can't send the data until all the steps are complete, then another option is just storing the data of each step into the next one, in hidden inputs.
class StepForm(FlaskForm):
  previous_field = SomeField(widget=HiddenInput())
  # ...

step = StepForm()
step.previous_field.data = previous_step.field.data

Of course, you could also just paginate in the frontend using javascript and sending all the data entirely in a single request at the end.


Comparing NSDate objects

Question: I have a an application that uses CoreData. One of the entities contains date attribute which is, well... a date. I am writing a test to check if timestamp passed to class method for that entity's class is being converted to correct NSDate.
Here's my test code:
NSDate *now = [NSDate date];
NSTimeInterval ts = [now timeIntervalSince1970];
// paramDict is a dictionary with attributes and values
[paramDict setValue:[NSNumber numberWithDouble:ts] forKey:@"date"];

MyEntity *myEntity = [MyEntity entityWithAttributes:paramDict inContext:testMOContext];

STAssertTrue([now isEqualToDate:[myEntity date]], @"dates were not equal");

This is only a snippet of the whole tests which checks if all parameters were set correctly. What's interesting though is that date assertion checks fail randomly. I presume the failures has something to do with the loss of double float precision? How should I check for date in this kind of scenario?
update
The timestamp is converted to date in the method like this:
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[[paramDict valueForKey:@"date"] doubleValue]];
[newObject setDate:date];

Comment: "Floating point math is not exact" [details here](http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm).  You should not try to compare floating point numbers for equality.
Answer: You can calculate the difference between your now date and the date of myEntity using
NSTimeInterval difference = fabs([[myEntity date] timeIntervalSinceDate:now]);

and compare the result to a threshold (1 second, for example). If difference is less than 1 second, consider both dates the same.
From the documentation of NSDate (isEqualToDate):

This method detects sub-second differences between dates. If you want to compare dates with a less fine granularity, use timeIntervalSinceDate: to compare the two dates.
Comment: Sorry, but it seems like a hack. I also presume the `isEqualToDate:` method is there for a reason. Just not sure what happens if I instantiate a date from the timestamp that was produced by another date.
Comment: I think it has to do with double float precision, as you mentioned in your question. Maybe the `dateWithTimeIntervalSince1970:` method converts the given time interval internally, which could cause the precision loss. Have you tried to use `dateWithTimeIntervalSinceReferenceDate:` instead? According to the documentation, it "provides the basis for all the other methods in the NSDate interface" and maybe doesn't need to recalculate the interval internally.
Answer: isEqualToDate compares NSDate objects, but your date attribute seems to be a time interval? I suggest using the date type for the attribute, and sticking with NSDate.

Comparing NSDate objects


What's the difference between a service and a store class?

Question: I came across several classes which all seem to implement similar things. When having 3 application layers (Presentation, Business Logic, Persistence) service or store classes seem to implement the business logic layer. So if I understand correctly this is just a naming convention or is there something I'm missing?
I've seen a SessionStore class and a UserService but never have I seen a SessionService or a UserStore (although I'm not certain about the latter).
Comment: `Store` reminds me more of a repository than a business logic class. Anyway it's probably some local naming convention.
Answer: Do not confuse Store with a business layer class. You will often find Store as part of a MVCS pattern (Model-View-Controller-Store), an extension of MVC.
It represents storage and is in fact closer to the repository-unitofwork pattern, and is likely to be used by the business layer.
Comment: Ah, so then `Store` and `Repository` are interchangeable (`UserStore`/`UserRepository`)?
Comment: It might mean something slightly different to the developper but as far as I'm aware, apart from the MVCS case, it is not "officially" part of a design pattern as described in either Design Patterns or Code Complete (the two main references in this realm of expertise).
Comment: When talking about a `Repository` class the design pattern applied is the repository pattern. But I've never heard of a store pattern. ;-)


Add markup to form during validation

Question: I have a custom validator on a webform. When a person enters an address, I validate it. When the address is not right, I set an error in the validation function. This is all going well. But now I want to give the visitor suggestions when he enter a wrong address. This should be done by giving the suggestion in a markup underneath the address input.
I allready set up an empty markup field in the webform, now I just want to put information in it during validation. How is this possible. If you need any dpm or printout let me know please.
Thanks in advance.
Answer: In your validate you can set a variable in the $form_state that tells if the validation failed or not:
function webform_validate_handler(&$form, &$form_state) {
  if ($mail_invalid) {
    $form_state['mail_invalid'] = TRUE;
  }
  else {
    $form_state['mail_invalid'] = FALSE;
  }
}

Then in your form, you can check for empty($form_state['mail_invalid']) and show the markup when the empty check returns false.
function hook_form_alter(&$form, &$form_state, $form_id) {
  ...
  if (!empty($form_state['mail_invalid']) {
    $form['markup'] = ...;
  }
}

Comment: how can I alter the form then ? hook_form_alter is called BEFORE validation handler, and if I change any varible in $form in the validation hook, nothing happens.
Comment: @Nealv You didn't read my answer properly, I have updated my answer to clearly show what I'm talking about. You need to check `$form_state` like I explained.
Comment: I understand what you are saying, but the "validation" hook is called AFTER the form alter. so when the form_alter is executed, $form_state['mail_invalid'] will be NULL, because you set it afterwards. right
Comment: @Nealv That is why you use the `empty()` to check it. First time around it won't exist so `!empty() == FALSE` in order words the markup isn't added to the form. If the validation fails, the form is rebuild, but this time `!empty() == TRUE` so the markup is shown. This is really quite simple.
Comment: I understand what you are saying, but there is no first and second time. flow is like this: hook_form_alter -> hook_validate -> render. So after the validation I cant change anything in the form, and during neither because the form is not a reference but a copy. Is it possible to chat ?
Comment: could you help me out please, I am really stuck, for days :S
Comment: @googletorp can't we alter the form right from the validate function ? $form is passed by reference and I have done some minor changes in validate functions before (like makring fields readonly, etc) so I'm wondering if there is a specific reason why you don't alter the form in validate function.

Add markup to form during validation


can't save search box configuration under themes>config

Question: I made a custom theme based on Zen. In my custom theme (and under stock Zen theme as well) there is a problem with enabling my search form. When I tick the checkbox that says "search" box under admin>theme>customtheme>config>Toggle Box and click save, the page refreshes and I notice that the checkbox at "search box" is unticked again. Obviously this results in me not being able to show the search form.
Here's the code from my page.tpl.php file.
<?php if ($search_box || $primary_links || $secondary_links || $navbar): ?>

        <?php if ($search_box): ?>

              <?php print $search_box; ?>

        <?php endif; ?>

Answer: I had the same problem - answer: Search module is not enabled by default! So

go to admin/build/modules, scroll down to 'Search' and tick the checkbox.
Then go to admin/user/permissions, scroll down to 'Search module' and set permissions for Anonymous and authenticated user (and any other type of users you might have configured and want to give this permission to).
Finally, go over to admin/build/themes/settings/[your-theme-name] where you will find that the 'Search box' checkbox is now tickable.

You should now see the search box - if you don't , flush caches!
Answer: Is it by any chance the same issue as mentioned in:

Search box gets disabled after arbitrary amount of time
Search Box in Subtheme Options keeps turning itself off
Comment: Not really. In those cases you mention, the search box does appear for a bit and only after having been there it dissapears. My problem is that enabling the search box and saving that configuration doesn't even work to begin with. Of course doens't mean those problems are related so I maybe it's a good idea to start sifting through those cases you mentioned after all.
Answer: Have you updated the theme_settings.php file of your subtheme, along with template.php?
theme_settings.php is where the search box toggle on the the config page is specified, so my guess is that the error is there.
Another quick check, if you edit the settings on the parent Zen theme, do those save and cascade down into the subtheme?


Does snmpd support SNMP monitoring of SendMail queues?

Question: CentOS 5.7 | SendMail 8.14.x
I've got a CentOS box running snmpd and I'd like to monitor sendmail queues. Is this natively supported by snmpd or will I need to do something special to monitor it?
Answer: It does appear this has been done as there is a mib for sendmail.  I found this reference to implementation and several references to using mibII/mta_sendmail.c
Comment: Thanks.  That's exactly what I needed.  Worked like a charm.


Prove zeta-esque relationship with floor function

Question: I'm looking to show that:
$$ \frac1{1-2^{-s}} \frac1{1-4^{-s}} = \sum_{k=0}^\infty \frac{\left\lfloor1+\frac{k}{2}\right\rfloor}{2^{ks}}$$
I've noticed $(1-4^{-s})^{-1} = (1-2^{-2s})^{-1}$ and I'm fairly certain that's somehow where the floor function comes from.
I'm stuck though on the denominator. I have the first terms of $\zeta(s)$ and $\zeta(2s)$ expressed as products of primes respectively on the left. Why do I get a $k$ in the exponent in the denominator on the right? How should I go about proving this?
Answer: We have:
$$\frac{1}{1-2^{-s}}\frac{1}{1-4^{-s}}=\sum_{n\geq 0}2^{-ns}\sum_{m\geq 0}2^{-2ms}=\sum_{k\geq 0}r(k)\, 2^{-ks}\tag{1}$$
where:
$$ r(k) = \#\{(a,b)\in\mathbb{N}^2 : a+2b = k \}\tag{2} $$
so we just need to show that $r(k)=\left\lfloor 1+\frac{k}{2}\right\rfloor$.
That is pretty easy, since $r(k)$ is just the number of even numbers $\leq k$.


Setting up GPO to apply upon SSTP VPN login

Question: I have successfully setup up a VPN connection to an EC2 instance of Windows Server 2008 using SSTP. How do I get GPOs to apply upon VPN login?
Answer: I'd use the Connection Manager Administration Kit to create an EXE that creates the SSTP connection. One of the features of the CMAK is the ability to execute commands after the connection has been established. You could execute a gpupdate after connection to apply Group Policy. Beware, though, that some Group Policy settings only work during boot (Software Installation being one example) so you may never see some types of settings apply.
Comment: That would be one of my exact uses for it (software installation and WSUS). I'll check it out though and see if I can combine this with some other script and registry hack. Thanks
Comment: You might consider just exposing the DCs directly to the Internet and requiring IPSEC such that the EC2 clients can access domain resources during boot.
Comment: Thought about that and even experimented with Amazon's firewall settings but ultimately AWS has to many restrictions that I cant modify to expose the DC "wide open". Plus even if I did get it to work, there are too many security complications that arise. However if you are familiar with that type of setup, I would be glad to look over the setting.
Comment: @JohnR: I'm not familiar with it in an Amazon context at all. I probably should spend some time on it but I never have... >sigh<  Copious free time, etc...
Comment: Just tried to use CMAK using the same settings (more or less) as the regular windows connection wizard and I get the following error: The certificate's CN name does not match the passed value.
 (Error 0x800b010f) For customized troubleshooting information for this connection, click Help.

Sigh, trouble shooting certificates... my favorite!! (>_<)
Answer: The documentation for Deploying VPN Connections by Using PowerShell and Group Policy worked nicely for me. Not sure why I couldnt get CMAK to work.
I added a small touch for smoother operation by using GPO to create a hidden folder on the local machine and copy the ps1 and xml files, that way there is a locally stored copy of the VPN connection script. Now that the computer startup script always has a locally stored path to the script... makes the setup much more reliable.


remove an element if it exists for all sub-elements of a list

Question: I come across lists that I would like to parse before coercing into a data frame. Sometimes I have lists that have elements I'm not expecting.  I'd like to be able to remove all of these unexpected elements by name when they arise.  Here is an example of a list with an element wackything that I would like removed without having to call the element index or using a for loop through each sub-element.
my_list <- list(person = list(name = "mike", phone = "111-1111"),
 person = list(name = "lisa", phone = "222-2222", wackything = "PLEASE REMOVE ME"),
 person = list(name = "kimo", phone = "333-3333"))

I would like my final list to look like this:
final_list <- list(person = list(name = "mike", phone = "111-1111"),
            person = list(name = "lisa", phone = "222-2222"),
            person = list(name = "kimo", phone = "333-3333"))

so that I can corece it to a data frame using
do.call(rbind, lapply(final_list, rbind))

Answer: I think you have too many rbinds in your anticipated use. See if this is satisfactory:
> rmwac <- function(x) x[ !names(x) %in% "wackything"]
> do.call(rbind, lapply(my_list, rmwac))
       name   phone
person "mike" "111-1111"
person "lisa" "222-2222"
person "kimo" "333-3333"

Notice that epi10's perfectly fine answer use a negative sign and that was possible because grep returns numeric values and indexing of lists with numeric values is possible. It is not, however, possible to use the negative sign with character and logical values.
Comment: Thanks! R doesn't like the duplicate row names when converting it to a data.frame.
Comment: Use: `as.data.frame( do.call(rbind, lapply(my_list, rmwac)), row.names=-1 )`
Answer: bind_rows from the dplyr package will work even if not all the lists share the same element names. Then you can remove the columns you don't need.
library(dplyr)

df = bind_rows(my_list)

   name    phone       wackything
1  mike 111-1111               NA
2  lisa 222-2222 PLEASE REMOVE ME
3  kimo 333-3333               NA

df = df[ , -grep("wackything", names(df))]

   name    phone
1  mike 111-1111
2  lisa 222-2222
3  kimo 333-3333

Answer: You could try this. The first step is similar to 42-'s answer. We then use sapply, which returns a matrix that we then have to transpose.
my_list <- lapply(my_list, function(x)x[names(x)!= "wackything"])
data.frame(t(sapply(my_list,c)), row.names=NULL)

#  name    phone
#1 mike 111-1111
#2 lisa 222-2222
#3 kimo 333-3333

Another option that gives you the same result.
data.frame(Reduce(rbind, my_list), row.names=NULL)

We use row.names=NULL when building the dataframe. You can do it without but that will result in a warning message related to the duplicate rownames that we have.


Setting up the private file directory (nginx)

Question: Problem
I'm trying to set-up a private file directory for Drupal on an LEMP stack (Ubuntu 12.04, nginx, MySQL, PHP), I wasn't 100% sure about the permissions or set-up so I thought I'd ask, how should you do it?
So Far
It needs to be a folder which is writable by the webserver but not accessible from the web.
Example:
Location: drupal_root/privatefiles
Permission: chgrp 775 www-data privatefiles
Nginx config: (goes into /etc/nginx/sites-available/mysite):
server {
         listen 8080;
           root /srv/www/mysite/public;

           location ^~ /privatefiles {
             internal;
           }

        ...
        }

Would that be enough? It recommends on the official page to have the folder outside the Drupal root. What difference would this make?
Answer: Have a look at Perusio's config, it has all the information and explanation you need. Here is a quote from it:

This config assumes that private files are stored under a directory
  named private. I suggest sites/default/files/private or
  sites/<sitename>/files/private but can be anywhere inside the site
  root as long as you keep the top level directory name private. (...)
  Example: Calling the top level private files directory protected
  instead of private.
location ^~ /sites/default/files/protected {
  internal;
}

Now any attempt to access the files under this directory directly will
  return a 404.

...

The usual practice involves setting up a directory outside of
  files directory and giving write permissions to the web server user.
  (...)  I think it to be less advisable, in the sense that now there's another directory that is writable by the server.
I prefer to use a directory under files, which is the only one that is
  writable by the web server, and use the above location (protected or
  private) to block access by the client to it.

In short, marking it as internal is enough.
Comment: That's a brilliant resource. Thank you so much for pointing me to that.
Comment: @Attiks, with your permission I edited the answer to add the relevant snippet, since it is recommended to have _self contained_ answers. Cheers


Can every continuous curve (or surface) be parametrised?

Question: I read here (on page 3) that

"Every plane parametric curve (or surface) can be expressed as an implicit curve (or surface). Some, but not all implicit curves (or surfaces) can be expressed as parametric curves (or surfaces)".

It also states that this fact comes from Algebraic Geometry.
I was interested in the parameterisation of continuous curves (or surfaces). Can every continuous curve (or surface) be parameterised? If not, then under what conditions they can't be?
Comment: A _rational_ parameterization for $y^2=x^3-2x+2$ does not exist.
Comment: Pertaining to the example above, have you heard of [$\wp$](https://en.wikipedia.org/wiki/Weierstrass%27s_elliptic_functions)?
Answer: There are obstructions to algebraic curves (and more general varieties) being parametrizable. I will discuss the case of projective curves for simplicity, but all of the main ideas extend to higher dimension. Let us even assume we have a smooth projective curve $C$.
A parameterization for $C$ amounts to a surjective morphism $\phi : \mathbb P^1 \to C$. By the Riemann--Hurwitz formula, this forces the genus of $C$ to be $0$ (and in fact forces $\phi$ to be an isomorphism). In the case of smooth curves over the complex numbers, the geometric, arithmetic, and topological notions of genus all agree, so you can think of this as being the "number of holes" appearing in the compact Riemann surface associated to a smooth projective curve over $\mathbb C$. When the curve is not smooth, more care has to be taken, but I'll ignore those subtleties here.
So a good class of examples of curves that cannot be parametrized are smooth curves of nonzero genus, e.g. elliptic curves. The example given in Jan-Magnus's comment above is an elliptic curve. These are the smooth projective curves of genus $1$. In characteristic $>3$, these are precisely the curves of the form $y^2=x^3+ax+b$ where the RHS does not have a double root. Curves of higher genus will also give examples.
Comment: Thanks for commenting! However, I am afraid my math knowledge is insufficient to comprehend your answer. Can you explain briefly considering I have knowledge pertaining to second-year undergraduate math? Or could you provide any relevant links? Thanks in advance!
Comment: @Vijay: What "Category" is the Isomorphism between $P^1$ and $C$. As Manifolds?


Whether to use structural equation modelling to analyse observational studies in psychology

Question: I've noticed this issue coming up a lot in statistical consulting settings and i was keen to get your thoughts.
Context
I often speak to research students that have conducted a study approximately as follows:

Observational study
Sample size might be 100, 200, 300, etc.
Multiple psychological scales have been measured (e.g., perhaps anxiety, depression, personality, attitudes, other clinical scales, perhaps intelligence, etc.)

The researchers have read the relevant literature and have some thoughts about possible causal processes.
Often there will be some general conceptualisation of variables into antecedents, process variables, and outcome variables.
They have also often heard that structural equation modelling is more appropriate for testing overall models of the relationships between the set of variables that they are studying.
Question

Under what conditions do you think structural equation modelling is an appropriate technique for analysing such studies?
If you would not recommend structural equation modelling, what alternative techniques would you recommend?
What advice would you give to researchers considering using structural equation modelling in such cases?
Answer: My disclaimer: I realize this question has laid dormant for some time, but it seems to be an important one, and one that you intended to elicit multiple responses. I am a Social Psychologist, and from the sounds of it, probably a bit more comfortable with such designs than Henrik (though his concerns about causal interpretations are totally legitimate).
Under What Conditions Is SEM An Appropriate Data Analysis Technique?
To me, this question actually actually gets at two distinct sub-questions:

Why use SEM in the first place?
If a researcher has decided to use SEM, what are the data-related requirements for using SEM?

Why use SEM in the first place?
SEM is a more nuanced and complicated--and therefore less accessible--approach to data analysis than other, more typical, general linear modelling approaches (e.g., ANOVAs, correlations, regression, and their extensions, etc.,). Anything you can think of doing with those approaches, you can do with SEM.
As such, I think would-be users should first strongly evaluate why they are compelled to use SEM in the first place. To be sure, SEM offers some powerful benefits to its users, but I have reviewed papers in which none of these benefits are utilized, and the end-product is a data analysis section in a paper that is needlessly more difficult for typical readers to understand. It's just simply not worth the trouble--for the researcher, or the reader--if the benefits of SEM vs. other data analysis approaches are not being reaped.
So what do I see as the primary benefits of an SEM approach? The big ones, in my opinion are:
(1) Modeling latent variables: SEM allows users to examine structural relations (variances, covariances/correlations, regressions, group mean differences) among unobserved latent variables, which are essentially the shared covariance between a group of variables (e.g., items from an anxiety measure your students might use).
The big selling point for analyzing latent variables (e.g., latent anxiety) vs. an observed score of the construct (e.g., an average of the anxiety items) is that latent variables are error-free--latent variables are formed of shared covariance, and error is theorized to covary with nothing. This translates to increased statistical power, as users no longer have to worry about measurement unreliability attenuating the effects they are trying to model.
Another, more understated, reason to consider using SEM is in some cases it is a more construct-valid way of testing our theories about constructs. If your students, for example, were using three different measures of anxiety, wouldn't it be better to understand the causes/consequences of what those three measures have in common--presumably anxiety-- in an SEM framework, instead of privileging any particular one measure as the measure of anxiety?
(2) Modeling multiple dependent variables: Even if someone isn't going to use SEM to model latent variables, it can still be quite useful as a framework for simultaneously analyzing multiple outcome variables in one model. For example, perhaps your students are interested in exploring how the same predictors are associated with a number of different clinically relevant outcomes (e.g., anxiety, depression, loneliness, self-esteem, etc.,). Why run four separate models (increasing Type I error rate), when you can just run one model for all four outcomes that you are interested in? This is also a reason to use SEM when dealing with certain types of dependent data, where multiple, dependent respondents might both yield predictor and outcome responses (e.g., dyadic data; see Kenny, Kashy, and Cook, 2006, for a description of the SEM approach to using the Actor-Partner Interdependence Model [APIM]).
(3) Modeling assumptions, instead of making them: With many other approaches to data analysis (e.g., ANOVA, correlation, regression), we make a ton of assumptions about the properties of the data we are dealing with--such as homogeneity of variance/homoskedasticity. SEM (usually combined with a latent variable approach) enables users to actually model variance parameters simultaneously alongside means and/or correlations/regressive pathways. This means that users can begin theorizing about and testing hypothesis about variability, in addition to mean differences/covariability, instead of just treating variability as an annoying assumption-related afterthought.
Another testable assumption, when comparing group mean levels on some variable, is whether that variable actually means the same thing to each group--referred to as measurement invariance in the SEM literature (see Vandenberg & Lance, 2000, for a review of this process). If so, then comparisons on mean levels of that variable are valid, but if groups have a significantly different understanding of what something is, comparing mean levels between groups is questionable. We make this particular assumption implicitly all the time in research using group-comparisons.
And then there is the assumption, that when you average or sum item scores (e.g., on an anxiety measure) to create an aggregate index, that each item is an equally good measure of the underlying construct (because each item is weighted equally in the averaging/summing). SEM eliminates this assumption when latent variables are used, by estimating different factor loading values (the association between the item and the latent variable) for each item.
Lastly, other assumptions about the data (e.g, normality), though still important for SEM, can be managed (e..g, through the use of "robust" estimators, see Finney & DiStefano, 2008) when the data fail to meet certain criteria (low levels of skewness and kurtosis).
(4) Specifying model constraints: The last big reason, in my opinion, to consider using SEM, is because it makes it very easy to test particular hypotheses you might have about your model of data, by forcing ("constraining" in SEM terms) certain paths in your model to take on particular values, and examining how that impacts the fit of your model to your data. Some examples include: (A) constraining a regression pathway to zero, to test whether it's necessary in the model; (B) containing multiple regression pathways to be equal in magnitude (e.g., is the associative strength for some predictor roughly equal for anxiety and depression?); (C) constraining the measurement parameters necessary to evaluate measurement invariance (described above); (D) constraining a regression pathway to be equal in strength between two different groups, in order to test moderation by group.
What are the data-related requirements for SEM?
The data-related requirements for SEM are pretty modest; you need an adequate sample size, and for your data to meet the assumptions of the model estimator you have selected (Maximum-Liklihood is typical).
It is difficult to give a one-size-fits-all recommendation for sample size. Based on some straightforward simulations, Little (2013) suggests that for very simple models, 100-150 observations might be enough, but sample size needs will increase as models become more complex, and/or as the reliability/validity of the variables used in the model decreases. If model complexity is a concern, you could consider parcelling the indicators of your latent variables, but not all are onboard with this approach (Little, Cunningham, Shahar, & Widaman, 2002). But generally speaking, all else being equal, bigger samples (I strive for 200 minimum in my own research) are better.
As for meeting the assumptions of a selected estimator, usually this is pretty easy to assess (e.g., look at skewness and kurtosis values for a maximum likelihood estimator). And even if data depart from assumed properties, a research could consider the use of a "robust" estimator (Finney & DiStefano, 2008), or an estimator that assumes a different kind of data (e.g., a categorical estimator, like diagonally weighted least squares).
Alternatives To SEM for Data Analysis?
If a researcher isn't going to take advantage of the benefits provided by an SEM approach that I've highlighted above, I'd recommend sticking to the more straight-forward and accessible version of that particular analysis (e..g, t-tests, ANOVAs, correlation analysis, regression models [including mediation, moderation, and conditional process models]). Readers are more familiar with them, and will therefore more easily understand them. It's just not worth confusing readers with the minutiae of SEM if you're essentially using SEM to the same effect as a simpler analytic approach.
Advice to Researchers Considering The Use Of SEM?
For those brand new to SEM:

Get a comprehensive, accessibly-written foundation SEM text. I like Beaujean (2014), Brown (2015; the earlier edition is solid too), and Little (2013; good overall introduction, even though it later focuses specifically on longitudinal models).
Learn how to use the lavaan package for R (Rosseel, 2012). It's syntax is as easy as SEM syntax can get, it's functionality is broad enough for many folks' SEM needs (definitely for beginners), and it's free. The Beaujean book gives a great simultaneous introduction to SEM and the lavaan package.
Consult/use CrossValidated and StacksOverflow regularly. Unexpected things can happen when fitting SEM models, and chances are, many of the weird things you might experience have already been described and troubleshot on Stacks.
As Herik points out, note that just because you are specifying a model that implies causal associations, it does not mean that SEM helps to establish causality in a cross-sectional/non-experimental study. Also, it's totally worth considering the use of SEM to analyze data from longitudinal and/or experimental designs.

And for those who are beginning to actually use SEM:

You will, at some point, be tempted to specify correlated residuals willy-nilly, in an effort to improve the fit of your model. Don't. At least not without a good a priori reason. More often than not, a larger sample, or a simpler model is the cure.
Avoid the use of the marker-variable method of identification for latent variables (i.e., fixing the first factor loading to 1). It privileges that indicator as the "gold-standard" indicator of your latent variable, when in most cases, there is no reason to assume this is the case. Be aware that this is the default identification setting in most programs.

References
Beaujean, A. A. (2014). Latent variable modeling using R: A step-by-step guide. New York, NY: Routledge.
Brown, T. A. (2015). Confirmatory factor analysis for applied researchers (2nd edition). New York, NY: Guilford Press.
Finney, S. J., & DiStefano, C. (2008). Non-normal and categorical data in structural equation modeling. In G. R. Hancock & R. D. Mueller (Eds.), Structural equation modeling: A second course (pp. 269-314). Information Age Publishing.
Kenny, D. A., Kashy, D. A., & Cook, W. L. (2006). Dyadic data analysis. New York, NY: Guilford Press.
Little, T. D. (2013). Longitudinal structural equation modeling. New York, NY: Guilford Press.
Little, T. D., Cunningham, W. A., Shahar, G., & Widaman, K. F. (2002). To parcel or not to parcel: Exploring the question, weighing the merits. Structural Equation Modeling, 9, 151-173.
Rosseel, Y. (2012). lavaan: An R package for structural equation modeling. Journal of Statistical Software, 48(2), 1-36.
Vandenberg, R. J., & Lance, C. E. (2000). A review and synthesis of the measurement invariance literature: Suggestions, practices, and recommendations for organizational researchers. Organizational Research Methods, 3, 4-70.
Comment: +1 good answer. I'm looking forward to your other contributions!
Comment: +1 Great answer. I agree with most of what you say. One follow up point: I don't think SEM has greater statistical power because it is estimating relationship between latent variables. In general, I would think that if anything SEM introduces an additional source of error. Thus, there is the usual  error in estimating the observed variable, and additional error in estimating error variance or other elements of the latent structure.
Answer: Disclaimer: I consider myself an experiemtal psychologist with an emphasis on experimental. Hence, I have a natural unease with designs like this.
To answer your first and second question: I think for a design like this a SEM or, depending on the number of variables involved, mediation or moderation analyses is the natural way of dealing with the data. I have no good idea what else to recommend.
For your third question: I think the main advantage with a design like this is it's main disadvantage. Namely that you (given enough variables) will find significant results. The question is, how you interpret these results.
That is, you can look at so many hypotheses (some more some less inspired by the relevant literature) that you will probably find something significant (not in the literal sense of rejecting a SEM) that will be interpratable in a psychological sense. Therefore, my advice to anyone doing this would be twofold:

Stress the problem with causal interpretation of these designs. I am not an expert in this but know, that a fully cross-sectional design can hardly be interpreted causal, independent of how intuitively plausible that may sound. More advanced designs like cross-lagged pnael designs or stuff like this is needed for causal interpetations. I think the work by Shadish, Cook & Campbell (or at least some of them) are a good ressource for further discussion of these topics.
Stress the individual responsibility and scientific ethics. If you see that your initial idea is not supported by the data, it is the natural next step to inspect the data further. However, you shall never rely on HARKing (Hypothesizing After the Results are Known; Kerr, 1998, see also Maxwell, 2004). That is, you should stress that there is a thin line between a reasonable adaption of your hypotheses given the data and cherry picking of significant results.
Comment: and Bernd:  Ditto! Great acronym and I hope it catches on.


Prove that there are infinitely many composite numbers so that $\phi (n)$ divides $n-1$

Question: Prove that there are infinitely many composite numbers so that $\phi (n)$ divides $n-1$, where $\phi (n)$ is Euler's function.
I really don't know how to solve this, so could someone give me a hint or something else?
Thanks.
Comment: Hint: what is $\;\varphi(p)\;$ for  *prime* $\;p\;$ ?
Answer: There are certainly infinitely many prime numbers $p$ with $\phi(p)\mid (p-1)$, namely all prime numbers. We have $\phi(p)=p-1$.
For composite numbers however it is not known whether or not there is any such integer.
In fact, this is called Lehrer's totient problem. Lehmer conjectured in $1932$ that there are no composite numbers $n$ with $\phi(n)\mid (n-1)$.
Comment: The original problem was to prove that there are infinitely many composite numbers sto that n divides $3^{n-1}-2^{n-1}$. I though if I prove the Lehrer's totient problem I could solve it easy.


Find $T(x,y,z)$ if $T:\mathbb R^3\to \mathbb R^3$ given that basis and the representation matrix, difference between 2 methods

Question:
Find $T(x,y,z)$ if $T:\mathbb R^3\to \mathbb R^3$ given that basis $B=((1,1,0), (0,1,1), (1,1,1))$ and
  $$
[T]_B=\begin{pmatrix} 0&1&0\\0&1&0\\-1&0&2\end{pmatrix}
$$

As far as I understand there're 2 methods for doing this. I will show the method I know $(1)$ and the method that I saw in the solution $(2)$. The final answers are different so I'd like to know whether only one method is correct, different answers are possible or I made a mistake.
My method 1 (possibly correct):
Express $(x,y,z)$ as a linear combination of the basis $B$:
$$
\begin{pmatrix}1&0&1&x\\1&1&1&y\\0&1&1&z\end{pmatrix}\to \begin{pmatrix}1&0&1&x\\0&1&0&y-x\\0&1&1&z\end{pmatrix}\to\begin{pmatrix}1&0&1&x\\0&1&0&y-x\\0&0&1&z-y-x\end{pmatrix}\to\begin{pmatrix}1&0&0&2x-z+y\\0&1&0&y-x\\0&0&1&z-y-x\end{pmatrix}
$$
Now we want to find the images of $(x,y,z)$ according to $[T]_B$:
$$
[T]_B\cdot [(x,y,z)]_B=\begin{pmatrix} 0&1&0\\0&1&0\\-1&0&2\end{pmatrix}\cdot\begin{pmatrix}2x-z+y\\y-x\\z-y-x\end{pmatrix}=\begin{pmatrix}y-x\\y-x\\-4x+3z-3y\end{pmatrix}
$$
Let $\{b_1,b_2,b_3\}$ be the vectors of the basis $B$ in their order.
Then $T(x,y,z)=(y-x)b_1+(y-x)b_2+(-4x+3z-3y)b_3=$
$$
=(y-x)(1,1,0)+(y-x)(0,1,1)+(-4x+3z-3y)(1,1,1)=\\
=(y-x,y-x,0)+(0,y-x,y-x)+(-4x+3z-3y,-4x+3z-3y,-4x+3z-3y)=\\
=(-5x-2y+3z,-6x-5y+3z,-5x-2y+3z).
$$

Method 2 (the correct one):
I don't even know what is the meaning of this stage $\ast$, I guess we're getting the images of the vectors from $B$ (even though we already know that $T((1,1,0)=(0,0,-1)$ etc.):
$$
\begin{pmatrix}1&0&1\\1&1&1\\0&1&1\end{pmatrix}
$$
$$
T(1,1,0)=B\cdot[T(v_1)]_B=B\cdot(0,0,-1)=-(1,1,1)\\
T(0,1,1)=B\cdot[T(v_2)]_B=B\cdot(1,1,0)=(1,2,1)\\
T(1,1,1)=B\cdot[T(v_3)]_B=B\cdot(0,0,-1)=(2,2,2)
$$
Now we find the vectors according to standard basis:
$$
T(1,0,0)=T(1,1,1)-T(0,1,1)=(2,2,2)-(1,2,1)=(1,0,1)
$$
Similarly:
$$
T(0,1,0)=(-2,-1,-2)\\T(0,0,1)=(3,3,3)
$$
Finally:
$$
T(x,y,z)=T(x(1,0,0)+y(0,1,0)+z(0,0,1))=\\
=x(1,0,1)+y(-2,-1,-2)+z(3,3,3)=\\
=(x-2y+3z,-y+3z,x-2y+3z)
$$
Please explain whether my method is incorrect and why.
Answer: I think the following sentence is wrong

I guess we're getting the images of the vectors from $B$ (even though we already know that $T(1,1,0)=(0,0,−1), \ T(1,1,0)=(0,0,−1)$ etc.)

Indeed $T(1,1,0)$ is equal to $(0,0,-1)$ in the base $B$, which is actually $(-1, -1, -1)$.
But your first method seems correct. However you made a sign mistake in the third matrix, the bottom right element should be $z-y+x$. I think this changes things a lot and might lead to the correct result.
Comment: $T(1,1,0)=(0,0,-1)_B=-(1,1,1)$
Comment: yes, you can represent the same vector in different bases, and therefore they won't have the same coordinates. $-(1,1,1)$ has coordinates $0$, $0$ and $-1$ in the base $B$
Comment: the "canonical" base of $\mathbb R^3$, $B_c=((1,0,0),(0,1,0),(0,0,1))$
Comment: So if $T(1,1,0)=(0,0,-1)$ then we already have an image. So what is $-(1,1,1)$?
Comment: I re-did the calculation after you noticed the mistake and it turned out the same! Thanks! I still don't understand the difference between $(0,0,-1)$ and $-(1,1,1)$. They're both images, are they images according to different bases?
Comment: so what is the base of $-(1,1,1)$?


How to make menu links with include?

Question: I'm making my website with include function so less have to bee downloaded. But I just can't remember how to make it the way I wan't.
I got a menu like this: Frontpage - Products - Prices - About us - Contact.
When on the frontpage and clicking the Products link I wan't the content of the Products page to show on the same page via the include, but how is it I do that? The content of the Products page and the other will of course just bee an empty file with some text.
Can you please help me?
Answer: If you're using PHP, you can simply use file_get_contents("FileYouWantHere");. This will output the contents of that file. If that file is written in PHP too however, use include("FileYouWantHere);.
Comment: But with that, will I be able to view Frontpage, product, prices, about us and contact text on the same page?

How to make menu links with include?


Image not shrinking when I try max width

Question: Trying to have my image shrink with the page size. Tried a couple things either it doesn't work or it decides to fit another div I have which isn't related to this one
.top-page-image {
    position: relative;
    top: -8px;
    left: -8px;
    background-image: url(basictop.jpg);
    background-size: cover;
    background-repeat: no-repeat;
    height: 100vh;
    width: 100vw;
    opacity: 0.8;
    max-width: 100%;
}

and the HTML

Comment: I'm not clear what you need to achieve. With the background size set to cover the part of the image shown will adjust to either rop the sides or the top/bottom to make sure its aspect ratio is not affected but that the whole window will be covered. Did you want the whole image to be viewable whatever the viewport aspect ratio instead?
Comment: yeah, want the image to be viewable regardless
Answer: To make the whole image always visible regardless of the viewport's aspect ratio use contain instead of cover as the background-size.
Also set background-repeat to no-repeat and you may want to ensure it is centered.
Inevitably you will have space either at the sides or top/bottom if the aspect ratio of the viewport isn't the same as the aspect ratio of the image.

.top-page-image {
  position: relative;
  top: -8px;
  left: -8px;
  background-image: url(https://picsum.photos/id/1015/200/300);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center center;
  height: 100vh;
  width: 100vw;
  opacity: 0.8;
  max-width: 100%;
}

Comment: How do you mean 'fixing the spaces'? If the image is sort of long and thin compared to the viewport there will just be blank space on either side of the image.
Comment: It shouldn't be leaving white spaces all over, only either on the sides or on the top and the bottom. You cannot avoid having white space if you want the whole of the image to show.
Comment: This helped thank you. But how will I now go about fixing the spaces on the sides kind of confused on how to deal with that part
Comment: Now when I shrink the page the image doesn't fit the whole screen anymore. The image shrinks but it doesn't fit the whole screen and leaves white spaces all over
Answer: It is the same as you want. If it is not what you won't try to describe your problem clearly by using code attribute in the text editor

.top-page-image {
    position: relative;
    top: -8px;
    left: -8px;
    background-image: url(https://cdn.dribbble.com/uploads/601/original/ff7474bc9245e3ac5a25cff4f39b2707.png?1544835635);
    background-size: cover;
    background-repeat: no-repeat;
    height: 100vh;
    width: 100vw;
    opacity: 0.8;
    max-width: 100%;
}


Spring: How to define database config?

Question: I try to execute simple request to MySql database via jdbcTemplate but I have an error when framework load and parse xml file whicj define my datasource:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
      <property name="url" value="jdbc:mysql://localhost:3306/spring_training"/>
      <property name="username" value="root"/>
      <property name="password" value="pass"/>
    </bean>
</beans>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>SpringTrainingTemplate</display-name>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-config.xml /WEB-INF/jdbc-config.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>hello</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>hello</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

and Controller that invoke it:
@Controller
public class HomeController {

@Autowired
private ExampleService exampleService;

@RequestMapping(value = "/details", method = RequestMethod.GET)
public String details(Model model) {

    ApplicationContext context = new ClassPathXmlApplicationContext("jdbc-config.xml");
    ExampleDao dao = (ExampleDao) context.getBean("ExampleDao");
    List<Application> list = dao.getAllApplications();

    model.addAttribute("application", list.get(0).getName());
    model.addAttribute("descriptionOfApplication", list.get(0).getDescription());

    return "details";
}
}

public class ExampleDao {

private String request = "select * from application";

private JdbcTemplate jdbcTemplate;

@Autowired
private DataSource dataSource;

public ExampleDao(DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
}

public List<Application> getAllApplications() {
    List<Application> applications = this.jdbcTemplate.query(request, new RowMapper<Application>() {
        @Override
        public Application mapRow(ResultSet rs, int i) throws SQLException {
            Application application = new Application();
            application.setName(rs.getString("name"));
            application.setType(rs.getString("type"));
            application.setDescription(rs.getString("description"));
            application.setDownloads(rs.getInt("downloads"));
            return application;
        }
    });
    return applications;
}
}

Whe I run it and input http://localhost:8080/details I have got an 500 exception with stacktrace with this message:
root cause
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [jdbc-config.xml]; nested exception is java.io.FileNotFoundException: class path resource [jdbc-config.xml] cannot be opened because it does not exist

Can you explain me how to configure jdbc connection in rigth way or if my approach is correct where I should look for a solution of my issue? All help would be appreciated. Thanks.
Answer: Spring cannot find your jdbc-config.xml configuration file.
You can put it in your classpath instead of the WEB-INF folder and load it in your web.xml like this:
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-config.xml,classpath:jdbc-config.xml</param-value>
</context-param>

A good practice is to create folders main and resources in your src folder and to add them in the classpath. Then you can put the spring config file in the src/resources folder.
Comment: Thanks for the answer and example. Could you explain how to put this files into classpath?
Comment: In IDEA via "Project structure->Modules" I mark WebContent project also as "src". It allows me to refer on jdbc-config.xml and spring-config.xml via classpath but I still have the same issue and erro message.
Comment: In intellij in the Project structure>Modules you have a "Sources" tab. In this tab you can see the source folders at the left and on the right side the module structures. To add a new source folder, right click on the folder to add and click on the Sources entry - there is a button on the top of the right pane called Sources to do the same thing
Comment: Yes, after I have changed code as you said, I am starting get another exception: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ExampleDao' is defined

But it is the another issue and I should find another answer. Thanks for your help.
Comment: The class ExempleDao must be a spring bean to use the annotation @Autowired on the datasouce variable.
Answer:
class path resource [jdbc-config.xml] cannot be opened because it does
  not exist

Is the file name correct, where is it located? the file specifying the db connection is not where you said it should be - on the classpath.
Comment: Thank you. Could you explain how add this files in classpath? It is not the same such classpath for jdk, right?

Spring: How to define database config?


How to create menuitem (?) in Xamarin forms?

Question: I just have a quick question on where i can find documentation about a view like this below that i see on a lot of different for example iOS apps:

Is there a sample project or documentation somewhere on how to implement it in xamarin forms? Perhaps this isn't possible but is there a similiar option out there for Xamarin forms development?
Comment: Do you want popup menu like this or toolbar? If there is only 2 options you might use switch
Comment: I would prefer a popup menu similiar to the image i posted. A switch is also possible of course but i want text on each option
Comment: Why don't you use ContentView? You can then either make it modal or just add to Children on page you need
Answer: This is a segmented control. There is no default support for it in Xamarin.Forms, probably because it isn't a control that is common on all three platforms.
There are a few ways about this if you still want to use it. Which basically break down to two scenarios: you either use the real native control and have to create different views for iOS and the other platforms you want to use. Or you simulate the segmented control with for instance the FreshEssentials NuGet by Michael Ridland. There are more of them out there.
If you choose the latter implementation will be easy and can be done right from XAML.
If you choose the first option you can either do it with a custom renderer or with the Native Embedding (Xamarin.Forms 2.2.0+) features. I have written a blogpost about it, but here are the basics. I am assuming you are using XAML to model your interface.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:EmbedNativeAwesomeness"
    xmlns:ios="clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS"
    x:Class="EmbedNativeAwesomeness.EmbedNativeAwesomenessPage">

</ContentPage>

First add the ios namespace declaration to your page. Notice how it has a targetPlatform tag in it, which means this will only be included when the iOS project is targeted.
Now, with the ios: prefix you can access all the iOS platform controls directly in Forms, in XAML.
So declaring the Segmented Control would probably be something like: <ios:UISegmentedControl /> and specifying the right properties to your needs.
There are some drawbacks to this method right now, but I'm sure you can work around it. For more info check my blogpost (and accompanying sample code) or some more resources here.
Comment: Thanks a lot for this :) Just what I was looking for. Will check it out straight away


How can i fix image width

Question: Here is a script for blog auto read more. I have given value in script for img thumb height and width but it is not applying it on my blog. anyone help me..
Here is my blog link.
My Blogger Tricks

Answer: The reason is CSS rule you have there setting image height to auto, see below:
.post img {height:auto;}

How can i fix image width


How to Execute these statements given beolw as a script in SQL*Plus, not as stored procedure

Question: PROCEDURE SP_PROCESS_RATE_PLAN IS
           var_cursor INTEGER;
           prv_rp_update_sql VARCHAR2(4000);
           prv_rp_insert_sql VARCHAR2(4000);
           v_Dummy INTEGER;
           SQL_STATEMENT VARCHAR2(400);
           /* Massage the data into the Rate_Plan table */
           BEGIN

               /*Trigger is dropped and recreated for table PRICEVIEW_RATE_PLAN_PROC */

             EXECUTE IMMEDIATE 'DROP TRIGGER RATE_PLAN_ID_TRIGGER';

             EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER RATE_PLAN_ID_TRIGGER
             before insert on priceview_rate_plan_proc
             for each row
             begin
             select RATE_PLAN_ID_SEQ.nextval into :new.rate_plan_id from dual;
             end;';

                        /* Update the Rate_Period to the same value for all rate_periods*/
                        prv_rp_update_sql:= 'UPDATE  RATE_USAGE_OVERRIDES a
            SET       a.rate_period = ''0''
            WHERE    a.seqnum  NOT IN (SELECT /*+ use_hash(rate_usage_overrides) */
                                                           a.seqnum
                                FROM rate_usage_overrides b
                                WHERE a.type_id_usg = b.type_id_usg
                                AND a.element_id = b.element_id
                                AND a.jurisdiction = b.jurisdiction
                                AND a.provider_class = b.provider_class
                                AND a.corridor_plan_id = b.corridor_plan_id
                                AND ( a.FIXED_CHARGE_AMT <> b.FIXED_CHARGE_AMT
                                        OR  a.ADD_FIXED_AMT <> b.ADD_FIXED_AMT
                                                                        OR a.ADD_UNIT_RATE <> b.ADD_UNIT_RATE )
                                                                AND DECODE(a.INACTIVE_DT,NULL,''00/00/0000'',a.INACTIVE_DT) = DECODE(b.INACTIVE_DT,NULL,''00/00/0000'',b.INACTIVE_DT)
                                                                AND a.ACTIVE_DT = b.ACTIVE_DT )

                AND
                                                                (SELECT count(*) from RATE_USAGE_OVERRIDES c
                                                                 WHERE
                                                                         a.type_id_usg = c.type_id_usg
                                 AND a.element_id = c.element_id
                                 AND a.jurisdiction = c.jurisdiction
                                 AND a.provider_class = c.provider_class
                                 AND a.corridor_plan_id = c.corridor_plan_id
                                 AND a.FIXED_CHARGE_AMT = c.FIXED_CHARGE_AMT
                                 AND a.ADD_FIXED_AMT = c.ADD_FIXED_AMT
                                                         AND DECODE(a.INACTIVE_DT,NULL,''00/00/0000'',a.INACTIVE_DT) = DECODE(c.INACTIVE_DT,NULL,''00/00/0000'',c.INACTIVE_DT)
                                                         AND a.ACTIVE_DT = c.ACTIVE_DT
                                 AND a.ADD_UNIT_RATE = c.ADD_UNIT_RATE) > 1';

                        var_cursor := DBMS_SQL.OPEN_CURSOR;
                        DBMS_SQL.PARSE(var_cursor,prv_rp_update_sql,DBMS_SQL.V7);

                v_Dummy:= DBMS_SQL.EXECUTE(var_cursor);
                DBMS_SQL.CLOSE_CURSOR(var_cursor);

             COMMIT;

                        LOCK TABLE PRICEVIEW_RATE_PLAN_PROC IN EXCLUSIVE  MODE;

                        /* Insert the Rate_Plan data */

                        prv_rp_insert_sql := 'insert into PRICEVIEW_RATE_PLAN_PROC
                                 (SSR_CODE,
                                 CORRIDOR_PLAN_ID,
                                 CORRIDOR_PLAN_DESCRIPTION,
                                 USAGE_TYPE,
                                 PRODUCT,
                                 JURISDICTION,
                                 PROVIDER,
                                 RATE_PERIOD,
                                 FLAGFALL,
                                 RATE,
                                 RATEBAND,
                                 NUMSECS,
                                 BAND_RATE,
                                 ACTIVE_DT,
                                 INACTIVE_DT)
                                 select /*+ use_hash(rate_usage_overrides,corridor_plan_id_values,product_elements,descriptions,jurisdictions,rate_usage_bands_overrides) */
                                 distinct
                                 decode(a.corridor_plan_id,0, '''', (select c.short_display from corridor_plan_id_values c where a.corridor_plan_id = c.corridor_plan_id)) AS SSR_CODE,
                                 a.corridor_plan_id AS CORRIDOR_PLAN_ID,
                                 decode(a.corridor_plan_id,0, '''', (select d.display_value from corridor_plan_id_values d where a.corridor_plan_id = d.corridor_plan_id)) AS CORRIDOR_PLAN_DESCRIPTION,

                                 decode(a.type_id_usg,0, '''', (select f.description_text from usage_types e, descriptions f where a.type_id_usg = e.type_id_usg and e.description_code = f.description_code)) AS USAGE_TYPE,

                                 decode(a.element_id,0, '''', (select h.description_text from product_elements g,descriptions h where a.element_id = g.element_id and g.description_code = h.description_code)) AS PRODUCT,

                                 decode(a.jurisdiction,0, '''', (select j.description_text from jurisdictions i,descriptions j where a.jurisdiction = i.jurisdiction and j.description_code = i.description_code)) AS JURISDICTION,

                                 decode(a.provider_class,0, '''', (select k.display_value from provider_class_values k where a.provider_class = k.provider_class)) AS PROVIDER,
                                 decode(a.rate_period,''0'', '''',(select l.display_value from rate_period_values       l where a.rate_period = l.rate_period)) AS RATE_PERIOD,
                                 (a.FIXED_CHARGE_AMT/100) + (a.ADD_FIXED_AMT/10000000) AS FLAGFALL,
                                 (a.ADD_UNIT_RATE/10000000) * 60 AS RATE,
                                 b.RATEBAND AS RATEBAND,
                                 b.NUM_UNITS AS NUMSECS,
                                 (b.UNIT_RATE/10000000) * 60 AS BAND_RATE,
                                 a.ACTIVE_DT AS ACTIVE_DT,
                                 a.INACTIVE_DT AS INACTIVE_DT
                                 from rate_usage_overrides a,
                                 rate_usage_bands_overrides b
                                 where a.seqnum = b.seqnum(+)';

            var_cursor := DBMS_SQL.OPEN_CURSOR;

                DBMS_SQL.PARSE(var_cursor,prv_rp_insert_sql,DBMS_SQL.V7);

                v_Dummy:= DBMS_SQL.EXECUTE(var_cursor);

                DBMS_SQL.CLOSE_CURSOR(var_cursor);

                         COMMIT;

                         /* Create the indexes */
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_RATE_PLAN_ID';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_USAGE_TYPE';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_CORRIDOR_PLAN_ID';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_SSR_CODE';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_PROD';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_JURIS';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_JURIS_PROV';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_PD_JR_PV';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_PROD_JURIS';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_PROD_PROV';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_PROV';

                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_CORRIDOR_PLAN_ID ON PRICEVIEW_RATE_PLAN_PROC(CORRIDOR_PLAN_ID, USAGE_TYPE) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE UNIQUE INDEX RRP_RATE_PLAN_ID ON PRICEVIEW_RATE_PLAN_PROC(RATE_PLAN_ID) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_SSR_CODE ON PRICEVIEW_RATE_PLAN_PROC(SSR_CODE) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_USAGE_TYPE ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_PROD ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, PRODUCT) TABLESPACE PRV_Index  STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_JURIS ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, JURISDICTION) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_JURIS_PROV ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, JURISDICTION, PROVIDER) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_PD_JR_PV ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, PRODUCT, JURISDICTION, PROVIDER) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_PROD_JURIS ON  PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, PRODUCT, JURISDICTION) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_PROD_PROV ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, PRODUCT, PROVIDER) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_PROV ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, PROVIDER)  TABLESPACE PRV_Index  STORAGE( PCTINCREASE 0 )';

                         /* Cut over to the new tables */
                         LOCK TABLE PRICEVIEW_RATE_PLAN IN EXCLUSIVE  MODE ;

                         EXECUTE IMMEDIATE 'ALTER TABLE PRICEVIEW_RATE_PLAN RENAME TO PRICEVIEW_RATE_PLAN_X';
                         EXECUTE IMMEDIATE 'ALTER TABLE PRICEVIEW_RATE_PLAN_PROC RENAME TO PRICEVIEW_RATE_PLAN';
                         EXECUTE IMMEDIATE 'ALTER TABLE PRICEVIEW_RATE_PLAN_X RENAME TO PRICEVIEW_RATE_PLAN_PROC';

                         /* Remove the old data */
                         EXECUTE IMMEDIATE 'TRUNCATE TABLE PRICEVIEW_RATE_PLAN_PROC';

                END SP_PROCESS_RATE_PLAN;

END PRICEVIEW_PROCESS_EXTRACT;

I am new to SQL , so no Idea about the above code so I need help in converting this procedure to SQl script
Comment: what do you mean by **not as stored procedure** ?
Comment: not as stored procedure mean , all the above query shoyuld be written in SQl query itseems.
Comment: can we use SET NOCOUNT ON query before stored procedure
Comment: because the above stored procedure is taking a lot of time approximately 22 hrs to get executed ...so need help in this to reduce execution of stored procedure script.
Comment: Query optimization depends on the number of records and type of join. This is not that simple as you are doing lots of stuffs inside your procedure.
Answer: It might work
declare
           var_cursor INTEGER
           prv_rp_update_sql VARCHAR2(4000)
           prv_rp_insert_sql VARCHAR2(4000)
           v_Dummy INTEGER
           SQL_STATEMENT VARCHAR2(400)
           /* Massage the data into the Rate_Plan table */
           BEGIN

               /*Trigger is dropped and recreated for table PRICEVIEW_RATE_PLAN_PROC */

             EXECUTE IMMEDIATE 'DROP TRIGGER RATE_PLAN_ID_TRIGGER';

             EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER RATE_PLAN_ID_TRIGGER
             before insert on priceview_rate_plan_proc
             for each row
             begin
             select RATE_PLAN_ID_SEQ.nextval into :new.rate_plan_id from dual;
             end;';

                        /* Update the Rate_Period to the same value for all rate_periods*/
                        prv_rp_update_sql:= 'UPDATE  RATE_USAGE_OVERRIDES a
            SET       a.rate_period = ''0''
            WHERE    a.seqnum  NOT IN (SELECT /*+ use_hash(rate_usage_overrides) */
                                                           a.seqnum
                                FROM rate_usage_overrides b
                                WHERE a.type_id_usg = b.type_id_usg
                                AND a.element_id = b.element_id
                                AND a.jurisdiction = b.jurisdiction
                                AND a.provider_class = b.provider_class
                                AND a.corridor_plan_id = b.corridor_plan_id
                                AND ( a.FIXED_CHARGE_AMT <> b.FIXED_CHARGE_AMT
                                        OR  a.ADD_FIXED_AMT <> b.ADD_FIXED_AMT
                                                                        OR a.ADD_UNIT_RATE <> b.ADD_UNIT_RATE )
                                                                AND DECODE(a.INACTIVE_DT,NULL,''00/00/0000'',a.INACTIVE_DT) = DECODE(b.INACTIVE_DT,NULL,''00/00/0000'',b.INACTIVE_DT)
                                                                AND a.ACTIVE_DT = b.ACTIVE_DT )

                AND
                                                                (SELECT count(*) from RATE_USAGE_OVERRIDES c
                                                                 WHERE
                                                                         a.type_id_usg = c.type_id_usg
                                 AND a.element_id = c.element_id
                                 AND a.jurisdiction = c.jurisdiction
                                 AND a.provider_class = c.provider_class
                                 AND a.corridor_plan_id = c.corridor_plan_id
                                 AND a.FIXED_CHARGE_AMT = c.FIXED_CHARGE_AMT
                                 AND a.ADD_FIXED_AMT = c.ADD_FIXED_AMT
                                                         AND DECODE(a.INACTIVE_DT,NULL,''00/00/0000'',a.INACTIVE_DT) = DECODE(c.INACTIVE_DT,NULL,''00/00/0000'',c.INACTIVE_DT)
                                                         AND a.ACTIVE_DT = c.ACTIVE_DT
                                 AND a.ADD_UNIT_RATE = c.ADD_UNIT_RATE) > 1';

                        var_cursor := DBMS_SQL.OPEN_CURSOR;
                        DBMS_SQL.PARSE(var_cursor,prv_rp_update_sql,DBMS_SQL.V7);

                v_Dummy:= DBMS_SQL.EXECUTE(var_cursor);
                DBMS_SQL.CLOSE_CURSOR(var_cursor);

             COMMIT;

                        LOCK TABLE PRICEVIEW_RATE_PLAN_PROC IN EXCLUSIVE  MODE;

                        /* Insert the Rate_Plan data */

                        prv_rp_insert_sql := 'insert into PRICEVIEW_RATE_PLAN_PROC
                                 (SSR_CODE,
                                 CORRIDOR_PLAN_ID,
                                 CORRIDOR_PLAN_DESCRIPTION,
                                 USAGE_TYPE,
                                 PRODUCT,
                                 JURISDICTION,
                                 PROVIDER,
                                 RATE_PERIOD,
                                 FLAGFALL,
                                 RATE,
                                 RATEBAND,
                                 NUMSECS,
                                 BAND_RATE,
                                 ACTIVE_DT,
                                 INACTIVE_DT)
                                 select /*+ use_hash(rate_usage_overrides,corridor_plan_id_values,product_elements,descriptions,jurisdictions,rate_usage_bands_overrides) */
                                 distinct
                                 decode(a.corridor_plan_id,0, '''', (select c.short_display from corridor_plan_id_values c where a.corridor_plan_id = c.corridor_plan_id)) AS SSR_CODE,
                                 a.corridor_plan_id AS CORRIDOR_PLAN_ID,
                                 decode(a.corridor_plan_id,0, '''', (select d.display_value from corridor_plan_id_values d where a.corridor_plan_id = d.corridor_plan_id)) AS CORRIDOR_PLAN_DESCRIPTION,

                                 decode(a.type_id_usg,0, '''', (select f.description_text from usage_types e, descriptions f where a.type_id_usg = e.type_id_usg and e.description_code = f.description_code)) AS USAGE_TYPE,

                                 decode(a.element_id,0, '''', (select h.description_text from product_elements g,descriptions h where a.element_id = g.element_id and g.description_code = h.description_code)) AS PRODUCT,

                                 decode(a.jurisdiction,0, '''', (select j.description_text from jurisdictions i,descriptions j where a.jurisdiction = i.jurisdiction and j.description_code = i.description_code)) AS JURISDICTION,

                                 decode(a.provider_class,0, '''', (select k.display_value from provider_class_values k where a.provider_class = k.provider_class)) AS PROVIDER,
                                 decode(a.rate_period,''0'', '''',(select l.display_value from rate_period_values       l where a.rate_period = l.rate_period)) AS RATE_PERIOD,
                                 (a.FIXED_CHARGE_AMT/100) + (a.ADD_FIXED_AMT/10000000) AS FLAGFALL,
                                 (a.ADD_UNIT_RATE/10000000) * 60 AS RATE,
                                 b.RATEBAND AS RATEBAND,
                                 b.NUM_UNITS AS NUMSECS,
                                 (b.UNIT_RATE/10000000) * 60 AS BAND_RATE,
                                 a.ACTIVE_DT AS ACTIVE_DT,
                                 a.INACTIVE_DT AS INACTIVE_DT
                                 from rate_usage_overrides a,
                                 rate_usage_bands_overrides b
                                 where a.seqnum = b.seqnum(+)';

            var_cursor := DBMS_SQL.OPEN_CURSOR;

                DBMS_SQL.PARSE(var_cursor,prv_rp_insert_sql,DBMS_SQL.V7);

                v_Dummy:= DBMS_SQL.EXECUTE(var_cursor);

                DBMS_SQL.CLOSE_CURSOR(var_cursor);

                         COMMIT;

                         /* Create the indexes */
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_RATE_PLAN_ID';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_USAGE_TYPE';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_CORRIDOR_PLAN_ID';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_SSR_CODE';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_PROD';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_JURIS';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_JURIS_PROV';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_PD_JR_PV';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_PROD_JURIS';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_PROD_PROV';
                         EXECUTE IMMEDIATE 'DROP INDEX RRP_UT_PROV';

                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_CORRIDOR_PLAN_ID ON PRICEVIEW_RATE_PLAN_PROC(CORRIDOR_PLAN_ID, USAGE_TYPE) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE UNIQUE INDEX RRP_RATE_PLAN_ID ON PRICEVIEW_RATE_PLAN_PROC(RATE_PLAN_ID) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_SSR_CODE ON PRICEVIEW_RATE_PLAN_PROC(SSR_CODE) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_USAGE_TYPE ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_PROD ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, PRODUCT) TABLESPACE PRV_Index  STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_JURIS ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, JURISDICTION) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_JURIS_PROV ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, JURISDICTION, PROVIDER) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_PD_JR_PV ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, PRODUCT, JURISDICTION, PROVIDER) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_PROD_JURIS ON  PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, PRODUCT, JURISDICTION) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_PROD_PROV ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, PRODUCT, PROVIDER) TABLESPACE PRV_Index STORAGE( PCTINCREASE 0 )';
                         EXECUTE IMMEDIATE 'CREATE INDEX RRP_UT_PROV ON PRICEVIEW_RATE_PLAN_PROC(USAGE_TYPE, PROVIDER)  TABLESPACE PRV_Index  STORAGE( PCTINCREASE 0 )';

                         /* Cut over to the new tables */
                         LOCK TABLE PRICEVIEW_RATE_PLAN IN EXCLUSIVE  MODE ;

                         EXECUTE IMMEDIATE 'ALTER TABLE PRICEVIEW_RATE_PLAN RENAME TO PRICEVIEW_RATE_PLAN_X';
                         EXECUTE IMMEDIATE 'ALTER TABLE PRICEVIEW_RATE_PLAN_PROC RENAME TO PRICEVIEW_RATE_PLAN';
                         EXECUTE IMMEDIATE 'ALTER TABLE PRICEVIEW_RATE_PLAN_X RENAME TO PRICEVIEW_RATE_PLAN_PROC';

                         /* Remove the old data */
                         EXECUTE IMMEDIATE 'TRUNCATE TABLE PRICEVIEW_RATE_PLAN_PROC';

end;
/
Comment: I didnot get you..the same query i have inserted so wat us the difference in my query and yours?
Comment: @gangas I removed procedure and I include begin
Answer: Can you not just execute the procedure from SQL*Plus  ?
BEGIN
  execute  PRICEVIEW_PROCESS_EXTRACT.SP_PROCESS_RATE_PLAN;
END;

This makes the assumption that

The package PRICEVIEW_PROCESS_EXTRACT has a definition of the SP_PROCESS_RATE_PLAN in the PACKAGE SPEC so it can be called from outside the package.
You are either the owner of the package or you have been granted execute on the procedure

If not, then can you add it to the package specification and have the grant made ?
Comment: CAn ANYONE answer this query?
Comment: it tells PRICEVIEW_PROCESS_EXTRACT package is invalid.
Answer: There are many factors, which affects query performance :

Network traffic
Table JOINS
Number of records in each tables.
Indexing and many more...

I can see inside your procedure, you are executing lot of DDLand DML queries, which definitely impact procedure performance.
What you can do is, you can execute each DDL and DML query individually and see, which query taking longer time. If you were able to find out that query, which impacting the procedure performance. Then, you can analyze the query and related tables for better performance. Also, remove unnecessary code like dropping/creating trigger (It's not good idea to use trigger as temporary objects, since you are creating and dropping the trigger in each procedure execution).
Comment: Actually I didnot understand your point fo view. so little skeptical about the solutino u have given
Comment: what is not clear ? I have already mentioned the factors, which affects performance. Also, I have pointed out reason in your procedure, which probably improve overall performance. Now, what else you wanted like to know  ?
Comment: Since I am a front end developer..no idea about this sql, since i have to solve this issue , so cant understand what changes to be done.i tried executing all the querys individually, everything is taking 30 mins..and if i delete alll those trigger statements doesnt it affect the script.
Comment: I am bothering you.. i am sorry, but i am in very needy help from you.
can you tell me how to replace above given  stored procedure with plain SQL in a script .my mail id is email@example.com


List comprehension in python with numbering

Question: Suppose I have the following list:
temp = ['Ok', 'Whoa. Robot?']

How do I get a string that looks like
"1) 'Ok', 2) 'Whoa. Robot?'"

I'm trying to do this for a list comprehension. I can obviously join them using:
" ".join(temp)

I can do it in a loop in a fairly ugly way:
mystring = ""
temp = ['Ok', 'Whoa. Robot?']
for i in range(len(temp)):
    mystring += str(i) + ") " + temp[i] + "  "

Is there a pythonic way to do it in one step with a list comprehension?
Answer: mystring = ', '.join(["{}) {!r}".format(i, s) for i, s in enumerate(temp, 1)])

The {!r} conversion produces the repr() representation of the string, so you get quotes around the parts, but note that the quotes may change depending on the string's content, or in other words if it contains quotes itself.
Comment: @James See e.g. [this thread](https://stackoverflow.com/questions/37782066/list-vs-generator-comprehension-speed-with-join-function). `str.join` is one of the functions that are faster with lists than with generators.
Comment: You don't need the list comp brackets inside of the `join`.  It will evaluate the generator.


Statistically significant differences, when sample is not normal.

Question: I have two sample which doesn't comes from normally distributions. How to analyse whether there are statistically significant differences ?
Comment: There are **very many** ways for a distribution to be **not normal**.  You wouldnt expect us to be able to say much about a number from tha fact that **it is no zero**, and your question is equivalent. Please augment!
Answer: In special situations, you can still do exact inference. However, if you're looking for general approaches, then you can try:

Nonparametric tests and confidence intervals (there are TONS of methods in this class that do not depend on normality)
Bootstrapping (parametric or nonparametric)
Likelihood-iterval-based
Bayesian inference

So, you have a lot of areas to look into. Normal-based stats is "classical" stats, and these have been shown to be broadly useful even when the underlying distribution is known to be very non-normal.


Isometry of two Euclidean structures on the same vector bundle

Question: I'm reading Milnor & Stasheff's Characteristic Classes, and I was struck by the following problem, which they call the Isometry Theorem:
"Let $\mu$ and $\mu'$ be two different Euclidean metrics on the same vector bundle $\xi$. Prove that there exists a homeomorphism $E(\xi) \rightarrow E(\xi)$ (i.e. of the total space) which carries each fiber isomorphically onto itself such that $\mu \circ f = \mu'$."
The hint for the problem suggests using the square root of a matrix and sketches a proof that the map $A \mapsto \sqrt{A}$ is smooth. I don't see the relevance of square roots anywhere.
My attempt at a proof is to say that between if $M, N$ are two positive definite matrices, then $M = {^{t}A} N A$ for some invertible matrix $A$, and then define the isomorphism of vector bundles on each stalk by $A$. What's wrong with this attempt? Where do square roots come in?
EDIT:
Thinking about this question raised another worry: why doesn't this result show that any two Riemannian metrics on the same space are isometric? If I'm remembering correctly, the only extra requirement we need there is that the map depend smoothly on the stalk, which the exercise in Milnor/Stasheff claims is true for square roots.
Comment: Regarding your edit: remember that an isometry of Riemannian manifolds is, in particular, a diffeomorphism of Riemannian manifolds $f: X \to Y$ that pulls back the latter's metric to the first. What happens on the Riemannian structure on the tangent bundle, then, is just $df$. The construction you're doing here is a vector bundle automorphism - it's not just $df$ where $f$ is the map $X \to X$ it lies over. If you could show that the $f: TX \to TX$ you're constructing was of the form $dg$ for some $g: X \to X$, that would show all Riemannian metrics were isometric. Of course, you can't.
Comment: There are $O(n)$ many such $A$, and no (obvious) canonical one. You have to pick $A$ in a continuous fashion. Locally, this is fine; but there's no obvious reason you should be able to globally patch together your local choices. The point of the square root business is that it allows you to pick an $A$ canonically, in a fashion that continuously depends on the stalk.
Answer: Note that every positive definite map $\mu$ can be written uniquely as square of $\sqrt \mu$, i.e. $\mu=\sqrt \mu \sqrt \mu$.
If $\mu'$ is another positive definite map, then we want a positive definite map $M:E(\xi) \to E(\xi)$ which gives us an isometry. The isometry will be in fact the square root $\sqrt M$ of the following composition $M$:
Let $b_\mu :E(\xi) \to E(\xi)^*$ the map which sends a vector $v$ to the linear map $\mu(v,\cdot)$. Very basic linear algebra tells you this is an isomorphism, hence you can try to compose $b_\mu$ and $b_{\mu'}$ to get the map $M$. Intuitively speaking, you will go to the dual by applying $\mu'$ and going back by $\mu$, and the resulting isomorphism will 'measure the difference'.
Edit: To answer the commented questions: we need the square root of $M$ in the first place because of the bilinearity and our wish that $\mu'(\sqrt M v, \sqrt M w) = \mu (v,w)$. So you also see here how you want to define the square root obviously. To make this precise you could note that the function on $n$-matrices $M \mapsto M^2$ restricts to a function on the space of positive definite $n$-matrices to ifself. You want to show that it actually restricts to a homeomorphism, i.e. that we have an inverse map
$$
\{\text{positive definite $n$-matrices}\} \stackrel {((\cdot)^2)^{-1}}\to \{\text{positive definite $n$-matrices}\} \subset GL_n(\mathbb R)
$$
which gives us the square root map.

Note that this is not a complete proof, since your question was only about how square roots come into play here. Note also, that most of the work is linear algebra, but to translate it to vector bundles you need to worry a little about continuity.
$$
\sqrt{M: E(\xi) \stackrel {b_{\mu'}} \to E(\xi)^* \stackrel {b_\mu} \to E(\xi)}
$$
Comment: I'm still a little confused on how the square roots work - why doesn't $M$ just give you what you want? Also, is the square root with respect to multiplication of matrices (i.e. composition) or with respect to pointwise multiplication in the target?
Comment: I edited my post to answer your questions.
Comment: I apologize, but there's something (probably silly) I'm still not getting - I don't see how the relation $\sqrt{M} \circ \sqrt{M} v =  Mv$ is the same as $\mu'(\sqrt{M} v, \sqrt{M} w) = \mu(v,w)$ $\mu'$ is linear, but it doesn't make sense to pull the matrices out of $\mu'$, does it? (since then everything is just one dimensional)


java.security.PrivilegedActionException while hitting webservices over https

Question: I am getting the following exception, when i am trying to hit the webservice over https  using java client:
com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection post
SEVERE: SAAJ0009: Message send failed
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: java.security.PrivilegedActionException: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Message send failed
    at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:157)
    at
Also if i use the same code for http , it works fine. Webservices are deployed on weblogic server.
Could anyone help me in resolving the issue.
Regards
Gurleen.
Answer: The exception says that message cannot be sent.
Is it a firewall problem like for the same question here : http://www.coderanch.com/t/223309/Web-Services/java/Sending-Soap-requests-thru-Https