Is drush required on the remote server to do sql-sync or rsync operations?

Question: I am working my way through the Drush chapter in Definitive Guide to Drupal 7 by Apress. I want to sync the mysql database and files to/from my local MAMP developer stack and the remote live server (shared hosting).
Given that the drush rync commands deal with the files and the database, then surely it is not necessary to have to have drush on the remote server? If it has to be on the remote server the I accept that but please explain why. I do appreciate that other drush operations would require it e.g. core-status though but the aforementioned operations I am doing involve just the drupal code and database not anything to do with drush.
Please advise, guides don't state everything and make assumptions sometimes.
Answer: Drush is needed on the remote server only to fetch the database credentials for the remote system.  If you declare your databases array in the site alias for your remote systems, then Drush will not need to have Drush installed on the remote machine to work.
I don't remember if I explained this in detail in the book, but there is an example on how to define database records in aliases in the example alias configuration file, example.aliases.drushrc.php.  Also, try running drush @site sa --with-db to see the whole site alias record for the given site with the databases array included.  This won't help you if Drush is not installed on the system where the site is installed, but you can run it on a local site, and edit the result to match the necessary settings for the remote end.
Comment: Thanks @greg_1_anderson I just tried to drush sync and drush sql-sync to my remote shared hosting and they seem like they could work. I say seem because I get errors with the file sync and I think that is because I am sync to the wrong place on the remote machine (should be solvable) and errors with the sql sync where it can't connect to my local sql (again resolvable but I'm using homebrew as a shell and MAMP as for a local dev stack and I think an issue maybe that there are 2 installations of mysql and I would prefer to hook them up to be the same.
Comment: I've had to hack up my mac a lot so might switch to the drupal vagrant project and run it all within a Linux VM on my mac and ditch MAMP altogether - so that all this drush stuff will work.
Comment: Also some suggestions about errors in the Drupal 7 Definitive Guide Apress book, not sure if some revisions fix these: 1) In the drush chapter drush extras is mentioned: `Project drush_extras (7.x-4.0) downloaded to /home/user/.drush/drush_extras.` but there doesn't seem to be a 7.x-4.0 version on the drupal.org/project/drush_extras and drush itself only offers 7.x-1.x-dev 2) an "examples directory" is mentioned but nowhere does it say where this is - exact path on the local drush install would be useful or if it is a download to accompany the book.
Comment: I can accept your answer though: "f you declare your databases array in the site alias for your remote systems, then Drush will not need to have Drush installed on the remote machine to work." I have created an alias file on my local machine here: /Users/robertdavis/.drush/aliases.drushrc.php and in it defined a `live` alias based on the example file on drush.org - I will also check out your example too.


why are Twig template variables with markup not being rendered?

Question: In my template preprocess function I have a variable:
$test = "
this is a paragraph
";

and I pass it to my template:
$variables['test'] = $test;

and output it in twig:
{{test}}

but instead of getting a formatted paragraph, I'm getting the original output in plain text:

this is a paragraph

How do I get Drupal to render this as normal HTML?
Answer: Because twig auto-escapes unsafe content and your content isn't marked as safe.
You can explicitly tell it that it is with $test = Markup::create($test); but you should be very careful with that. If it contains any sort of user input, you might open yourself for XSS issues.
Better approaches are using a render array like ['#markup' => 'your text'] which by default will allow a certain amount of html tags but not all of them. You can also use an inline template as documented here: https://www.drupal.org/node/2311123.
Twig natively understands render arrays, so it doesn't matter for your template if you provide a render array or a string.
Comment: I found that by using the raw filter, I get the output I need, so: {{test|raw }} gives 'this is a paragraph' without the markup.
Comment: ok, so raw is unsafe and I don't understand how I should use the example documentation you provided
Comment: Ok, with the help of some #drupal IRC idlers I found this: https://www.drupal.org/node/2296163 which contains a few options for outputting markup in twig.
Comment: In my example, I retrieved $test from a db query, and the field data was stored with markup (basic html ckeditor field), so the #markup method was the most relevant for this use case.
Comment: @RominRonin, just seen this comment. If this is data stored in a formatted text field this is a completely different question. Then #markup is unsafe. You have to render it with processed_text. See https://drupal.stackexchange.com/questions/223967/how-do-i-output-html-from-a-text-long-field-in-twig
Answer: These are two possibilities to wrap $test in a paragraph and pass it to the twig template:
$variables['test'] = [
  '#markup' => $test,
  '#prefix' => '
',
  '#suffix' => '
',
];

$variables['test'] = [
  '#type' => 'inline_template',
  '#template' => '
{{ text }}
',
  '#context' => [
    'text' => $test,
  ],
];

Comment: I was trying to create a render array in Twig to pass that to a sub-template via include. The Markup render array doesn't work, but the inline_template worked. Yea, seems like I need to pass the #allowed_tags too.


$\mathbb{Z}$-module homomorphism $\mathbb{Z}/(n)\to\mathbb{Z}$ is trivial

Question:
Show, that every $\mathbb{Z}$-module homomorphism $\mathbb{Z}/(n)\to\mathbb{Z}$ is trivial (hence identical 0)

Let $f:\mathbb{Z}/(n)\to\mathbb{Z}$ be a $\mathbb{Z}$-module homomorphism.
I have to show, that $f([m])=0$ for every $[m]\in\mathbb{Z}/(n)$
Can I do it like this:
If n=0 there is nothing to show. So $\mathbb{Z}\ni n\neq 0$.
Now, using that $f$ is a $\mathbb{Z}$-module homomorphism we get:
$1.~~~f([m]+n[m])=f((n+1)[m])=(n+1)f([m])$ and also:
$2.~~~f([m]+n[m])=f([m]+[nm])=f([m]+[0])=f([m])$
Hence: $f([m])=(n+1)f([m])=nf([m])+f([m])\Leftrightarrow nf([m])=0$
Since $n\neq 0$ it has to be $f([m])=0$ for every $[m]\in\mathbb{Z}/(n)$
Is this proof done correct, or am I missing something?
Thanks in advance.
Comment: Can you do this exercise if you replace "$\mathbb Z$-module homomorphism" with "group homomorphism" - which are here equivalent?
Comment: Well, it should be kinda the same: $0=f([0])=f([nm])=f([n][m])=nf([m])$, so $f([m])=0$, since $n\neq 0$
Answer: The first sentence is incorrect, since if $n=0$, $\mathbb{Z}/(n)$ is isomorphic to $\mathbb{Z}$, and then we have more than one homomorphism from $\mathbb{Z}$ to itself, the identity and the zero homomorphism are examples. I suppose we should assume $n \neq 0$. The rest of the proof is correct, but I would prove it like this. The idea is that in $\mathbb{Z}/(n)$ every element $x$ satisfies the relation
$$n\cdot x=0,$$
and since homomorphisms preserve all relations we have $n \cdot f(x)=0$ in $\mathbb{Z}$, which implies $f(x)=0$.
Comment: Thank you. So we need $n\neq 0$ as an assumption, since the question is not true else?
Comment: @Cornman Yes that's what I mean.


unable to fix the project ,gradle issue

Question: enter code hereunable to fix the project , new to android studio , need help fixing gradle my gradle file ,happening when i import projects from eclipse, exporting done fine
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}
apply plugin: 'com.android.application'

dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
    compile project(':ksoap2-android-assembly-2.5.8-jar-with-dependencies')
}

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        instrumentTest.setRoot('tests')

        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

and the error i am getting is
Error:Configuration with name 'default' not found.

changed code
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
 buildscript {
                repositories {
                    jcenter()
                }
                dependencies {
                    classpath 'com.android.tools.build:gradle:1.2.3'
                }
            }
            android {
                compileSdkVersion 23
                buildToolsVersion "23.0.1"

                defaultConfig {
                    applicationId "com.package.name"
                    minSdkVersion 11
                    targetSdkVersion 23
                    versionCode 1
                    versionName "1.0"
                }
                buildTypes {
                    release {
                        minifyEnabled false
                        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                    }
                }
            }
            apply plugin: 'com.android.application'

            dependencies {
                compile fileTree(include: '*.jar', dir: 'libs')
                compile project(':ksoap2-android-assembly-2.5.8-jar-with-dependencies')
            }

            android {
                compileSdkVersion 23
                buildToolsVersion "23.0.1"

                defaultConfig {
                    applicationId "com.package.name"
                    minSdkVersion 11
                    targetSdkVersion 23
                    versionCode 1
                    versionName "1.0"
                }
                buildTypes {
                    release {
                        minifyEnabled false
                        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                    }
                }

                sourceSets {
                    main {
                        manifest.srcFile 'AndroidManifest.xml'
                        java.srcDirs = ['src']
                        resources.srcDirs = ['src']
                        aidl.srcDirs = ['src']
                        renderscript.srcDirs = ['src']
                        res.srcDirs = ['res']
                        assets.srcDirs = ['assets']
                    }

                    // Move the tests to tests/java, tests/res, etc...
                    instrumentTest.setRoot('tests')

                    // Move the build types to build-types/<type>
                    // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
                    // This moves them out of them default location under src/<type>/... which would
                    // conflict with src/ being used by the main source set.
                    // Adding new build types or product flavors should be accompanied
                    // by a similar customization.
                    debug.setRoot('build-types/debug')
                    release.setRoot('build-types/release')
                }

            }

Comment: this is usually a project settings.gradle error - most likely gradle can't find one of the dependencies there or a dependency in build.gradle because the settings is missing the proper reference to it. Post settings.gradle
Comment: Have you checked this? http://stackoverflow.com/questions/17188489/android-studio-gradle-configuration-with-name-default-not-found http://stackoverflow.com/questions/22743582/error-configuration-with-name-default-not-found-in-android-studio
Answer: Add the defaultConfig into the android block
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.package.name"
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

EDIT 1 : The android part of your gradle file should be inside the applications build.gradle not in the projects root gradle
There are two gradle files
Here is a sample Root Project Gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-alpha1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Sample Module Gradle file
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.package.name"
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.android.support:cardview-v7:23.1.1'
}

Comment: tried the code,         respone            Error:(10, 0) Gradle DSL method not found: 'defaultConfig()'
Possible causes:The project 'Wafi_Smt_24_Nov_15' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
Comment: added sample gradle for your reference
Comment: can u post both of your gradle files..?
Comment: Canary 4 was known to introduce some bugs for Instant Apps development.
Please see whether Canary 5 fixes the problems you've been experiencing.

unable to fix the project ,gradle issue


Jquery: Append array elements to div

Question: Jquery:
$(document).on('click', '.customers__photo', function(){

  let img_array = $(this).children().attr('src').ToArray();
  img_array.forEach(function (src) {
    $(".pushed").append('');
   });
})

HTML:

How can I get children's only src attribute value and append image with these src values to div?
Answer: You can do it like this:
$(document).on('click', '.customers__photo', function() {

  let img_array = $(this).children().map(function()  {return $(this).attr("src")}).get();
  img_array.forEach(function(src) {
    $(".pushed").append(`<img src="${src}" class="reviews__photo">`);
  });
})

Demo

$(document).on('click', '.customers__photo', function() {

  let img_array = $(this).children().map(function() {
    return $(this).attr("src")
  }).get();
  img_array.forEach(function(src) {
    $(".pushed").append(`<img src="${src}" class="reviews__photo">`);
  });
})

Comment: How did You do that?)))))
Comment: How can I know which function can I use after one?
Comment: Where can I read exctly about this example?
Comment: @AzizxonZufarov you can read more here https://api.jquery.com/jquery.map/
Comment: What about : How can I know which function can I use after other? Is there any jquery object model tree?
Comment: @AzizxonZufarov Not really, you just learn by experiance
Comment: I have forgotten one div please can You rewrite code for me? Look to html

Jquery: Append array elements to div


Why is there a gap in pole-vault records starting in 1994 and resuming as of 2020?

Question: Looking at the Men's pole vault world record progression on Wikipedia, the record advances fairly regularly starting in the late '50 up through 1994. There are no new records until 2014, and then the record goes back to being broken fairly regularly since 2020 (with a small pandemic gap for 2021). Why is there such a large gap after 1994?
One observation of note is that often the same name appears many times in the records, so the overall regularity might be due in part to athletes regularly beating their own records over their careers as they grow longer.
Answer: As with most sports, you can argue that the athletes have been getting better over the years and decades. They have better form and technique, are more specialized in what they do and tend to stick to a sport from a younger age, have access to better nutrition, and with modern sponsorship they can fully focus on their sports. Based on these factors one expects records to improve over the years, until a human productivity plateau is reached under the rules of a sport, which can cause stagnation of new records, or the rate at which they're set.
There are also other factors that can effect the rate of new records; we'll focus on technology. In a different sport for example, the Fastskin swimming suit resulted in many swimming records being broken. But eventually the technology was banned, considered "technology doping" as it gave advantage to those swimmers who wore them. Change in technology can also lower/decrease the records. For example after Uwe Hohn's javelin throw of over 100m, the javelin was redesigned to be thrown shorter on purpose, as athletes were starting to throw it far enough that it was becoming dangerous for the other events happening on the track.
Technology may have had the greatest impact on Pole Vault when it comes to improvements. You can read about the evolution of the poles here. Poles have changes from stiff wood, to slightly bendable bamboo, to steel and aluminum, to carbon fiber these days. I personally don't follow pole vault enough, but suspect even the fiber carbon technology has had improvements over the years. The jumpers get their energy to gain vertical distance from their run up, so the better the pole can translate the horizontal energy of the athlete running towards the box, to vertical, the higher the athlete can jump. So with poles that more efficiently transfer the energy, we can expect the pole vault records to get better.
Furthermore, as you mentioned, the records plateaued after 1994. This is because Sergey Bubka was the best jumper at the time and pushed the records to the point no other could. He took it to the plateau point where we had to wait untill "better' suited athletes could make improvements.
The record was eventually broken by 2cm, but Bubka remained the most consistent high pole vaulter of all time. Only in summer of 2022, Mondo Duplantis managed to have more 6 meter jumps than Bubka. Having been born to parents who competed in athletics, and with great talent, Duplantis has already been improving world records since he was 20. He's now doing what Bubka did decades ago, pushing the world record higher few cm at a time.
Comment: It is still important to mention the pole went through a number of technological changes before settling on fiber glass. You are assuming the the OP and any reader already knows that the pole material changes a lot from the 50s (explicitly mentioned by OP) till the records stopped moving in the 90s.
Comment: This answer is not very helpful. The first paragraph restates the unmet expectation that the question is trying to recover from. It is clear that technology hasn't been the reason, since pole tech has not been through a significant change since fibre glass poles came in, it suggests we should expect the total opposite of what happened. If the last paragraph is to imply the 1994 record was just due to someone freakishly good and special, requiring an even more special athlete to overcome it, it could do so much more clearly.
Comment: Bubka also didn't seem to push the record any harder than previous record holders. While he almost singlehandedly pushed the record from 19 1 1/2 to 20 1 1/4, he did so over a 10-year period that matched the previous 10 years it took for a similar 1-foot increase in the record.
Comment: Bubka had an overwhelming dominance at the time and seemingly pushed the record at will. The reason his overall addition to the record over that time period may not look that impressive is his world record bonus deal with Nike. He got paid a bonus for breaking the world record. So to financially maximize his earnings he only pushed it 1 or 2cm at a time almost all the time. Had the world record bonus wasn't there, it's believed Bubka would've made that record progression in much faster time.


Apache RewriteCond RewriteRule combo assistance for HTTPS redirects

Question: Need some help for combining some RewriteRule's and RewriteCond's together and preventing redirect loops.
Case is to force all incoming requests to these patterns, to redirect to https:// with same pattern...
http://www.domain.com/admin --> https://www.domain.com/admin
http://www.domain.com/something/wp-login --> https://www.domain.com/something/wp-login
http://www.domain.com/something/wp-admin --> http://www.domain.com/something/wp-admin
http://www.domain.com/something/else/wp-login --> https://www.domain.com/something/else/wp-login
http://www.domain.com/something/else/wp-admin --> https://www.domain.com/something/else/wp-admin

But the real trick is that I'd like to accomplish this in the fewest statements. Here's what I have so far, but it's not quite right and creates redirect loops in the /admin cases and fails in the "wp-" cases.
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^(/admin|wp-login|wp-admin) [NC]
RewriteRule ^(.*)$ https://www.domain.com$1 [R,L]

Much obliged for any pointers here.
Cheers.
Comment: `RewriteRule ^/(.*)$ https://www.domain.com/$1 [R=301,L]`
Answer: The comment above helped get rid of the redirect loops. I also tried to simplify the preceding RewriteCond in a number of ways but couldn't get anything but the above to work.
For example..why doesn't the below RewriteCond do the same thing only more simply..
RewriteCond %{REQUEST_URI} ^/(.*)admin/?$ [NC]

Seems to me that should be a true condition for all of the following...
http://domain.com/admin
http://domain.com/admin/
http://domain.com/whatever/wp-admin
http://domain.com/whatever/wp-admin/
http://domain.com/whatever/somethingelse/wp-admin
http://domain.com/whatever/somethingelse/wp-admin/

But for some reason the wp- urls don't match that condition/pattern.


Is it better to play the keyboard standing or sitting?

Question: I recently purchased a Yamaha FC7 foot pedal. I plan to use it for overall volume control, emphasizing breaks and solos. This poses a challenge, though, as I normally stand when playing the keyboard. It is possible but feels a little awkward and tiring to stand mostly on the foot that I sustain with keeping the other foot on the volume control.
So, my question is, it is better to stand or sit? My biggest concern is if it appears better to the audience to stand. I'm confident I can I figure out a way to stand (it is my preference), but if there really aren't any advantages to standing, it would obviously be easier to play sitting (which could have another advantage of helping being relaxed when playing).
Are there better ways to manage two pedals?
Answer: It will always be easier to sit and operate pedals - the required uneven shift in weight from one foot to the other and holding it for extended periods can become quite tiring.
If your biggest concern is how it looks to the audience then yes, you'll probably have to put up with the discomfort and awkward stance of standing but there are a couple of things you can do to help:

Make sure the keyboard is set at a comfortable height (certainly don't leave it at sitting height!) and place the pedals relative to your playing position such that you don't have to lean excessively to operate them. If they're too far forward, you'll find yourself leaning backwards.
Use a bar stool or similar behind you to 'lean' against. That way, you can appear to be standing but you also have the support of a seat. Make sure it's sturdy and not on a slippery floor, else it may let you down when you come to rely on it!
If you're using a volume/expression pedal, get a 'balanced' one that holds its position so you don't have to keep your foot on it unless you're moving it.
Answer: I both play guitar and keyboard and I ran into the same problem with pedals. It does not matter if you stand or sit just do what is comfortable.


Como limpar campos de formulario html?

Question: variaveis javascript que referenciam cada campo do meu form
var checkbox = $('input:checkbox[name^=check]:checked');
    var categoriaVeiculo = $("#codCategoriaVeiculo").val();
    var descricaoVeiculo = $("#descricaoVeiculo").val();
    var placaVeiculo = $("#placaVeiculo").val();
    var chassiVeiculo = $("#chassiVeiculo").val();
    var anoFabricacaoVeiculo = $("#anoFabricacaoVeiculo").val();
    var ativo = $("input:radio[name='ativo']");
    var value = ativo.filter(":checked").val();
    var codPessoa = $("#codigoPessoa").val();

Comment: Podes fazer `form.reset();` é isso que procuras? se não podes explicar a pergunta melhor?
Comment: A pergunta está longe de ser clara para que se possa responder à mesma de forma adequada.
Answer: Podes usar assim penso que seja isso que pretende caso não seja diga
document.getElementById('campo').value=''; // Limpa o campo

Answer: No seu código você disse que as variáveis se referem aos campos, mas na verdade eles se referem apenas aos valores, o mais correto seria usar algo como var [SUA VARIAVEL] = $("[SEU SELETOR]");, exemplo:
var checkbox = $('input:checkbox[name^=check]:checked');
var categoriaVeiculo = $("#codCategoriaVeiculo");
var descricaoVeiculo = $("#descricaoVeiculo");
var placaVeiculo = $("#placaVeiculo");
var chassiVeiculo = $("#chassiVeiculo");
var anoFabricacaoVeiculo = $("#anoFabricacaoVeiculo");
var ativo = $("input:radio[name='ativo']");
var value = ativo.filter(":checked");
var codPessoa = $("#codigoPessoa");

Para pegar o valor da variável codPessoa, chame assim:
console.log(codPessoa.val());

ou
alert(codPessoa.val());

Para limpar o campo você pode usar, algo como .val(""), exemplo:
codPessoa.val("");

Comment: Simples e direto, valeu.
Answer: No Jquery não existe o método reset, mas você pode chamar o nativo do javascript:
$('form').submit(function(){
    $(this)[0].reset();
});

Answer: Teria necessidade utilizar Javascript se você precisasse resetar uma variável ou limpar um campo especifico, como proposto na resposta do César Souza. Se precisa limpar todos os campos, utilize um input type='reset'.

input {
  margin: 2px;
  padding: 6px;
  width: 250px
}

input[type='text'],
input[type='email'],
input[type='password']{
  border: 1px solid #333;
}

input[type='reset']{
  border: none;
  background: #3498db;
  color: #fff;
  padding: 6px;
  width: 265px
}
<form action='#'>
  <input type='text' placeholder='Nome de usuário'/>
  <input type='email' placeholder='Email'/>
  <input type='password' placeholder='Senha'/>

  <input type='reset' value='Limpar todos os campos'/>
</form>

Deixe claro para o usuário que ao clicar naquele botão todos os campos serão resetados. Ou então, faça uma verificação antes de realizar a ação, como no exemplo a seguir:

document.getElementById('confirm').onreset = function(){
  return confirm("Gostaria de resetar todos os campos?");
};
input[type='text']{
  border: 1px solid #ccc;
  padding: 6px;
  width: 200px
}

input[type='reset']{
  background: #9b59b6;
  border: none;
  color: #fff;
  padding: 6px 18px
}
<form id='confirm'>
  <input type='text'/>
  <input type='reset' value='Limpar'/>
</form>

Em ambos os exemplos o CSS não tem relevância e foi usado somente para tornar a view mais 'apresentável'.

Como limpar campos de formulario html?


Are vectors and covectors the same thing?

Question: In Euclidean space, we usually don't distinguish between vectors and covectors (or dual vectors or 1-forms or whatever you want to call them) -- because the spaces overlap.  However, a physicist friend of mine (I'm a physics major, too, BTW) was trying to convince me that not only are Euclidean vectors and covectors the same thing, but ANY vector is equivalent to a covector.  His reasoning is that because there is an isomorphism between them and we can convert one to the other with the metric tensor, that there's no real difference between them.  My argument is that an isomorphism between mathematical objects is not enough to call two things the same.  For example, there is an isomorphism between the additive groups of $\Bbb R$ and $\Bbb R^2$, but surely no one would say that $\Bbb R$ is the SAME THING as $\Bbb R^2$.
So which of us is right?  Are vectors the same thing as covectors?
Comment: Your friend's remark suggests that he doesn't understand tensor calculus.
Comment: An isomorphism is an equivalence relation, so it's technically correct to say that a vector is *equivalent* to its covector, though it's not *equal* to its covector. I really hope this is what your friend meant, else he's a really bad physicist. Physicists should be more acutely aware than anyone else of the vital distinction between the two.
Comment: No one has pointed out that the only reason you get the isomorphism is that Euclidean space comes equipped withh a natural Riemannian metric. In an abstract manifold, without a metric or a nondegenerate two-form, you don't get such an isomorphism, which for Riemannian manifolds is called the "musical isomorphism." This is usually first learned when you're taught that you're really integrating forms instead of vector fields.... http://en.m.wikipedia.org/wiki/Musical_isomorphism
Comment: Perhaps in physics the difference between a vector and a covector are best emphasized by the terms contravariance and covariance. For example, a generalized coordinate transforms contravariantly (ok, essentially by defininition) whereas a generalized momentum transforms covariantly. These transformation laws are not the same.
Comment: @DavidH I'm not quite sure if he was making that distinction or not.  Basically I read a short paper on tensors and told him that the only thing I didn't really like about it was the it didn't distinguish between vectors in a vector space vs its dual space (though it was only discussing Euclidean vectors for the most part).  Then he said that there's "only one type of vector, both vectors and covectors are really the same thing."
Comment: Alright.  I'm let him know that mathematicians are backing me up.  Thanks.
Comment: @phizzy I'm a physicist, not a mathematician, so you can tell we all think he's wrong.
Comment: @symplectomorphic That would go as a nice answer I think.
Answer: To add to all the answers above, there is a delightful example in the text "Mathematics for Physics" by Stone and Goldbart, (Appendix A.3), to clarify the difference between vectors and co-vectors, which I can't resist quoting here.

One way of driving home the distinction between $V$ and $V^*$ is to consider
  the space $V$ of fruit orders at a grocers. Assume that the grocer stocks only
  apples, oranges and pears. The elements of $V$ are then vectors such as
$x = 3 \text{ kg apples }+ 4.5 \text{ kg oranges } + 2 \text{ kg pears.} $
Take $V^*$ to be the space of possible price lists, an example element being
$f = (\$3.00/\text{kg}) \text{ apples}^* + (\$2.00/\text{kg}) \text{ oranges}^* + (\$1.50/\text{kg}) \text{ pears}^*$
The evaluation of $f$ on $x$
$f(x) = 3 \times \$3.00 + 4.5 \times \$2.00 + 2 \times \$1.50 = 21.0$
then returns the total cost of the order. You should have no difficulty in
  distinguishing between a price list and box of fruit!
Answer: If $V$ is a finite-dimensional vector space then there exists an isomorphism $V\cong V^*$, under which every vector in $V$ can be interpreted as a covector (linear map $V\to $ the scalar field). However, there are going to be many such maps, and there is in general no canonical such isomorphism, so given a vector $v\in V$, which covector in $V^*$ it corresponds to depends on an ultimately arbitrary choice of isomorphism $V\cong V^*$.
Your friend does observe a valid mental tool that is useful in mathematics: identifying things when they are "essentially the same." If ever there is a canonical isomorphism $A\cong B$ between two objects satisfying some set of desirable properties (what's desirable depends on context), then we can think of any $a\in A$ as a corresponding $b\in B$. (Often we're really speaking about a collection of objects $A$ that are built or result from some kind of process or characterization, and we may use the language of category theory (universal properties, natural isomorphisms). In particular, there does not exist a natural isomorphism between the identity endofunctor and "dual space" endofunctor on the category of finite-dimensional vector spaces over a given field.)
But this identification idea doesn't work when there is no unique or canonical isomorphism between two given objects or structures. Indeed, $\{1,2,3\}\cong\{\rm\color{Red}{red},\color{Green}{green},\color{Blue}{blue}\}$. But if someone were to claim that "the numbers $1,2,3$ are basically colors," you could simply ask "if $1$ is a color, which color is it specifically?" and there would be no correct answer. Whenever there is a unique or canonical isomorphism $A\cong B$, given a $a\in A$, the question "which $b\in B$ is $a$ basically?" does have a unique correct answer; it's $\phi(a)$, where $\phi:A\to B$ is the aforementioned isomorphism.
Answer: Expanding just a touch on my comment:
One simple way to see that vectors and covectors are not as naively identifiable as your friend says is to realize that there are settings where the spaces they form aren't naturally isomorphic. They are developed independently on abstract manifolds, via the tangent and cotangent structures, respectively.
In particular, the only reason they are naturally isomorphic in Euclidean space is the presence of a natural Riemannian metric. It's this metric that gives you the sort structure you need to convert covectors (actually covector fields) into vectors (actually vector fields). This mapping is called the "musical isomorphism." You can get a similar mapping any time you have a non-degenerate two-form, e.g. a symplectic form would also work. But in the absence of such structure -- on an abstract finite-dimensional smooth manifold -- there is no such natural isomorphism, and you can't naturally identify the tangent and the cotangent structures (although any given tangent and cotangent space are isomorphic, by a dimensional argument).
This is a really important distinction, even in physics, as many have pointed out. It will show up when you learn how to integrate differential forms; you can't talk about "gradients" unless you have a Riemannian metric. It will also show up when you learn the symplectic structure of Hamiltonian mechanics: the natural setting for that is the cotangent bundle, but you can use the Legendre transform, sort of like the musical isomorphism, to push that physics into the tangent bundle, which gives you Lagrangian mechanics.
EDIT
You might also be interested in the following discussion of how to "visualize" a covector, which can help to give an intuitive sense of why, though isomorphic, covectors and vectors are different things:
http://www.physicsinsights.org/pbp_one_forms.html


Why selenium does not provide any info with NoSuchElementException

Question: I'm using webdriver with firefox in Java.
I'm searching for elements by using annotations, eg.:
@FindBy(id = "terminal")
private WebElement selectTerminal;

lets say that page fails to render, and for some reason this element does not get rendered. The error message is very obscure and if i'm running tests remotely on Jenkins, its very hard to debug and see what exactly happend, eg.:
The element could not be found (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 72 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.20.0', revision: '16008', time: '2012-02-28 15:00:40'
System info: os.name: 'Linux', os.arch: 'i386', os.version: '2.6.32-312-ec2', java.version: '1.6.0_20'
Driver info: driver.version: RemoteWebDriver

How could i get more detailed info that would contain the selector? Of course i could wrap it up in some kind of helper method, with try/catch, etc. But what i want to know is why it is not displaying the selector, and how can i get rid of that WARNING ?
Thanks!
Comment: Also, the webpage isn't really helpful. This really is a pain and I am looking forward for a solution. In my case, it was the custom catch, log the selector and take of a screenshot.
Comment: Looking at the source of org.openqa.selenium.remote.ErrorHandler class i see comment like this, so guess this is expected behavior:   //If serverError is null, then the server did not provide a className (only expected if
    // the server is a Java process) or a stack trace. The lack of a className is OK, but
    // not having a stacktrace really hurts our ability to debug problems.
Comment: I had similar issues in PHP and also ended up wrapping things in a try/catch block. Seems to be the only thing for it...
Answer: While this is not an ideal solution, it's what helped me with the same issue.
Enable logging to a file by setting webdriver system property E.g.
-Dwebdriver.firefox.logfile=/tmp/ff.log

or in your test code:
System.setProperty("webdriver.firefox.logfile", "/tmp/ff.log")

Then in ff.log you should see output where the error occurred e.g.
[6.389][FINE]:      Command received (/session/5a4c8a0a7ef5453467687267348e8cb3/element)    with params {
"using": "xpath",
"value": "//input[@class='login-submit']
}

[6.389][FINER]:     Waiting for all views to stop loading...
[6.390][FINER]:     Done waiting for all views to stop loading
[6.505][FINER]:     Waiting for all views to stop loading...
[6.506][FINER]:     Done waiting for all views to stop loading
[6.506][WARNING]:   Command finished (/session/5a4c8a0a7ef5453467687267348e8cb3/element)   with response {
   "sessionId": "5a4c8a0a7ef5453467687267348e8cb3",
    "status": 7,
    "value": {
    "message": "The element could not be found"
 }
}

At least now I can see which element it was based on the xpath. This works with ChromeDriver as well


Need help inserting json literal into mysql 5.7

Question: When I try to insert the following query I keep getting this error message:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '['php','javascript'])' at line 2
I am using the following query
INSERT INTO freelancer (tags) VALUES (['php','javascript']);

I tried another query, this time making it a string, and then I get this error
INSERT INTO freelancer (tags) VALUES ("['php','javascript']");

Invalid JSON text: "Invalid value." at position 1 in value for column 'freelancer.tags'.
I am not sure how to go about inserting this into mysql... if anyone can help me figure this out, I would really appreciate it!
Answer: JSON is very particular about quotes. You must use doubles:
VALUES ('["php","javascript"]')

You can test with a JSON validator if you're curious about what is or isn't JSON.


PyQt: How to get listItem Index after ListView's onDrop()

Question: This example creates a simple dialog window with two drag-and-drop enabled listWidgets (thanks ekhumoro!).
On dropEvent the droppedOnA() and droppedOnB() functions print out an information: what listWidgets the items came from and what indexes they used to have. But I need to find what indexes the dropped listItems assigned after they were dropped onto a QListWidget-receiver. I would appreciate if it would be explained how to achieve this.
from PyQt4 import QtGui, QtCore
import sys, os

class MyClass(object):
        def __init__(self):
            super(MyClass, self).__init__()

class ThumbListWidget(QtGui.QListWidget):
    _drag_info = []
    def __init__(self, type, name, parent=None):
        super(ThumbListWidget, self).__init__(parent)
        self.setObjectName(name)
        self.setIconSize(QtCore.QSize(124, 124))
        self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
        self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.setAcceptDrops(True)

    def startDrag(self, actions):
        self._drag_info[:] = [str(self.objectName())]
        for item in self.selectedItems():
            self._drag_info.append(self.row(item))
        super(ThumbListWidget, self).startDrag(actions)

    def dragEnterEvent(self, event):
        if event.mimeData().hasUrls():
            event.accept()
        else:
            super(ThumbListWidget, self).dragEnterEvent(event)

    def dragMoveEvent(self, event):
        if event.mimeData().hasUrls():
            event.setDropAction(QtCore.Qt.CopyAction)
            event.accept()
        else:
            super(ThumbListWidget, self).dragMoveEvent(event)

    def dropEvent(self, event):
        if event.mimeData().hasUrls():
            event.setDropAction(QtCore.Qt.CopyAction)
            event.accept()
            links = []
            for url in event.mimeData().urls():
                links.append(str(url.toLocalFile()))
            self.emit(QtCore.SIGNAL("dropped"), links)
        else:
            # event.setDropAction(QtCore.Qt.MoveAction)
            super(ThumbListWidget, self).dropEvent(event)
            self.emit(QtCore.SIGNAL("dropped"), self._drag_info )

class Dialog_01(QtGui.QMainWindow):
    def __init__(self):
        super(QtGui.QMainWindow,self).__init__()
        self.listItems={}

        myQWidget = QtGui.QWidget()
        myBoxLayout = QtGui.QVBoxLayout()
        myQWidget.setLayout(myBoxLayout)
        self.setCentralWidget(myQWidget)

        self.listWidgetA = ThumbListWidget(self, 'MainTree')
        self.listWidgetB = ThumbListWidget(self, 'SecondaryTree')

        for i in range(7):
            listItemA=QtGui.QListWidgetItem()
            listItemA.setText('A'+'%04d'%i)
            self.listWidgetA.addItem(listItemA)

            myClassInstA=MyClass()
            listItemA.setData(QtCore.Qt.UserRole, myClassInstA)

            listItemB=QtGui.QListWidgetItem()
            listItemB.setText('A'+'%04d'%i)
            self.listWidgetB.addItem(listItemB)

            myClassInstB=MyClass()
            listItemB.setData(QtCore.Qt.UserRole, myClassInstB)

        myBoxLayout.addWidget(self.listWidgetA)

        myBoxLayout.addWidget(self.listWidgetB)
        self.connect(self.listWidgetA, QtCore.SIGNAL("dropped"), self.droppedOnA)
        self.connect(self.listWidgetB, QtCore.SIGNAL("dropped"), self.droppedOnB)

    def droppedOnA(self, dropped_list):
        print '\n\t dropped On MainTree', dropped_list,

    def droppedOnB(self, dropped_list):
        print '\n\t dropped On SecondaryTree', dropped_list

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    dialog_1 = Dialog_01()
    dialog_1.show()
    dialog_1.resize(720,480)
    sys.exit(app.exec_())

Answer: Not tested to destruction, but try reimplementing rowsInserted and emitting the draginfo from there:
class ThumbListWidget(QtGui.QListWidget):
    _drag_info = []
    def __init__(self, type, name, parent=None):
        ...
        self._dropping = False

    def dropEvent(self, event):
        if event.mimeData().hasUrls():
            event.setDropAction(QtCore.Qt.CopyAction)
            event.accept()
            links = []
            for url in event.mimeData().urls():
                links.append(str(url.toLocalFile()))
            self.emit(QtCore.SIGNAL("dropped"), links)
        else:
            # event.setDropAction(QtCore.Qt.MoveAction)
            self._dropping = True
            super(ThumbListWidget, self).dropEvent(event)
            self._dropping = False

    def rowsInserted(self, parent, start, end):
        if self._dropping:
            self._drag_info.append((start, end))
            self.emit(QtCore.SIGNAL("dropped"), self._drag_info)
        super(ThumbListWidget, self).rowsInserted(parent, start, end)

Comment: Great! Let me try it! While on subject. The data stored with listItem gets "deepcopied" onDrop(). Is there any way to override it?
Comment: Thanks! Tuple list's arg brings an index number beautifully! What's happening on super(ThumbListWidget, self).dropEvent(event)? and why _dropping needs to be reset in a row? Thanks again!
Comment: @Sputnix. I'm afraid I don't understand your first comment. The `_dropping` flag is needed becasue `rowsInserted` gets called every time a row is inserted (not just in the drop event), so it avoids emitting signals at the wrong time.


How to binarize data for FP Growth in Weka?

Question: I have a CSV file where all comlumns contains numerical values except for the quality column which contains nominal values. I want to use FP Growth Weka algorithm on the dataset. For that I need to binarize my data. In Weka I choose in the Preprocess tab: Choose->Unsupervised->attribute->NumericToBinary with attributeIndices covering all columns except for the last on (which has nominal values).
After the operation when I select the attribute in Weka's preprocess window I see that each variable indeed was converted to 0 or 1 label but 0 has 0 records count while 1 has all the records:

When I binarize the quality variable which has nominal values:
Preprocess->Choose->unsupervised->NominalToBinary (with attributeIndex only for the quality column) nothing happens at all.
As a result I can't use FP Growth of course. How should I binarize the data correctly to be able to use FP Growth?
These are some example rows of my data:

The original dataset can be found here.

EDIT 1: I guess because the numeric values greater than 0 but less than 1 Weka uses floor function when binarizing data that's why all values appear under 1. So I discretized the numeric attributes and then binarized them using NominalToBinary filter. In addition I changed my dataset from having 3 possible values for quality to only have 0 or 1
 values possible (manually binarized it). Still the FP Growth is not available in Weka. This is an excerpt from .arff output after binarization.

EDIT 2:
I managed to get FP Growth become active by selecting NumericToBinary filter with ignoreClass=True, and selecting class: None next to Visualize All button. However I still have all attributes have all values under 1 label. I tried manually converting all decimal values to integers (because I thought in this cases Weka will not be using floor function on decimal values) but this didn't help at all.
Answer: I figured out the answer finally and wrote the solution here.
In essence, I had to manually convert binarized attributes type from numeric to binarized and reduce support and confidence settings.
Answer: There are two major data-mining issues underlying this question.*
The first data-mining issue is matching the tools you use to the data and the goals of your project. Almost all the predictors in your linked dataset are continuous variables. In general, it's not a good idea to bin continuous predictors, as this page discusses in detail.
Yes, association-rule-mining tools like FP-Growth do require binarized predictors. But if your data are continuous variables then you will be better off using other approaches to identify relationships and subclasses among the predictors and the observations. Other approaches would exploit rather than discard the information provided by continuous variables. James et al describe several supervised and unsupervised approaches to such statistical learning.**
The second data-mining issue is how to binarize data in cases when it might be appropriate. For example, if most of a set of columns in market-basket data were already binary (items bought/not bought) but there were a few for each transaction that were continuous (like profit per transaction), then it could be appropriate to map the non-binary data to binary representations, as noted on page 8 of the arules package vignette .
You should not, however, depend on automated processes to do that continuous-to-binary conversion in any useful way. As the arules vignette continues:

First, a domain expert has to create useful categories for all metric attributes.

It is best to use your (or a colleague's) expertise in the subject matter to perform this task. If a predictor is so novel that there is no prior expertise available, look at its distribution among observations to see if there are obvious breakpoints.
Breaking a continuous predictor first into multiple categories that then are represented by dummy binary predictors discards less information than simply breaking it arbitrarily into 2 categories. For example, arules provides "equal interval length, equal frequency, clustering-based and custom interval discretization." I suspect that Weka provides similar pre-processing facilities.* You should ideally examine several different discretization schemes to ensure that your results don't depend strongly on any particular data pre-processing choices.
With today's easy access to powerful data-mining tools, it's easy to hope that you can just put a new data set into the input and have useful results come out the other end. That false hope can easily lead you astray. Close familiarity with the data and with the questions you are trying to answer is the most reliable way to get useful results via choosing appropriate tools and pre-processing data usefully into forms that those tools need.

*The Weka-specific aspects of this question are off-topic on this site. See this page for a link to Weka-specific help.
**If your interest is in learning how to use FP-growth rather than in these data per se, you should consider another dataset like the 1984 US Congressional voting records also available from UCI. Those data are already effectively binary; I have seen them used in explanations of association-rule mining.
Comment: Your answer is great in terms of providing extra knowledge on binarization in general. However it doesn't provide the answer to my question. Also the link you provided for Weka-specific help doesn't say Weka questions are off-topic. In fact there're more than 600 questions on Weka on this site.
Comment: that being said, I'll gladly accept your answer if you add the link to the answer (I provided in my answer and say that is the answer to the question and then provide your answer below).


What do I have to do to get hook_form_alter picked up?

Question: Trying to move from Drupal 7 to Drupal 8.  First step is to get a custom module with hook_form_alter() and the Devel module working so that I can see how bad I am messing things up.
To do so, I made a custom module with the following files.
mymodule.info.yml
name: My Module
type: module
description: "Custom module"
package: Custom
core: 8.x

mymodule.module
<?php

function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  dpm($form);
  print_r($form);
}

Other steps

I enabled both the Devel module and this custom module.
I gave anonymous users permission to view devel information.
I made sure the Status block was enabled on the Block Admin page.
I cleared all caches via the Pantheon admin interface.
I tried using print_r($form), dpm($form), and var_dump($form).

However, when I refresh /user/login, I don't see any output from dpm(), so the hook isn't getting picked up for some reason.  What else do I need to do?
Comment: That's all you need to do (literally just done the same thing myself and the `dpm` is there). I have had some pretty bad problems with other similar things today though, since going to 8.0.2, so it might be bugs. Just check to make sure you've got the Status Messages block being printed to the page to start with, that got me for a little while
Comment: If the module is installed then the issue is most likely the fact that you are outputting all forms that go through the hook which will overflow the session storage in db. I would suggest outputting only form id or only selected form based on the form id. On the other hand var_dump or print_r should work(if you're not seeing WSOD). Als you have mentioned dummy pages..are there any forms on any of those?
Comment: @Clive I do have the Status Messages block, but still no dice.  @Ivan Jaros I also tried `/user/login`, but I just see the normal login form, no output from `dpm()` or `var_dump()`, which I separately tried.
Answer: It turns out this was something related to MultiDev, a Pantheon-specific feature.  By cloning back and forth between the main dev branch and my multidev branch, I was able to get the custom hook_form_alter() to work.


Symfony 2 SOAP CLIENT

Question: Please tell me why i must put "\" before \SoapClient. When i delete "\", then i have a error.
public function indexAction($name)
{

    try {
            $client = new \SoapClient('some WSDL', array('trace' => 1));
            $a = array('Login'=>'1', 'Password'=>'1', 'LetterNo'=>'1');
            $response = $client->__soapCall('GetTracking', array($a));
            ladybug_dump($response->GetTrackingResult->Status);
        } catch (\SoapFault $e) {
            var_dump($e->getMessage(), $client->__getLastResponse()); die();
    }
    return array('response' => $response);
}

Thanks for help
Comment: It would be a good idea to catch \Exception instead of \SoapFault in Symfony2
Answer: ...because your controller is in a namespace, so your call to instantiate SoapClient without the root slash tries to load that object from the current namespace.
App\Controller\SoapClient instead of SoapClient.
You can use a use statement at the top of your controller to bring it into scope. use SoapClient; and you'll be good to go.

Symfony 2 SOAP CLIENT


Binomial identity

Question: I'd like to get a hint to prove the following identity:
$$\tag{1}\sum_{\nu}(-1)^{\nu}\displaystyle \binom{a}{\nu}\binom{n-\nu}{r}=\binom{n-a}{n-r} .$$
The original statement reads "By specialization derive from (12.9) the identity..." where (12.9) refers to:
$$\tag{2}\sum_{\nu}\binom{a}{\nu}\binom{b}{n-\nu}=\binom{a+b}{n}. $$
The problem suggests using $$\tag{3} \binom{-a}{k} = (-1)^k\binom{a+k-1}{k}.$$
I assumed that "by specialization" means "start with (2) and derive $(1)$", so I changed the sign of $a$ in (2), then I used $(3)$, but it didn't work or I don't know how to proceed from there, so I'd appreciate any help.
Thanks!
Comment: This does look to be one of those things that cry out for Chu-Vandermonde...
Comment: This might be from a source about probability, but the question itself is wholly about binomial coefficients and is self-contained without any reference to probability, so I am re-tagging and re-titling. Hope you don't mind Robert.
Comment: No, it's ok your re-tagging. Indeed, it's a problem from 'An Introduction to Probability Theory and Applications" (http://www.amazon.com/Introduction-Probability-Theory-Applications-Vol/dp/0471257087)
Comment: Can you specify the range of values for $v$ you're summing over? I assume that the sum is from $v=0$ to $v=a$, but it could also be from $v=1$ to $v=a$ or any number of other ranges.
Comment: @AlexBecker Right, I forgot to mention it. It doesn't say (I know, it's annoying). I'm not so confident about this but a reasonable assumption could be $\nu$ from 0 to $a$ because of the first binomial.
Comment: @J.M. Certainly looks like that identity (which I didn't know) could help, although I'm probably 'not allowed' to use it (by the way, this is self-study but using that identity would be 'too much' help :-))
Comment: It isn't too difficult to prove Chu-Vandermonde from first principles if need be. Have you seen "Concrete Mathematics"? You might want to study the route taken in that book for Chu-Vandermonde.
Comment: @J.M. Now I see. It gives a nice combinatorial explanation (page 170, for those interested). Even so, I'd like to know what Feller had in mind for proving it, but thanks for that.
Answer: As long as both $n-\nu$ and $r$ are non-negative integers, we have
$$
\begin{align}
(-1)^\nu\binom{n-\nu}{r}
&=(-1)^\nu\binom{n-\nu}{n-\nu-r}\\
&=(-1)^{n-r}\binom{-r-1}{n-\nu-r}\tag{1}
\end{align}
$$
Using $(1)$, we get
$$
\begin{align}
\sum_{\nu}(-1)^{\nu}\binom{a}{\nu}\binom{n-\nu}{r}
&=(-1)^{n-r}\sum_{\nu}\binom{a}{\nu}\binom{-r-1}{n-\nu-r}\\
&=(-1)^{n-r}\binom{a-r-1}{n-r}\\
&=\binom{n-a}{n-r}\tag{2}
\end{align}
$$
Comment: Great, thank you very much. I was asking for a hint but now I see it was more or less elementary. Just a small correction: in (1), the exponent should be $(-1)^{n-r-\nu}$.
Comment: I believe the exponent in $(1)$ is correct: $\binom{m}{k}=(-1)^k\binom{-m+k-1}{k}$. Set $m=n-\nu$ and $k=n-\nu-r$. (The way I remember this is that the sum of the tops is $1$ less than the bottom and the exponent of $-1$ is the bottom.)
Comment: Oh, yes, I missed that you multiplied already $(-1)^{\nu}$ in (1). I thought you had multiplied implicitly starting (2). Thanks again :-)
Answer: Well, let's see what do Mathematica say about this :
<code>In:= Sum[(-1)^p*Binomial[a, p]*Binomial[n - p, r], {p, 0, a}]
Out= Binomial[-a + n, -a + r]
</code>
It looks like your statement is not true... (EDIT but of course it is true !)
Let's go for a proof.
Let $f_{n,a,p,r}$ denote the expression $(-1)^p \binom{a}{p} \binom{n-p}{r}$, and $S_u$, the shift w.r.t. the variable $u$. For example, $(S_a f)_{n, a, p, r} = f_{n, a+1, p, r}$.
Let $g$ denote the sum $\sum_{p=0}^a f_{n,a,p,r}$, and $g'$ the expression $\binom{n-a}{r-a}$. We want to proof $g=g'$.
You can check that
$$ \left((1+r)S_r+p+r-n\right)f + (S_p - 1)\left(\frac{-p - n p + p^2}{1 + r}f\right) = 0$$
When you sum, you get (notice the telescoping sum)
$$ \left((1+r)S_r+p+r-n\right)g + \underbrace{\left[\frac{-p - n p + p^2}{1 + r}f\right]_{p=0}^{a+1}}_{=0} = 0$$
This gives you a recurrence for $g$, and it is easy to check that $g'$ satisfies the same.
You have similar formulas for the variables $n$ ans $r$. And you check that $g$ satisfies the defining recurrence equations of $g'$. And so $g=g'$.
These formulas can be found with the method of creative telescoping, which is implemented in Mathematica by the package HolonomicFunctions of Christoph Koutschan : you can prove this equality in a algorithmic way !
strong text
Comment: Um, $\binom{n-a}{r-a} = \binom{n-a}{n-a-(r-a)} = \binom{n-a}{n-r}$, by the symmetry of the binomial coefficients.  So the statement is true.
Comment: @Lierre: I take for granted this is not the proof I was expected to work out but I will certainly take a closer look at this. Thanks!
Comment: You're right Mike, of course ! I'm getting stupid when I use a computer, this is a problem ;)

Binomial identity


Troubles with converting oracle.sql.TIMESTAMPTZ to string value

Question: I try get some data from oracle db, put this data in json and use it in other place, but i have problem with converting timestamptz. Oracle give me timestamp with timezone in string format like "23.10.14 18:34:16,000000 ASIA/NOVOSIBIRSK". Here some piece of my code.
public void loadFromDb(ResultSet resultSet, Connection oc) throws SQLException {
    ResultSetMetaData metaData = resultSet.getMetaData();
    int columnCount = metaData.getColumnCount();
    for (int i = 1; i <= columnCount; i++) {
        Object obj = resultSet.getObject(i);
        if (obj == null)
            continue;
        if (obj instanceof TIMESTAMPTZ) {
            TIMESTAMPTZ ts = (TIMESTAMPTZ) obj;
            if (oc != null) {
                super.setValue(metaData.getColumnName(i), ts.stringValue(oc));
            } else {
                super.setValue(metaData.getColumnName(i), ts.stringValue());
            }
    }
}

and i get this exception
java.sql.SQLException: Conversion to String failed
at oracle.sql.Datum.stringValue(Datum.java:181)

btw, earlier i get timezone in number format like 'XX:XX' and this code not work too, but work this magic super.setValue(metaData.getColumnName(i), ts.stringValue(null))now this way thtows nullpointerexception.
Please help me, because i tried all which found in javadocs.
Comment: There can be some problems with your jdbc driver + have you read this? http://stackoverflow.com/questions/17559658/oracle-jdbc-retrieving-timestamp-with-time-zone-value-in-iso-8601-format
Comment: I think that the easiest way to solve the problem is to retrieve string representation of timestamp with time zone (if it's possible in your case)
Comment: @Multisync maybe i missunderstand you but this my problem - get  string representation of timestamp with time zone
Comment: I mean select to_char(col_timestamp_with_time_zone, 'format') ... Which format do you need?
Comment: @Multisync i cant do anything in db side. i just call procedure which return some resultset. thanks for you link, i think that #4(write own toString()) is one possible way for my situation....
Comment: It can be dangerous because Oracle can generate different representations of this type depending on database/session settings. If you call a function which return a cursor you may represent this call as select from table and make a conversation on the oracle side.
Comment: No, I wasn't right. Seems it's impossible without touching a db: http://stackoverflow.com/questions/13690110/function-return-sys-refcursor-call-from-sql-with-specific-columns Then I would recommend an answer which was awarded +50 because it takes into consideration different formats Oracle may return
Answer: The format of TIMESTAMPTZ is well documented. We currently use the following code.
If you are on Java SE 8 and ojdbc8 you can use getObject(int, OffsetDateTime.class). If you use getObject(int, ZonedDateTime.class) you may be affected by bug 25792016.
Answer: TIMESTAMP is not a string and vice-versa. You need to convert it into a string using TO_CHAR and desired format.
SQL> SELECT SYSTIMESTAMP
  2  FROM   dual
  3  /

SYSTIMESTAMP
---------------------------------------------------------------------------
24-OCT-14 18.104.22.168000 AM +05:30

SQL>
SQL> SELECT TO_CHAR(systimestamp, 'DD-MON-YYYY HH24:MI:SS.FF TZH:TZM') tm
  2  FROM dual
  3  /

TM
-------------------------------------
24-OCT-2014 11:14:55.163000 +05:30

SQL> SELECT to_timestamp_tz('24-OCT-2014 11:07:40.348000 +05:30','DD-MON-YYYY HH24:MI:SS.FF TZH:TZM') tm
  2  FROM dual
  3  /

TM
---------------------------------------------------------------------------
24-OCT-14 11.07.40.348000000 AM +05:30

SQL> SELECT TO_TIMESTAMP('24-OCT-2014', 'DD-MON-YYYY')
  2  FROM dual
  3  /

TO_TIMESTAMP('24-OCT-2014','DD-MON-YYYY')
---------------------------------------------------------------------------
24-OCT-14 12.00.00.000000000 AM

Let's validate.
SQL> set serveroutput on;
SQL> DECLARE
  2    tm_stamp  TIMESTAMP;
  3    tm_string VARCHAR2(30);
  4  BEGIN
  5    SELECT SYSTIMESTAMP INTO tm_stamp FROM dual;
  6    dbms_output.put_line(tm_stamp);
  7    SELECT SYSTIMESTAMP INTO tm_string FROM dual;
  8    dbms_output.put_line(tm_string);
  9  END;
 10  /
24-OCT-14 22.214.171.124000 AM
DECLARE
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 7

SQL>

So, tm_string cannot store timestamp, since tm_stamp is a string type and not timestamp.
The correct way is to convert it into string explicitly.
SQL> DECLARE
  2    tm_stamp  TIMESTAMP;
  3    tm_string VARCHAR2(50);
  4  BEGIN
  5    SELECT TO_CHAR(systimestamp, 'DD-MON-YYYY HH24:MI:SS.FF TZH:TZM') INTO tm_string FROM dual;
  6    dbms_output.put_line(tm_string);
  7  END;
  8  /
24-OCT-2014 11:25:20.060000 +05:30

PL/SQL procedure successfully completed.

SQL>

Comment: thanks, but i limited resource of java, because i cant do anything in db side. i just call procedure which return some resultset.


Find asymptotic efficiency of MLE to UMVUE

Question: Let $\{X_i\}_{i=1}^n $ be a sequence of i.i.d random variables with common pdf:
$$ f(x;a,\theta) =\theta a^\theta x^{-(\theta+1)} \boldsymbol 1_{(a,\infty)}(x) \, \,\text{; where } \theta, a > 0$$
I would like to find the asymptotic relative efficiency of the MLE of a with respect to the UMVUE of a. I believe I have already found the correct MLE for $a$ but I'm not sure how to find the efficiency in this case. From the likelihood it seems like the first order statistic is the MLE.
$$\mathcal{L}(X,a,\theta) = \theta^n a^{n\theta} \prod_{i=1}^n\left( x_i^{-(\theta+1)} \boldsymbol \cdot 1_{(a,\infty)}(x_i)\right)  \implies \min_{1 \leq i \leq n}(x_i) = \hat{a} $$
Typically I would use the score to find the Fisher Information and then take the ratio but I don't think that works here. Thanks for your help.
Comment: "UMVUE" abbreviates "[uniformly minimum-variance unbiased estimator](https://en.wikipedia.org/wiki/Minimum-variance_unbiased_estimator)".
Comment: Is $\theta$ unknown?
Answer: MLE of $a$ is indeed the first order statistic $X_{(1)}=\min\limits_{1\le i\le n}X_i$ because the likelihood is non-decreasing in $a$ subject to the restriction $a<X_{(1)}$. Because the population distribution is Pareto, you can verify that $X_{(1)}$ also has a Pareto distribution from which you can get its exact variance.
UMVUE of $a$ however depends on whether $\theta$ is known or not. In any case, it is found using the Lehmann-Scheffé theorem.

If $\theta$ is known, then $X_{(1)}$ is a complete sufficient statistic and UMVUE of $a$ is of the form $c(\theta) X_{(1)}$ for some function $c$.

If $\theta$ is not known, then $\left(\prod\limits_{i=1}^n X_i,X_{(1)}\right)$ or equivalently $\left(U, X_{(1)}\right)$ is a complete sufficient statistic where $U=\sum\limits_{i=1}^n (\ln X_i-\ln X_{(1)})$. Here $U$ has a certain Gamma distribution, and $U$ and $X_{(1)}$ can be shown to be independent. The resulting UMVUE of $a$ would be of the form $g(U)X_{(1)}$ for some function $g$.

Using the points above, you can find the exact variance of both UMVUE and MLE of $a$. Asymptotic relative efficiency of MLE with respect to UMVUE is then the limit of the ratio $\operatorname{Var}(\hat a)/\operatorname{Var}(X_{(1)})$ as $n\to \infty$ where $\hat a$ is UMVUE of $a$. Note that Fisher information is not usually defined for non-regular distributions like this where support of the distribution depends on the parameter of interest.
Answer: Since the MLE is the first order statistic it has the pdf: $n \theta a^{n\theta} x^{-(n\theta+1)} \boldsymbol 1_{(a,\infty)}(x) $.
Naturally then $\displaystyle \mathbb{E}[X_{(1)}] = \frac{a n\theta}{n\theta-1 } $, so that $\displaystyle \frac{(n\theta-1)X_{(1)} }{n\theta } = T(x)$ is the UMVUE by Lehmann-Scheffé.
$$\implies \frac{Var(T(x)) }{Var(X_{1})} = \left(\frac{(n\theta -1) }{n\theta }\right)^2 = 1 - \frac{2}{n \theta} + \frac{1}{n^2\theta^2}$$
So that the asymptotic efficiency is indeed 1.


Difference between Dynamic Factor Model (DFM) and Dynamic Linear Model (DLM)

Question: one simple question: what is the difference between a Dynamic Factor Model (DFM) and a Dynamic Linear Model (DLM) ?
Comment: You might get better answers if you tell us what you think the answer is, where you are stuck, and what other steps you have taken to solve your problem.
Answer: No, it is not the same. Usually, DFM refers to a particular DLM where you assume the observables are dependent on an state vector of reduced dimension with no other structure: think of a PCA in which the principal components are allowed to evolve over time. DLM on the other hand refers to the situation in which the state elements may be related, have tendencies, seasonal effects, etc.


What way am I supposed to practice/learn scales?

Question: I'm currently learning scales and 4 note chords, but I'm not really sure what I'm aiming for. When practising chords, I think they're slowly being cemented into my brain, through muscle memory mainly - I'm guessing this is the best way to memorize them. But when practising scales (which I've been doing for longer than chords, and they're just not sticking), I'm having to think about the interval pattern (e.g. W W h W W W h for major scale) every single note, to figure out what to play next. I've also tried memorising the circle of fifths - before I play the scale, I think about what notes are sharped/flatted and then play them. As you can imagine both of these 'methods' are taking me ages, so I feel like I'm going completely the wrong way about it.
Is there a 'proper'/conventional way to learn scales? I understand that this is slightly opinion based, but surely there's a generally accepted way to memorize these things... Unless I'm doing it correctly and it is literally just a matter of practising them over and over until they stick in my head through muscle memory or something?
Answer: I would venture that you're doing it correctly, and that it takes awhile.
I was still reaching new levels of mastery over the same basic scales for many years after I began.
One thing that accelerated the process, beyond what you described, was practicing the scales in two ways:
Imagine "C" is the scale of choice.
Imagine its notes C D E F G A B are represented 1 2 3 4 5 6 7.
1) Diatonic sequence: Pick a number (x), and play the first x notes of the scale for every note. So if the number is 3, you would play:
123,234,345,456,567 etc.
If the number is 4 you would play:
1234,2345,3456, etc.
2) Intervallic scales: pick an interval and play the scale in that interval. There is no choice to play the interval of a second since each note in the scale is adjacent to its second. But you can use 3, 4, 5, 6 or 7. For example:
In thirds: 13,24,35,46 (CE, DF, EG, FA), etc.
In fourths: 14,25,36,47(CF,DG,EA,FB), etc.
Answer: Different people think in different ways, and what works for you may not work for other people. So you need to do some exploring, to find out how your own mind works.
Some alternatives to thinking in terms of intervals for each step:
Concentrate on how it sounds
For some people, it helps to have an idea in your head of what the scale will sound like, then play it. Rather than think logically about whether the next interval is a semitone or a tone, just play what you "feel" -- and if it sounds wrong, start again. Repeat until you get it right.
It may help to get some recordings of someone playing the scales correctly (or sequence it in a computer program, etc.)
Concentrate on the set of notes in the key
For some people, it helps to know key signatures. Mentally highlight the piano keys that are "allowed" and grey out the piano keys that are "forbidden". So for example, in D minor, all the black keys except Bb are "forbidden" and all the white keys except B are "allowed", and Bb is allowed.
Now playing a D minor scale is just a matter of playing the allowed notes in order.
One of the reasons for practising scales is to get used to key signatures. By drilling these sets of "allowed" notes, you're preparing yourself to play those notes in different orders.
Answer: This is another example where it's a culmination of finding a technique that works for you, and then sticking to a practice regime when you find one that works. One way I have found particularly useful, was using the circle of fifths as you said, and going one way round (i.e through the sharps) and then back the other way. Once I had this, I started doing it every single time I sat down at the piano, treating it as a method of warming up before I practiced pieces. Hope this helps. Just stick at it and it will come!
Answer: If you're learning scales for guitar, then a powerful way to practice scales is to play the arpeggiated harmonized scale.
Take for example C major.

C D E F G A B

The harmonized scale are the diatonic chords that use each note in the scale as the root.

C Dm Em F G Am Bdim

The harmonized arpeggiated scale would be:

C E G
  D F A
  E G B
  F A C
  G B D
  A C E
  B D F

Now play your scales in two octaves ascending and descending and start your scale on every possible location of the C note.
Once you get that down, try playing the harmonized scale in chord order:

C E G B D E F A C

Once you get that down, you can start playing the harmonized scales in circles of fourths and fifths.

C scale, F scale, Bb scale, etc.

Once you can do that, try playing the chords away from your positions.  For example

C chord on fret n
  D F A chord on fret n - 2
  E G B chord on fret n + 2
  ...

The exercises accomplish two things:

You learn the chord tones. Chord tones are the most important parts of a melody, they have the strongest motion.  If you just practice straight scales, then your solos will sound like scale exercises.
You learn where every note is on the fretboard. Guitar players play in patterns all the time.  That's good but you don't want to be a slave to the patterns you've learned.  These exercises help you learn the placement of each note on the fretboard, which greatly expands your freedom.

I've done these excercises but the main thing I do these days is play melodies on all possible positions on the guitar, but that's for a different post. :-)
However, if you're playing guitar, one thing that is very important is to master the guitar scales systems.  Lots of folks recommend the CAGED system but that never really worked for me.  An excellent systematic introduction to guitar scale systems is Richard Daniel's "Heavy Guitar Bible". http://www.amazon.com/The-Heavy-Guitar-Bible-Instruction/dp/0895240661
Comment: The question is tagged piano. I'm sure that some of this advice translates well to piano, but you might want to be more explicit about it. The guitar info is good stuff so I'd leave it in – just please try to also make it more helpful for piano.
Answer: The way I memorized modes and scales was playing some jazz. I would analyze the piece and think about which scales could sound good over each chord. Playing at a slow tempo, very slow usually, I'd go through the piece trying to come up with ideas using the scales. This is a very lame way of playing jazz, but you'll sometimes be surprised at the things you can come up with and its a really great way to get the scales ingrained into your head and fingers while having a little bit more fun.


XML Signature Generation using IBM SDK 6.0

Question: I'm having an interesting problem trying to sign a SAML2 Assertion using IBM's JRE 6.0. If I run the code under a Sun JDK, it signs the assertions correctly and the signature verifies. If I run the exact same code under the IBM JRE, the Assertion is created correctly, but the signature won't verify. Again, this is the same code, indeed, as it's running from Jetty, it's the exact same Jetty config and WAR file as well. I have two instances of Jetty running on different ports with different JREs but pointing to the same Jetty home. The signatures generated under the Sun JRE validate, but those generated under the IBM JRE do not. I'm frankly stumped and am running out of things to try, so any suggestions would be helpful.
Comment: Ok, figured this out. As it turns out, the Sun implementation of XML Dsig is more tolerant than Xerces/XML Security and IBM's implementation. There was a mix of DOM1 and DOM2 calls that were causing problems and the way URIs were dereferenced also caused issues. Replacing all DOM1 calls (DOM calls with no namespace) with DOM2 calls and setting the id information on the DOMSignContext solved the problem and it works under both JVMs now.
Comment: Hey could you further explain what you did in your comment? Its the Xerces Implmentation that has to be changed right? Whats the best way to do that? I tried changing the Parent_ClassLaoader but I got Servlet classpath errors. So I would like to avoid doing that.
Comment: Basically I just made sure that every DOM call was one that uses a namespace value. So instead of Document.createElement(), I used Document.createElementNS(). By making sure that everything had a namespace defined it cleared up the errors. There's no need to change Xerces implementations, just don't mix DOM1 (not namespace aware) and DOM2+ (namespace aware) calls on the same document.
Answer: A few years late, but I'm going to answer this myself. The problem was a mix of DOM1 (non-namespace aware) and DOM2+ (namespace aware) calls. By shifting everything to namespace aware DOM2+ calls, the problem went away.


Sufficient conditions for a stochastic process to be continuous?

Question: Let $(X_t)_{t\ge 0}$ be a stochastic process, such that $X_t-X_s \xrightarrow{w} \delta_0$ as $t\to s$. Is that a sufficient condition for $(X_t)_{t\ge 0}$ to be continuous? If not, can you provide what conditions should be needed. Also, can you provide a reference where I can read about continuity of stochastic processes?
Answer: It is no different than the continuity of an ordinary function with the exception that you can assign a probability to the event that a given stochastic process is continuous.
Let $X(t,\omega)$ be a stochastic process. The mapping $t \rightarrow X_t(\omega)$ defines a path for each $\omega$. When one talks about the continuity of $X$, he/she means the continuity of these paths. For continuity of a certain path, we require that $t_n \rightarrow t$ imply $X_{t_n}(\omega) \rightarrow X_t(\omega)$.
If $P\{\omega: t\rightarrow X_t(\omega) \text{ is continuous}\} = 1$, then we say $X$ is almost surely continuous.
Answer: Consider the poisson point process with constant rate $1$. It is true that $X_t-X_s \xrightarrow[]{w}\delta_0$ but the process is not continuous (It has jumps of size $1$).
To obtain continuity of the stochastic processes you need to prove that the oscilation tends to zero, that is:
$$ \Bbb{P}(\sup_{|t-s|<\delta} |X_t - X_s|> \epsilon)\xrightarrow[\delta \to 0]{} 0$$
A good reference book in this subject is Billingsley https://books.google.com.br/books/about/Convergence_of_Probability_Measures.html?id=GzjbezrsrFcC&redir_esc=y
See the chapter that treat the space $D$ of discontinuous processes.
Comment: Thanks a lot for the reply
Comment: Shouldn't it be $\delta\to 0$?
Comment: Yes thank you!!
Comment: Hi, can you have a look at this question and suggest how I can use this definition there http://math.stackexchange.com/questions/1356106/proof-that-the-ornstein-uhlenbeck-process-is-continuous/1356158#1356158
Comment: You know which page in Billingsly this sufficiemt condition is stated?


The operation could not be completed. Invalid FORMATETC structure

Question: I am developing web based application using asp.net and ajax. Today I am facing an issue, while dragging and dropping the ajax based components under the ajax enabled webform.
The error message is
The operation could not be completed. Invalid FORMATETC structure

If your answer is assembly then please let me know which assembly such issues (be specific about assemblies)
Comment: try this http://dotbert.loedeman.nl/solution-the-operation-could-not-be-completed-invalid-formatetc-structure
Comment: Let me know which assembly is responsible for this error...
Comment: Can you please give a bit more information on what system are you receiving this error? Visual Studio version? Other third party controls / extensions addins involved?
It may be because of the Ajax Control Toolkit but it may be some other library intercepting the drop event as well. FORMATETC is carying out the information you are dragging (image, rtf, object, other) so what is receiving it does not expect it.
Answer: It is basically due to Ajax Toolkit assembly if you have added it as toolbox. Only way to get rid of this is to restart your IDE , whenever your have Formatetc error , or unload the toolbox and recreate it. Either of them will solve the. But it will not go. Occurance will become rare. Hope this help.
Ajax toolkit version < 3.5 seen such bugs.
Answer: If you using AjaxControlToolkit.dll try remove it and redownload and adding again.
Also try re-install Ajax Control Toolkit, which might solve your problem.
Answer: first Check in  control panel => administrative tool => .net framework . your internet priority is low then change it


Chromatic Functional Harmony (Musical Theory of Everything)

Question: When I started studying music theory, I was fascinated by functional harmony. I loved learning why certain chords naturally tend to lead toward certain other chords and why so many chord progressions follow the same patterns.

In my early days of composing (mostly piano, choir and a bit of film scoring), functional harmony drove nearly everything I did. Whenever I'd get stuck (which was most of the time) I'd turn to my functional harmony chart for guidance and it never failed me.
With time I came across more and more techniques that went beyond the boundaries of diatonic functional harmony (secondary functions, tri-tone substitutions, chromatic mediants, axis theory, modal interchange, negative harmony, etc.). With all these extra techniques at my disposal and standard chord functions permanently etched into my brain, my chart eventually became obsolete.
For some reason I have always had a hard time accepting all these other techniques as being outside the bounds of functional harmony. Instead, I see them as extensions, each introducing a new set of functions that can push the piece in new directions. I guess it comes down to the way I think of a chord's function:
what role does it play in moving the piece forward?
Recently, it occurred to me that any chord can go to any other chord. Obviously this is physically possible, but what I mean is that every chord has a distinct relationship with every other chord and every change creates motion, be it forward, backward, sideways, up, down or inter-dimensional. In other words, every chord has a function at any given point.
And this (finally) brings me to my actual question:

Is there such a thing as chromatic functional harmony, a musical theory of everything? I have seen some things that come close (axis theory comes to mind), but nothing that truly explains everything.

And, as a followup to that:

If there is no such thing, could it even be theoretically possible? Or are there simply too many combinations to reasonably classify everything in a useful manner?

And lastly:

Would there even be any benefit to something like this? Or are we better off leaving all these additional "functions" where they are, encapsulated in a particular branch of music theory?
Comment: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/98051/discussion-on-question-by-willross1-chromatic-functional-harmony-musical-theory).
Answer: Edit: I tried to construct a meta-model of styles of harmony at the end of this answer.
Functional harmony is a simple narrow "mini-game" that can be played on the larger field of music. If you sit down at a fixed tonic and do the functional harmony thing like it's supposed to be done, so that the listener's sense of tonic is retained, then the functional harmony framework is well suited to reasoning about the things that happen. But there are other kinds of games that can be played, and other kinds of situations where functional harmony isn't the best tool.
Let's take an example of how you might not be properly playing the functional harmony game. If you think about a major key, but then you play only the IV chord for five minutes straight, the listener has no other possibility than suppose that your chord is a I chord. If you then start adding some of what you think are "V" chords, but you keep your "IV" note in the bass as a pedal tone, you might claim that you're playing IV - V/IV, but your listeners will hear it as not a functional harmony at all, but some kind of a modal harmony, maybe a lydian mode of your "IV" note.
Inside the functional harmony game, the sense of tonic is important, and the tonic shouldn't move. If it moves, then AFAIK the movement itself shouldn't be considered a part of functional harmony, even if you start playing the functional harmony game around a different tonic right after the key change. And even if the key-change might seem to utilize the same underlying phenomenon as leverage that works in the V-I motion of functional harmony.
There are many different kinds of games and "player role schematics" that can be overlayed on musical pitches. For example the Barry Harris "sixth diminished" scale system, which could be called a variation of functional harmony. If you use that scale, e.g. C-D-E-F-G-Ab-A-B, and use chords where you take every second note, you get two chords: (1) C-E-G-A and (2) D-F-Ab-B. Chord 1 could be called the tonic because it works as a home chord, and chord 2 could be called the dominant, because it works in that role - but there's no purely "subdominant" role in this game (if we disregard bass inversions). This is very interesting, because you have both the tonic of the "major key" and its relative "minor key" in the same chord C6 or Am7, and both keys' dominants share a chord too, the Bdim7 (and its three aliases).
If you want to see everything that can be done with chromatic notes in a unified and "functional harmony compatible" way, I think you have to think of functional harmony as only one perspective or tool for reasoning about what is where at any given time. If the tonic starts moving around, or if it stays fixed but with different note/chord relationships like in modal harmony, you can still use some of the concepts you've learned from functional harmony, but not completely in their purest forms. For example, and this is just my subjective description, the dorian mode feels almost the same as a regular minor, just with a slight twist. But the lydian mode feels like the harmony is permanently chained down to a IV chord, and no matter how hard it struggles, its feet remain glued to the floor. If just the bass could properly move to the V note and then back home to I! But like I said, this is only my personal subjective feeling, but I'm able to use concepts from functional harmony for thinking about the situation.
My unification of theories
I'll try to formulate my meta-model of harmonic styles and frameworks that I called "mini-games" in the beginning of this answer. (Disclaimer: I haven't studied music in any institution, and I would assume that such theories and models already exist in abundance "out there" in the academic world.) I use a model of harmonic context where each possible perceived situation or position has the following dimensions:

(T) the tonic
(C) the set of possible expected chords around the tonic (which is closely related to scales)
(B) the current balance/imbalance or "leaning" within that set of chords and tonic

At any given time, several descriptions of a position can be simultaneously possible or plausible. For example if you only play a single note, a great number of situational descriptions along the C and B axes feel possible, but the position in the T dimension might feel more certain. So, you actually have a set of (T, C, B) triplets, each with an associated probability.
The harmonic context can move in each of these dimensions, or along the axes. Harmonic movement is a change in the perceived set of probabilities: "how plausible does each positional description feel now". A change in the set of probabilities in itself has a certain feeling and effectiveness to it, and each dimension has its own feeling. A regular pop song chord-change is a change in the B dimension, and a chromatic pop song modulation is a change in the T dimension. (I don't necessarily mean that any of the axes would need to have any specific ordering of positions, though you can probably come up with different distance metrics and definitions of "spatial" ordering inside each of the three dimensions, and such questions have been posted here, like "what's the distance between two chords")
How can we map different harmonic styles to the meta-model?

Traditional functional harmony assumes that things happen only in the B dimension, and maybe a little bit in the C dimension, but it says almost nothing about the T dimension.
Modal harmony assumes that inside each mode, the T and C dimensions are kept totally fixed, and even the B dimension is a bit so-so, because there's the risk that leaning too much in any direction is effectively a change in the T or C dimension, making it a different mode.
Non-modal jazz harmony is like functional harmony, but a bit more relaxed, and it acknowledges the T dimension strongly, meaning that key changes are used in the trick palette.
In some jazz styles where the tonic seems to move a lot, the change in the probabilities is used as an effect in itself. And some styles might toy especially with having a large set of possible positional interpretations as having a considerably high probability/plausibility. For example, using tritones, dim chords and other symmetric things that easily lend themselves to multiple interpretations.
In atonal music, probabilities in the T dimension should be low or spread over a large array of positions, meaning that you're not supposed to be able to name any note as the tonic with confidence at any point.
(insert other harmonic styles here - for example Indian music genres? would they be close to modal styles in terms of this meta-model)

If you consider that the probabilities for each (T, C, B) come from or are affected at least partly by the listener's own internal state and memory, either short-term, long-term and even cultural background, this meta-model could be used to describe a lot of things. For example the relationship between rhythm and harmony, and sense of chord-tone vs. passing tone: if your internal clock sync says it's time for a strong beat/pulse, then the notes you hear get more weight in affecting the probabilities than when you're off-beat.
Could there be a real theory of everything about harmony
To answer the question "could there be a single unified theory like functional harmony but more general" ... I don't think it's possible to describe all possible harmonic styles in the same sentence, so to speak. Each style is complex enough by itself, and follows its own set of rules and assumptions. Even if we could see all the general underlying physical/biological/psychological mechanisms, you would still want to build specialized higher-level abstractions on them, because too much detail is too much. You want to see the forest from the trees and look at things from different perspectives. We have e.g. quantum mechanics, chemistry, biology, psychology and economics as separate fields of science, even though they in some way operate in the same universe. But you can use a meta-model to talk about the differences in perspective and operating domain of each harmonic style.
Answer: I can't answer the whole question!   But I can suggest that you move on from considering chords as entities but rather look at them as a collection of notes and intervals.   You're probably half-way there already in recognising the tritone interval as the driving force within a dominant 7th chord.  You'll also have discovered that if that tritone is allowed to resolve (in either direction) it doesn't matter too much what other notes surround it.    Now, recognise other tensions between pairs of notes, played together or linearily.
Comment: Good point about the single-entity vs. group of things. It must be confusing for a music student: first you're told to look at note groups as entities called "chords" so you can see the forest from the trees... but when you progress far enough, you're told to look at all the individual notes and their relationships again!? ;) Learning music is a subjective process, and the idea on this site that there could be "correct" questions and answers feels laughable.
Comment: You may be in danger of confusing 'music student' with 'guitar student' :-)
Answer:
Is there such a thing as chromatic functional harmony, a musical theory of everything?

Even a chromatic theory wouldn't really be a theory of everything, because the chromatic scale only represents 12 pitches out the hundred or more different pitches that a human being can distinguish in each octave.
If we think of what the chromatic scale really is, it's not "non-diatonic", as all diatonic music can (possibly with tuning compromises) be played within the chromatic scale. Rather, it's a kind of "super-diatonic" scale - it allows any mode of the diatonic scale to be played starting from any of the chromatic scale's 12 notes.

For some reason I have always had a hard time accepting all these other techniques as being outside the bounds of functional harmony. Instead, I see them as extensions, each introducing a new set of functions that can push the piece in new directions.

I think that's very reasonable. Perhaps traditional functional harmony can be seen as 'single-dimensional' from a diatonic point of view, in that it functions within a single diatonic scale, while some of these other techniques are multi-dimensional, as the functions move you between different diatonic scales.

If there is no such thing, could it even be theoretically possible?

I guess to me, when you talk about secondary functions, tri-tone substitutions, chromatic mediants, modal interchange... those things do, in a slightly messy way, make up a kind of 'chromatic theory'. Yes, when you talk about 'secondary functions' it does still seem like you're seeing things in diatonic terms - but then the chromatic scale is the twisting, flipping, mutating, transforming cousin of the diatonic.
If you really wanted to make a musical theory of every aspect of harmony, I think you'd start by not initially starting with the idea of scales that restricted you to certain pitches, but by allowing every frequency/pitch, and every timbre - or perhaps even abandoning the idea of 'notes' altogether, and see things simply in terms of changing spectra.
Comment: Doesn't functional harmony also handle modulations, so it functions within *multiple* diatonic scales instead of just one?
Comment: The first thing to do with a chromatic harmony model would be to build a diatonic scale on it, to be able to handle any actual music. Isn't that what guitar players do?


How to infer correlations from correlations

Question: I have a question regarding correlation inference. Consider, I have two sets of variables X and Y. For an x element of X I know the correlation to an unknown variable z. I also have the covariance matrix X and Y. Moreover, I know a set of (y1,y2,y3) element of Y, which model best my variable x. So how to infer the correlation of (y1,y2,y3) and z?
I need a function: f(corr(x,z), corr(x,(y1, y2, y3)), cov(X,Y)) --> corr((y1,y2,y3),z)
This might be a very simple question, but I have no idea how to do it or for what I can search in the literature.
Thank you in advance!
Answer: Given corr(A,B) and corr(A,C) you can obtain bounds on corr(B,C) (and similar such calculations involving more variables), but the bounds are in general quite wide. Indeed, typically such calculations aren't very informative at all.
Specifically, by looking at the relationship between the ordinary pairwise correlation and the partial correlation:
$$\rho_{BC\cdot A } = \frac{\rho_{BC} - \rho_{AB}\rho_{AC}} {\sqrt{1-\rho_{AB}^2} \sqrt{1-\rho_{AC}^2}}$$
you can rearrange the formula to back out bounds for $\rho_{BC}$:
$$\rho_{BC}=\rho_{AB}\rho_{AC}+\rho_{BC\cdot A } {\sqrt{1-\rho_{AB}^2} \sqrt{1-\rho_{AC}^2}}$$
and noting that the partial correlation must lie between -1 and 1, this implies that $\rho_{BC}$ is bounded to lie in
$$\rho_{AB}\rho_{AC}\pm {\sqrt{1-\rho_{AB}^2} \sqrt{1-\rho_{AC}^2}}\,.$$
e.g. Let's say $\rho_{AB}=0.8$ and $\rho_{AC}=0.6$.
Then $\rho_{BC}= 0.6 \times 0.8  \pm \sqrt{(1-.64)(1-.36)}=0.48\pm 0.48 = (0,0.96)$
With more variables the situation becomes more complex; in some situations it's easier to work with Cholesky decompositions.
If you impose additional structure on the problem then in some situations those bounds might reduce.
Additional details may help.


ID3 Artwork Tags from MP3 In Documents Directory iPhone Development

Question: I have several MP3 files in the user's documents directory, and I want to be able to get and display the ID3 Artwork Tags. I have tried using NSURLAsset, but I am unsure how to convert that to a UIImage or a UIImageView!
Thanks!
Answer: You have to use the AVAsset class:
For instance:
<code>NSString *mp3Path = [[NSBundle mainBundle] pathForResource:@"audio-file" ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:mp3Path];

AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
for (NSString *format in [asset availableMetadataFormats]) {
    for (AVMetadataItem *item in [asset metadataForFormat:format]) {
        if ([[item commonKey] isEqualToString:@"artwork"]) {
            NSData *data = [(NSDictionary *)[item value] objectForKey:@"data"];
            UIImageView *img = [[[UIImageView alloc] initWithImage:[UIImage imageWithData:data]] autorelease];
            [self.view addSubview:img];
            continue;
        }
        NSLog(@"%@", item);
    }
}
NSLog(@"> Duration = %.2f seconds", CMTimeGetSeconds(asset.duration));
</code>