Filter nodes by entity reference

Question: I have an article content type linked to an event content type via entity reference.
In the Articles view, I would like to offer a filter allowing to filter articles by linked event title.
With Drupal 7, we used to manage it with better_exposed_filters module but I can't find a way to do it in Drupal 8.
Comment: The core issue to fix this is [Generalize TaxonomyIndexTid filter to be available for all entity reference fields](https://www.drupal.org/node/2429699).
Answer: Here is the my solution inspired from:

http://www.webomelette.com/creating-custom-views-filter-drupal-8
http://www.sitepoint.com/drupal-8-version-entityfieldquery/

Thanks to Danny Sipos
I already had a dedicated custom module for this project where I added the following:
mymodule.views.inc
<?php
/**
 * Implements hook_views_data_alter().
 */
function mymodule_views_data_alter(array &$data)
{
    $data['node_field_data']['related_content_titles'] = array(
        'title' => t('Related content titles'),
        'filter' => array(
            'title' => t('Related content titles'),
            'help' => t('Specify a list of titles an content node can have.'),
            'field' => 'nid',
            'id' => 'mymodule_related_content_titles'
        ),
    );
}

src/Plugin/views/filter/RelatedContentTitles.php

use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\filter\ManyToOne;
use Drupal\views\ViewExecutable;

/**
 * Filters by given list of event title options.
 *
 * @ingroup views_filter_handlers
 *
 * @ViewsFilter("mymodule_related_content_titles")
 */
class RelatedContentTitles extends ManyToOne
{
    /**
     * {@inheritdoc}
     */
    public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL)
    {
        parent::init($view, $display, $options);
        $this->valueTitle = t('Allowed event titles');
        $this->definition['options callback'] = array($this, 'generateOptions');
    }

    /**
     * Helper function that generates the options.
     * @return array
     */
    public function generateOptions()
    {
        $storage = \Drupal::entityManager()->getStorage('node');

        $relatedContentQuery = \Drupal::entityQuery('node')
            ->condition('type', array('event', 'story'), 'IN')
            ->condition('status', 1);

        $relatedContentIds = $relatedContentQuery->execute();

        $res = array();
        foreach ($relatedContentIds as $contentId) {
            $res[$contentId] = $storage->load($contentId)->getTitle();
        }

        return $res;
    }
}

When ceating the view listing my articles where I want to expose the related event filter I had to :

add a relationship field_article_associated_event: Content
add a filter criteria of my type Related content titles, select the perviously cerated relationship for the field Relationshi, check Expose this filter to visitors, to allow them to change it
Comment: Explained a bit more in details here:
http://antistatique.net/en/we/blog/2015/10/06/entity-reference-filter-with-drupal-8
Comment: Can this code be used to help fix the core issue over at https://www.drupal.org/node/2429699 ?
Comment: Worked great - thank you!
Answer: You can use the Entity Reference Exposed Filters module.

A module for those who need their Entity Reference Exposed Filters to have titles in Select Lists.

Filter nodes by entity reference


R returning impossible values when trying to set up the regression for ROC with multiple curves

Question: Image of roc data
Hello! I have been trying to plot some pilot data in ROC space but have run into some issue that I suspect is because I am fairly new at this. Specifically, I set my regression up like so:

`> model1 <- lm(probSame.Same ~ Same.Pitch + same.location + same.syl + same.multi, data = rocdata)

summary(model1)`

and it returns NAN values (image of output attached)
To give some context: the roc data image breaks down such that each column is the probability of respondents saying 'Same' when the item was the same (its a change detection task), then 'Same' when the pitch was different, 'same' when the location was different, 'same' when the syllable was different, and 'same' when all three of those features had in fact changed. Each row is the confidence level:

Sure same
Sure + Probably same
Sure + Probably + Maybe same
Sure + Prob + Maybe Same + Maybe different
Sure + Prob + Maybe Same + Maybe different + Probably different

So 1-5 increase and get close to a probability of 1.
Anyway, I am getting the attached output which I think means I have a an uneven number of predictors? The output is the same regardless of whether I use glm() or lm(). When I exclude one of the predictors the regression works, but obviously I need to include it.
Can anyone provide guidance on what is wrong with my setup? Thank you for any advice you can give. Output of regression
Comment: You have too many predictors for the amount of data you have.  This is a stats problem, not a programming problem.
Comment: That makes sense. It sounds like I need to search for a more suitable forum for this question. If you have any suggestions I'd appreciate it but thank you for the help already.
Answer: As a comment notes, "You have too many predictors for the amount of data you have."
Your model involves 4 predictors that you name, plus an intercept. That's 5 parameter values that need to be estimated. You have exactly 5 observations, so you can fit your current data exactly with those 5 parameters. There is no residual error and "no residual degrees of freedom," which in this case is the number of observations minus the number of estimated parameter values.
Thus R isn't returning "impossible" values. It's returning exactly what it should for a saturated model like this.
This is an extreme example of overfitting, in which you do a good (here, perfect) job of modeling your data in a way that probably won't generalize to a new data sample. To avoid overfitting with the variability typically seen in human-subjects research, you typically need about 10-20 observations for each predictor in a linear regression or, in binary (logistic) regressions, that many members of the minority class per predictor.
As you talk about ROC values and have a probability as your outcome variable, I assume that you are doing binary-outcome modeling. My guess is that there is a better way to accomplish what you want than your current approach, which seems to be working with some type of already processed data. It's usually best to work with as close to the original data as possible. You might ask another question on this site that describes your project and your data in more detail, to get some ideas for other analysis approaches. Please see the help center for how to ask a question that might get one or more helpful answers.


Como acessar variável de outra controller - CakePHP

Question: Como faço pra acessar variáveis de outra controller?
Por exemplo:
Tenho uma controller X, e na action index, crio uma variável (ou uma constante).
Da controller Y, quero acessar o valor da variável (ou constante) da controller X.
É possível fazer isso?
Lembrando que cada action de cada controller, em minha aplicação, terá uma variável que deverá ser acessível de outra controller.
Controller ExemploX
class ExemploXController
    {
        $dependencias = array("index","listar");

        public function index()
            {
                echo "Index";
            }
        public function funcaoX()
            {
                echo "Funcão X";
            }
        public function listar()
            {
                echo "listando";
            }
    }

Controller ExemploY
class ExemploYController
    {
        $dependencias = array("index","atualizar");

        public function index()
            {
                //pegar o valor da variável $dependencias da controller ExemploXController
                $dependency[] = ExemploXController->dependencias;
            }
        public function funcaoY()
            {
                echo "Funcão Y";
            }
        public function atualizar()
            {
                echo "atualizar";
            }
    }

Comment: Pode dar um exemplo simples, mas concreto? O que você está pedindo provavelmente dá pra fazer de outra maneira.
Comment: Ok. Adicionei. Como eu faria isso?
Answer: Olá, você pode criar um requestAction.
Com ele você pode usar tanto no mesmo controller quanto em outros controllers, mas não se esqueça de criar o elemment de cache.
http://book.cakephp.org/2.0/pt/controllers.html#Controller::requestAction
Comment: A partir do momento que ele pode setar uma variável em um `action` de um `controller` e não precisar importar um `controller` inteiro para conseguir resgatar o `action` que ele precisa, responde sim.
Comment: Essa foi a melhor resposta. =)
Comment: @IgorMartins Esta é uma boa resposta se você quiser chamar um método de outro controlador. Mas fazer um request para recuperar uma constante?
Comment: @utluiz `requestAction` não serve apenas para chamar um método de um controler. segundo a documentação `Este método chama uma ação de um controller de qualquer lugar e retorna os dados da ação requisitada.`. `Você pode usar o requestAction() para recuperar uma view totalmente renderizada passando 'return' no array de opções: requestAction($url, array('return'));`. Sem contar que ele vai requisitar menos memória por faezr o uso do cache.
Comment: Foi exatamente isso o que eu disse. Mas isso simplesmente não responde à pergunta.
Answer: Acessar variáveis de outros controladores é completamente diferente de acessar métodos ou ações deles.
Os controllers do CakePHP são apenas classes comuns, então, em tese, você poderia acessar seus atributos e métodos da mesma forma como faria com qualquer classe, bastando para isso carregar o respectivo arquivo.
Uma forma de fazer isso é usando o App::import. Veja o exemplo da própria documentação:
// The same as require('Controller/UsersController.php');
App::import('Controller', 'Users');

// We need to load the class
$Users = new UsersController();

Como a própria documentação indica, isso é equivalente a usar diretamente o método require. Alternativamente, você poderia criar um arquivo com as constantes que você precisa e incluir esses arquivos no seu código, usando onde for necessário.
Comment: Foi exatamente o que fiz agora, antes de vir aqui. Pensamos juntos.De qualquer forma, obrigado.


phpmyadmin and import of an existing database

Question: I have just installed phpmyadmin on a Windows 2008 Sever with IIS installed and I want to important a database which I have created on my own machine onto this server within phpmyadmin.
When I try do so I get an error message

File could not be read

I have read this may be due to the open_basedir within php.ini
I have changed open_basedir to open_basedir = D:\inetpub and then placed the database.sql.zip file into the inetpub folder but I am still getting the same error message.
Anyone know where I am going wrong?
Answer: see this article. http://sourceforge.net/projects/phpmyadmin/forums/forum/72909/topic/3817584
I don't know why that works but seemed to help that case.  My answer to you is don't use phpmyadmin as a crutch.  You should at least learn the basic mysql syntax to import your database from the command line.
http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html
Comment: +1 for "don't use phpmyadmin as a crutch"


Android NDK- Error:Execution failed for task ':app:buildNative'

Question: I am developing an Video Compression app so i am using NDK and getting error when run the app.
I seen the many stackOverflow Questions (Execution error in app:buildNative) but the stackOverflow solutions are not works for this error.
Gradle Build Message:
Gradle tasks [:app:assembleDebug]
:app:buildNative FAILED
Error:Execution failed for task ':app:buildNative'.
> A problem occurred starting process 'command 'null/ndk-build.cmd''

Is anyone help for my questions?
build.gradle(Module:app)
apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'
    defaultConfig {
        applicationId "com.xxxx.videocompressor"
        minSdkVersion 16
        targetSdkVersion 22
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    sourceSets.main {
        jni.srcDirs = [] // This prevents the auto generation of Android.mk
        jniLibs.srcDir 'src/main/libs'
        // This is not necessary unless you have precompiled libraries in your project.
    }
    task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
        def ndkDir = android.ndkDirectory
        commandLine "$ndkDir/ndk-build.cmd",
                '-C', file('src/main/jni/').absolutePath, // Change src/main/jni the relative path to your jni source
                '-j', Runtime.runtime.availableProcessors(),
                'all',
                'NDK_DEBUG=1'
    }

    task cleanNative(type: Exec, description: 'Clean JNI object files') {
        def ndkDir = android.ndkDirectory
        commandLine "$ndkDir/ndk-build.cmd",
                '-C', file('src/main/jni/').absolutePath, // Change src/main/jni the relative path to your jni source
                'clean'
    }

    clean.dependsOn 'cleanNative'
    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn buildNative
    }

    productFlavors {
    }
}

dependencies {
    compile 'com.android.support:support-v4:22.2.+'
    compile 'com.android.support:support-v4:22.2.+'
    compile 'com.android.support:appcompat-v7:22.2.+'
    compile 'com.android.support:recyclerview-v7:22.2.+'
    compile 'com.android.support:design:22.2.+'
    compile 'com.google.android.gms:play-services-ads:7.8.0'
}

Comment: If any gives downvote, please give me a reason. Thanks
Comment: The build output indicates that `android.ndkDirectory` is `null`. Have you checked this variable?
Comment: No, Where that locates? @tomasulo
Comment: What gradle version are you using?
Comment: Gradle version 2.2.1 @bullsy
Comment: @VenkateshSelvam Hmmm, what's the content of your local.properties file?
Answer: Instead of using only this
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
    } else {
        commandLine 'ndk-build', '-C', file('src/main').absolutePath
    }
}

Use this
// call regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec) {
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
        } else {
            commandLine 'ndk-build', '-C', file('src/main').absolutePath
        }
    }

   tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }


McNemar's test p-value NA

Question: I have paired data from 9 individuals. The response variable is ordinal with levels 1-5. As the sample is very small and the data are categorical, I thought the appropriate test was McNemar's test. However I get McNemar's chi-squared = NaN and therefore a p-value = NA. What should I do to test whether the effect is significant?
My data:
before
4 3 4 5 4 4 4 5 3

after
5 4 3 5 5 4 5 5 4

Comment: A recent similar question: http://stats.stackexchange.com/q/224941/3277
Answer: I wonder if you really want McNemar's test (more specifically the McNemar-Bowker test).  These are tests to see if the marginal proportions are the same (see here).  Under the assumption that pairings can be recovered from the orders of the two vectors, here is a table of your data with the marginal proportions computed:
bef = c(4, 3, 4, 5, 4, 4, 4, 5, 3)
aft = c(5, 4, 3, 5, 5, 4, 5, 5, 4)
table(bef, aft)
#    aft
# bef 3 4 5
#   3 0 2 0
#   4 1 1 3
#   5 0 0 2
table(bef)/sum(table(bef))
# bef
#         3         4         5
# 0.2222222 0.5555556 0.2222222
table(aft)/sum(table(aft))
# aft
#         3         4         5
# 0.1111111 0.3333333 0.5555556

Since you state that your variables are ordered, it seems more appropriate to assess if one set has higher values than the other.  That would use the Wilcoxon signed rank test:
wilcox.test(bef, aft, paired=TRUE)
#   Wilcoxon signed rank test with continuity correction
#
# data:  bef and aft
# V = 3.5, p-value = 0.1294
# alternative hypothesis: true location shift is not equal to 0

Because you have ties, you cannot use the exact version of the test; you use the asymptotic approximation. If that bothers you due to the small sample size, you could simulate the null and compute the p-value that way.  There are different ways to do that, but I'm not sure how much difference they will make in practice.  Bootstrapping is generally not recommended with small samples.  You could try a permutation-based version, or you could do a Monte-Carlo simulation of the null based on the marginal distribution of the values (ignoring timepoint).
Comment: The only assumption the Wilcoxon signed rank test makes about your response data is that you can say if 1 value is > another. You can do that here, so there isn't really a problem.  You cannot use the exact version of the test since there are ties; you use the asymptotic approximation. If that bothers you due to the small sample size, you could simulate the null and compute the p-value that way.
Comment: Thank you very much, I thought the Wilcoxon signed rank test would not be valid for qualitative data, because it doesn't take into account that the response variable can only take values from 1 to 5.
Answer: It is almost certainly because you have a pair of cells which both have zeroes (3, 5) and (5, 3). If you look at the way the test is defined that will lead to problems.
What to do is a problem. You could always merge categories but that may not make scientific sense. I think you may have to program your own solution. You could define a log-linear model of quasi-symmetry without including the offending cells (treating them as structural zeroes) but that may not be a sensible assumption either. More data would help but I suppose that may not be an option.
Comment: Thanks, so how can I test it in R?
Comment: @Mikmeadow I have edited my answer
Answer: You can use the exact binomial test. Let a be the number of cases where before < after. Let b be the number of cases where before > after.
H0: Getting a smaller value after is as likely as getting a bigger value after.
So you can use
bef = c(4, 3, 4, 5, 4, 4, 4, 5, 3)
aft = c(5, 4, 3, 5, 5, 4, 5, 5, 4)
a <- length(bef < aft)
b <- length(bef > aft)
binom.test(a, a + b, p=0.5)

Comment: Just to be clear, this is ***not*** an implementation of McNemar's test in this case. It's something more akin to a sign test. It's important for the analyst to be clear if they wish to treat their categories as nominal in nature or ordinal in nature, as the analysis will be different. ... (Although a binominal case can be used as an analogous test for McNemar's test in the case of a 2 x 2 table.) –

McNemar's test p-value NA


Using mod_rewrite to shutdown website

Question: I am trying to shutdown a website to everyone except my ip address. I almost have it working. I cannot access www.mysite.com, but I can access all folders that have another .htaccess file in them.
I have a .htaccess file in /www with the following code:
#Use this when website is down
RewriteEngine on

#this allows access through my ip
RewriteCond %{REMOTE_ADDR}  !^(66\.777\.888\.99)$
RewriteRule  !down.php$ /down.php [L]

Some folders in my site have .htaccess files in them. If I have a file with the line:
RewriteEngine on

I can still access the folder. For example, if I have the second .htaccess file in /www/about, then I can still access mysite.com/about (but the .css file included on that page actually loads down.php).
If I delete "RewriteEngine on" I get redirected to down.php.
Any ideas? I think my mod_rewrite gets confused with multiple .htaccess files.
Thanks!
Answer: how about putting:
Order deny,allow
Deny from all
Allow from ip.ad.dre.ss

in your .htaccess file? or even in the system wide httpd configuration?
Comment: because then you don't get a custom "down" message (unless you also change the 403 error message)
Answer: If you can reach your (virtual)host config, why not add these lines?
<Location />
    Order deny,allow
    Deny from all
    Allow from 184.108.40.206
    ErrorDocument 403 /down.php
</Location>
<Location /down.php>
    Order allow,deny
    Allow from all
</Location>

Comment: This (or almost identical to this) is what i use to lock down our production environments for updates.
Answer: Check your apache log file for errors, it's possible you'll be seeing a 404 somewhere for  about/down.php. Otherwise, default Mod Rewrite debugging tips follow:
Try adding this to your http config (Somewhere in the config, it doesn't work at htaccess or virtualhost level)
RewriteLog /tmp/rewrite.log
RewriteLogLevel 9

This will provide you with a line by line explaination of what it's trying to match against what regex, and what the final decision is.
Remove these lines afterwards, otherwise one day you'll discover you don't have nearly as much disk space as you thought you should...
Answer: Thanks for the tip about RewriteLog. I tested it out, and it looks like the .htaccess file in the site root only applies to directories that do not have their own .htaccess file with the line "RewriteEngine on".
note, 12.345.678.90 is my ip, and 99.888... is the ip I want to allow to see stuff.
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b878d060/initial] (1) [perdir /srv/www/mysite.com/about/] pass through

/srv/www/mysite.com/about/
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b879b090/subreq] (1) [perdir /srv/www/mysite.com/about/] pass through

/srv/www/mysite.com/about/index.html
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b879b090/subreq] (1) [perdir /srv/www/mysite.com/about/] pass through

/srv/www/mysite.com/about/index.cgi
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b879b090/subreq] (1) [perdir /srv/www/mysite.com/about/] pass through

/srv/www/mysite.com/about/index.pl
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b879b090/subreq] (1) [perdir /srv/www/mysite.com/about/] pass through

/srv/www/mysite.com/about/index.php
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b8791070/initial] (1) [perdir /srv/www/mysite.com/about/] pass through

/srv/www/mysite.com/about/css/about.css

12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b87df100/initial] (3) [perdir /srv/www/mysite.com/] strip per-dir prefix:

/srv/www/mysite.com/requires/css/header.css -> requires/css/header.css
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b87df100/initial] (3) [perdir /srv/www/mysite.com/] applying pattern

'down.php$' to uri 'requires/css/header.css'
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b87df100/initial] (4) [perdir /srv/www/mysite.com/] RewriteCond:

input='12.345.678.90' pattern='!^(99\.888\.777\.88)$' => matched
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b87df100/initial] (2) [perdir /srv/www/mysite.com/] rewrite

'requires/css/header.css' -> '/down.php'
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b87df100/initial] (1) [perdir /srv/www/mysite.com/] internal redirect with

/down.php [INTERNAL REDIRECT]
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b8790810/initial/redir#1] (3) [perdir /srv/www/mysite.com/] strip per-dir

prefix: /srv/www/mysite.com/down.php -> down.php
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b8790810/initial/redir#1] (3) [perdir /srv/www/mysite.com/] applying pattern

'down.php$' to uri 'down.php'
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b8790810/initial/redir#1] (3) [perdir /srv/www/mysite.com/] strip per-dir

prefix: /srv/www/mysite.com/down.php -> down.php

12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b8790810/initial/redir#1] (3) [perdir /srv/www/mysite.com/] applying pattern

'^(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])-((19|20)\d\d)/?(/([a-zA-Z0-9_-]{1,20}))?$' to uri 'down.php'
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b8790810/initial/redir#1] (1) [perdir /srv/www/mysite.com/] pass through

/srv/www/mysite.com/down.php
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b879d098/initial] (3) [perdir /srv/www/mysite.com/login/] strip per-dir

prefix: /srv/www/mysite.com/login/js/ajax_login.js -> js/ajax_login.js
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b879d098/initial] (3) [perdir /srv/www/mysite.com/login/] applying pattern

'^([a-z0-9]+/?){0,3}$' to uri 'js/ajax_login.js'
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b879d098/initial] (1) [perdir /srv/www/mysite.com/login/] pass through

/srv/www/mysite.com/login/js/ajax_login.js
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b8796080/initial] (3) [perdir /srv/www/mysite.com/login/] strip per-dir

prefix: /srv/www/mysite.com/login/images/ajax_busy.gif -> images/ajax_busy.gif
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b8796080/initial] (3) [perdir /srv/www/mysite.com/login/] applying pattern

'^([a-z0-9]+/?){0,3}$' to uri 'images/ajax_busy.gif'
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b8796080/initial] (1) [perdir /srv/www/mysite.com/login/] pass through

/srv/www/mysite.com/login/images/ajax_busy.gif
12.345.678.90 - [mysite.com/sid#b85a5dc8][rid#b8796080/initial] (1) [perdir /srv/www/mysite.com/about/] pass through

/srv/www/mysite.com/about/images/edit.png

As you can see, the about/index.php page contains a css file that is located in /requires. Above, the ip address rule applies to the css file and it gets redirected. The ip address rule gets skipped if I place a .htaccess file in /requires with just the line:
RewriteEngine on

Comment: I found the solution:

The .htaccess files in sub directories like /about should have the line:

RewriteOptions inherit

This makes them inherit the rules from the parent directories .htaccess

more info here: http://www.rankinglabs.com/Mod_Rewrite#Thank-You-For-Visiting!

However, I think I am going make a script for my server that I run to close the site. It will just de-activate subfolder .htaccess files when I want to close the website. Otherwise, the other rules in my root folder will be applied on every page load, and maybe hurt performance.

Thanks!
Answer: Do this in all the subfolder .htaccess files.
RewriteEngine On
RewriteOptions Inherit

See more: http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#RewriteOptions
Answer: why not doing the ip check with php?
can look sth. like this

< ?php if($_SERVER['REMOTE_ADRR'] != '66.777.888.99') exit; ? >

Using mod_rewrite to shutdown website


Why are there different formulas for the Quadratic Cost Function

Question: Some sources suggest the Quadratic Cost Function as the following formula.

But other sources suggest otherwise.

The difference is marginal but one is 1/n while the other is 1/2n
What is the difference that I am not catching here?
Answer: (This is copied verbatim from an answer of mine on Data Science: https://datascience.stackexchange.com/a/53189/73930. Perhaps we should address this topic on Cross Validated, too, and have an explicit answer.)
A major reason for using MSE is to optimize the parameters of a regression model. From calculus, you know how to find the minimum of a function by taking the derivative. That puts a "2" out in front, which is irritating to keep writing, so it is reasonable to put a "1/2" at the beginning so the derivative doesn't need a constant out front.
We get away with it because the minimum of $f(x)$ and $f(x)/2$ is achieved at the same value(s) of $x$.


Determine the limit measure

Question: Let $X=\{0,1\}^{\mathbb{Z}}$ be the space of all bi-infinite sequences $x=(x_n)_{n\in\mathbb{Z}}$ of zeros and ones.
On $X$, define the Left-Shift $\sigma\colon X\to X, (\sigma(x))_n=x_{n+1}$.
Now, consider the probability space $(X,B(X),\delta_x)$, where $B(X)$ is the Borel-$\sigma$-algebra and $\delta_x$ is the Dirac-measure for some fixed $x\in X$.
Now, for $B\in B(X)$, I am considering the measures
$$
\mu_n(B):=\frac{1}{n}\sum_{i=0}^{n-1}\delta_x(\sigma^{-i}(B))
$$
and would like to know to which measure the sequence $(\mu_n)_n\in\mathbb{N}$ converges as $n\to\infty$ (that it converges follows from the compactness of $M(X)$, the set of all probability measures on $B(X)$, in the weak*-topology).
Should be the Dirac measures.
Comment: I am not so sure that this actually converges in general. Compactness only gives you convergence of some subsequence (or even sub-net). Also, you should specify the topology with respect to which you consider the convergence.
Comment: 2 questions: Why must the limit measure exist? And. have you tried to identify the limit in any particular case, such as in the sequence of all $0$s, so $x_i=0$ for all $i$?
Answer: There are sequences of binary digits that are not Cesàro summable, that is, for which the sequence of partial averages $a_n=\sum_{i=1}^n x_i/n$ does not converge.  (You can construct examples by concatenating ever-longer blocks of consecutive $0$s and $1$s.  If the block boundaries are $n=3^k$, for instance, the quantities $a_n$ oscillate between about $1/3$ and $2/3$, as the block ending at $3^k$ is twice as long as all the previous blocks put together.)
Starting with such a sequence $x$ your measures $\mu_n$ do not converge in the weak* topology.  Take, for instance the projection map $f:X\to\mathbb R$ that sends the sequence $u=(u_n)$ to its $0$-th component $u_0$.  It is continuous and bounded, and clearly $\langle \mu_n, f \rangle=a_n$.  If the $\mu_n$ had a weak* limit $\mu$, then $a_n$ would converge to $\langle \mu, f\rangle$.
In response to comments: It is possible that you are confusing having limit points with has a limit, that is, converges.  Yes, your set of measures $\mu_n$ is relatively compact, and hence has convergent subsequences, but it need not be the case that those subsequences all converge to the same limit.
Comment: Yes.  Slightly more generally: if $x$ is periodic, with period $p$, then your limit measure splits its mass evenly between the $p$ shifts of $x$.  Or, if $x$ differs from a periodic sequence in finitely many entries, then the limit measure splits its mass between the periodic translates, and assigns mass $0$ to the original $x$ and its translates.  Your question was/is interesting, but you did not clearly indicate what you knew, tried, or what the context of the question was.
Comment: Yes.  Since $x$ has period $p$, the set of all translates of $x$ actually consists of $p$ distinct points, etc etc.
Comment: I'm sorry: I don't understand your last comment.  "Enough" for what?
Comment: Yes, I think you are right.

Determine the limit measure


Ad Hoc Wireless Network Between Vista IIS and Leopard

Question: I am trying to set up an Ad Hoc network between my PC running Vista and my Macbook running Leopard.  It's not just the Ad Hoc network though.  I have Visual Studio Developer Express and SQL Studio Express running on the PC.  When I launch a web service on localhost from Visual Studio, I want the Mac to be able to access the web service on my pc (localhost).  I am accessing the web service on the mac through the iphone simulator in xcode.
Basically, I am trying to access my Vista localhost web service from the iphone simulator in xCode on my mac over an ad hoc wireless network.
I tried setting up the ad hoc wireless network, but I can't even access the web service in Firefox on the mac using :
       http://(ipadress):(port)/webservice.asmx
At this point the Mac has not even shown up in my network on the PC.
Can anyone point me in the right direction or let me know if this is even possible?  Do I have to disable firewalls possibly?
Thanks
Answer: It shouldn't be a problem - by default in an ad-hoc environment where you are not running a DHCP server or setting static ip's the systems should both end up with automatically assigned private ip-addresses in the link-local address range ( 169.254.0.0/16 subnet for ipv4 )and should be able to communicate.  If your systems connect to each other at the physical layer but don't end up with ipv4 addresses in this range then one or other of the relevant zero-configuration services are probably disabled.
I'd be surprised if you didn't have to disable the client firewall on the target (Windows Vista) System. This is exactly the sort of casual connectivity that the Windows Firewall is intended to block unless you explicitly tell it not to.
In a Windows environment systems broadcast based NetBIOS name resolution mechanisms will kick in (provided they are enabled and the systems are configured to treat the ad-hoc network as trusted rather than public). I believe MAC OS X also supports NetBIOS name resolution but I don't know if it is enabled by default.
Apple's Bonjour and SSDP\UpNP on Microsoft systems provide more general purpose\robust name resolution services in link-local setups. You can install a Windows Bonjour client to make it easier for the systems to find each other
Comment: I downloaded bonjour for windows and changed the settings on my PC to disable the local firewall.

I get an ip-address in the range you specified on both machines and I can resolve the mac server in firefox through http://name-macbook.local/ .  However, I still cannot accomplish my goal of accessing the pc localhost on my mac.  Any more suggestions?

You have helped so much already.
Comment: Are you sure that the web service in question is listening on the ad-hoc IP address of the Wireless interface of the PC? Can you ping the PC from the Mac (you should be able to if the Firewall is off)? If you can then share a folder on the PC and you should be able to map to it from the Mac by following these instructions: support.apple.com/kb/HT1568 If that works then your problem is definitely with the web service on the PC not binding to the link-local address, possibly restarting whatever app\service manages it might help but you may need to explicitly configure it also
Comment: Wow!  I am almost there!  I was about to post back and say that the ip did not resolve, but when I seemingly switched my mac and pc wireless connections from the Ad-Hoc back to my internet wireless network, the ip resolved.  So the ad-hoc network must persist..  Now I can find the root of localhost from the mac firefox browser, but I can't get to the port(?) my web service is on.  I am trying to access http://localhost:49973/BaseballWebService/ using http://192.168.0.199:49973/BaseballWebService/ but nothing.  http://localhost/ resolves fine.  Any more suggestions?  Thanks so much!
Comment: Here is what I figured out:   http://localhost/ and http://192.168.0.199/  both resolve to the same page.  But http://localhost:49973/BaseballWebService/Service.asmx resolves the web service and  http://192.168.0.199:49973/BaseballWebService/Service.asmx cannot find the webservice.  FYI localhost redirects to localhost/xampp/  Could that be a problem?


Removing Null values from an Array Collection using Flex

Question: I have an ArrayCollection that I want to have all null or empty values removed.
What line in the code might accomplish this?
Answer: This is the faster way in terms of performance:
<code><mx:Script><![CDATA[
    public function cleanArrayCollection(collection:ArrayCollection):ArrayCollection{
        var currentArray:Array = null;
        var newCollection:ArrayCollection = new ArrayCollection();
        for(var i:int = 0; i < collection.length; i++){
            currentArray = collection.getItemAt(i);
            if(currentArray != null && currentArray.length != 0){
                newCollection.addItem(currentArray);
            }
        }

        return newCollection;
    }
]]></mx:Script>
</code>
Edit: Removed critical bugs in logic.


How to implement SNMP TRAP originator in v2c with pysnmp

Question: I am implementing a SNMP command responder using pysnmp which will respond to SNMP GET/GETNEXT/SET and also will originate SNMP TRAP messages based on events. I have already implemented GET/GETNEXT/SET based on this example but facing issues with TRAP. For TRAP I have followed this example which is for SNMP v1. I have converted it for v2c as instructed(changing line 31,32 and excluding 39-41). It worked, originated a TRAP message in v2c. But I want to originate a TRAP message with specific OID and octet string. Couldn't find any example of this. How can I do this?
Answer: Debian's package python-pysnmp4-doc v4.2.5-1 contains trap-v2c.py
#
# Notification Originator
#
# Send SNMP TRAP notification using the following options:
#
# * SNMPv2c
# * with community name 'public'
# * over IPv4/UDP
# * send TRAP notification
# * to a Manager at 127.0.0.1:162
# * with TRAP ID 'coldStart' specified as an OID
# * include managed objects information:
#   184.108.40.206.184.108.40.206.0 = 'Example Notificator'
#   184.108.40.206.18.104.22.168.0 = 'Notificator Example'

from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
from pysnmp.entity.rfc3413 import ntforg, context
from pysnmp.proto.api import v2c

# Create SNMP engine instance
snmpEngine = engine.SnmpEngine()

# SecurityName <-> CommunityName mapping
config.addV1System(snmpEngine, 'my-area', 'public', transportTag='all-my-managers')

# Specify security settings per SecurityName (SNMPv2c -> 1)
config.addTargetParams(snmpEngine, 'my-creds', 'my-area', 'noAuthNoPriv', 1)

# Setup transport endpoint and bind it with security settings yielding
# a target name
config.addTransport(
    snmpEngine,
    udp.domainName,
    udp.UdpSocketTransport().openClientMode()
)
config.addTargetAddr(
    snmpEngine, 'my-nms',
    udp.domainName, ('localhost', 162),
    'my-creds',
    tagList='all-my-managers'
)

# Specify what kind of notification should be sent (TRAP or INFORM),
# to what targets (chosen by tag) and what filter should apply to
# the set of targets (selected by tag)
config.addNotificationTarget(
    snmpEngine, 'my-notification', 'my-filter', 'all-my-managers', 'trap'
)

# Allow NOTIFY access to Agent's MIB by this SNMP model (2), securityLevel
# and SecurityName
config.addContext(snmpEngine, '')
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))

# *** SNMP engine configuration is complete by this line ***

# Create default SNMP context where contextEngineId == SnmpEngineId
snmpContext = context.SnmpContext(snmpEngine)

# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator(snmpContext)

# Error/confirmation receiver
def cbFun(sendRequestHandle, errorIndication, cbCtx):
    print('Notification %s, status - %s' % (
        sendRequestHandle, errorIndication and errorIndication or 'delivered'
      )
    )

# Build and submit notification message to dispatcher
ntfOrg.sendNotification(
    snmpEngine,
    # Notification targets
    'my-notification',
    # Trap OID (SNMPv2-MIB::coldStart)
    (1,3,6,1,6,3,1,1,5,1),
    # ( (oid, value), ... )
    ( ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
      ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) ),
    cbFun
)

print('Notification is scheduled to be sent')

# Run I/O dispatcher which would send pending message and process response
snmpEngine.transportDispatcher.runDispatcher()


Show related content. Search results?

Question: I am working on an Equipment Checkout system using Drupal 7, MERCI, views, panels, rules, and many other modules. I am working for a community college in Oregon. I am upgrading features on an already running system that was built by myself with the help of a few other people last year. The system is offline for the summer.
One of the features that I am trying to implement is that when we pull up a customer account, we also see content related to the customer blog posts, reservations, and some custom content types.
I have created a block called 'Customer History' on the customer view for the information to be displayed.
So now I need to figure out how to get the content into that block.
I'm thinking that I could somehow do a search for the customers name and display results in the block. What do you think? Is this a good way to go?
Any help would be great thank you.
Answer: Views is probably your best option, using a contextual filter, and various Views Blocks
If for example the url was www.mysite.com/user/12/profile, you could list all of any number of content types where the user id matches 12.
The specific answer depends on the structure however. If you include that information, I will update this answer with more specific direction.
EDIT 1:

create a separate view for each content type you want visible on the user's page
for each, set it as a BLOCK, not a page, and set the fields and order, etc as appropriate
set a contextual filter - this will depend on your structure, but I will show one as an example and you should be able to extrapolate. Contextual Filter->Content:Author uid
Contextual Filter, When not Available -> Provide Default Value, Raw Value from URL, Path Component 2 (for /user/12/*)
go to admin/structure/blocks and you should see the new views blocks. set them to only show on user/* for example to show in the profile pages, and place the blocks in the appropriate region
Comment: Yea! Thank you for your help Geoff :) A few additional pieces of information that might be useful. I am running Drupal on a local host server, If that matters and the customers are custom content types. The URL to our "Damaged Items" customer is `code`localhost:8082/node/2527`code` We use this account to temporarily remove items from inventory when they are getting repaired. Could you please tell me what structure you need from me? Thank you again
Comment: I have been working through your instructions and have a few questions. I created 2 views and set them both as a block. The next instruction was to "set the fields and order, etc" Im not sure what fields to set. I would like to display a list of teasers, similar to a search engine result. The next instruction is to choose a contextual filter and I got lost. I did some looking around on the topic but i am still confused. Can you help me figure out what contextual filter I need to choose?
Comment: Followed all your instructions, and from what I can gather the contextual filter is going to look in the url at position 1 for the author id. I'm assuming at some point I need to tell Drupal to put the author ID into the url at position 1? Also I'm not sure if this is relevant here but, Our checkout is run by an attendant that will be viewing multiple customer accounts in a shift. So the customer never has access to the system. Is Author ID still the best choice?  Thank You again Geoff you are a life saver :)
Comment: I set the contextual filter to Content:L# (This is the customer number) Then in the preview area I typed in an active L# and I get a teaser of the customer content type. So some success! now if we can get it to display reservation content types instead of customer content types. While in the contextual filters, I stumbled across Search: Search Terms. While testing it seemed to return the search results like I am looking for. Have you ever used this filter?
Comment: I set the Filter criteria to Content: type(=Reservation). When I type in an L# in the preview area nothing shows up. Thinking there might not be content to display, I than created a reservation with my L# and tried again, and again nothing came up. Any Ideas? Is there maybe something I need to set in the L# field?
Comment: Does the contextual filter refer to a field that is in the reservation content type or in the customer content type? The field in the reservation content is called field_customer and is formatted (L#xxxxxxxx - Student Name). And in the customer content type the two are separate fields, field_name and field_l_. So the information is not formatted the same. Could this be our problem? Thanks Again man :)
Comment: The Current content type is Customer and the field is field_l_. So i set the contextual filter to field_l_ and the filter to type=reservation. I then type in an L# with associated reservations, and nothing shows up in the preview area. Does the field  need to be in the reservation too?
Comment: ah.. that makes lots of sense. Im going to do some rearranging of my fields so that the field that is in my reservation content type will be in the customer content type also. Ill get back to you on my finding :)
Comment: Once I got the same field in both content types things worked great! Thanks again :) It is exciting when things work. So now can you help me get the field into the URL position 4?
Comment: We will access the Customer Accounts via links from two sources; search, and a direct link from reservations. But mostly from search. I have two views created "Customer Related Reservations", and "Customer Related Forum Posts". Both are displayed in a Mini Panel called "Customer Related Information". The Mini Panel is set to be displayed in the content area, and set only to be displayed on Customer content types.
Comment: for the search, if you implement the search as part of a view, it is quite simple - if you want to use core search, you will need to write a custom module to handle it. The reservation depends on too many variables to get into in this comment
Comment: The search is implemented as part of a view, lets start there.
Comment: The search is set to display as a table. The field l# is already one of the fields displayed, so I did not create a new field, and kept it displayed. Added Global:Custom Text to the fields. Under Rewrite results, I ticked Output this field as a link, in the link path I put [field_l_]. Tested and no luck. I changed the other view to look in the URL 1st position for the L#, and again no luck. I noticed that the url that is displayed when the Customer Page is loaded does not have the information in it, it looks like the url before I inserted the Global Text.
Comment: The Global Text does not appear in the table, is it supposed to give me a link to click on that appears in the search results? After searching for a customer the url looks like this localhost:8082/search-customers?field_l__value=00229635 I then click on the title of the customer page and it loads the customer content type, localhost:8082/node/3598
Comment: Had some-kind of brain malfunction yesterday, I was editing one view and testing a different view. Now that I am back on track, The URL I get when I click on the global text link is localhost:8082/00229635 The URL to the actual customer account is localhost:8082/node/3598 It looks like I need to change the link path somehow? This makes me think I should be saving my customer accounts to be the L# instead of the nid. If this would help I can implement it.
Comment: OK, Im good at tinkering, it's gotten me this far lol :) It looks like there is a prefix field, that I set to /node/ then my url should be /node/[field_l_], then I rename my customer accounts to be the same as [field_l_]. I think I saw an auto rename node feature. Thank you for helping me get thro a lot of this, I can already see ways to use this in other places on my site. I'll ping here again if I have further questions. Thanks Again!
Comment: Thats a good idea! once I get the link correct, I should end up with localhost8082:node/[nid]/[field_l_], and tell my view to look in the 3rd spot for the information?
Comment: OMG it worked!!! You Rock Geoff! Thank you for sticking around, your a rock star! :)
Comment: no problem - I will update the answer with everything we talked about tonight or tomorrow, and you should accept this answer so the question doesn't appear unanswered going forward

Show related content. Search results?


How can I change the "Edit" tab name to something more meaningful?

Question: I would like to change the Edit tab from Edit to Edit Client.  The content type is Client.
I tried using the following code in the bartik.theme file in the web/core/themes directory (running drupal 8.5.4).
function bartik_preprocess_menu_local_task(&$variables) {
  if (isset($variables['element']['#link']['title']) && $variables['element']['#link']['title'] == 'Edit') {
    $node = \Drupal::request()->attributes->get('node');
    if ($node && $node->getType() == 'client') {
      $variables['link']['#title'] = t('Edit Client');
    }
  }
}

Comment: I hope you're just using Bartik here for testing purposes. You're not suppose to touch anything in /core folder. Because when you update Drupal, it will override everything inside the /core folder; thus, you will lose all your changes. If you like Bartik and want to use it as your theme, then you should create a new theme and use Bartik as your base theme.
Answer: Use hook_menu_local_tasks_alter see the docs. You can get a dynamic title combining tokens and the translation API.


Deserialize an array of struct

Question: Once again I'm receiving structs via UDP from a C++ programm,
Now I ported the structs to C#, Example:
[Serializable]
struct sample
{
public int in;
public byte[] arr;
public int[] arr2;
public float fl;
}

Ok so how does the Deserializer know when one array ends and the other begins?
Can specify somehow how big the array is?
I don't want to use fixed, since this makes my code unsafe, and I also can't use a Constructor since structs are not allowed to contain constructors without parameters.
Any suggestions?
//edit:
the arrays are known to be 32 and 4 long.
the problem is that I don't know how to pass this information to the deserialiser
then sender is C++ an works like this:
char* pr = &sample;
int i=0;
while (i<sizeof(sample))
{
 udp.send(*(pr+i))
 i++;
}

Comment: ok switching the whole thing to classes helps with the constructor problem,
but I still don't geht HOW this works, can anybody explain?
Comment: How *what* works? What is serializing the C++ here? You haven't told us what you have currently in terms of your attempt at deserialization, so it is hard to comment on "HOW this works"...
Answer: Now that you have told us that the lengths are of pre-defined length, then the following statement becomes clearer:

I don't know how to pass this information to the deserialiser

In fact, it becomes moot. There is no pre-defined serializer that is going to help you here. You have two options:
A: write your own serializer, and process the data now that you know the format - perhaps using BinaryReader:
using(var reader = new BinaryReader(source)) {

    int in = reader.ReadInt32();
    byte[] arr = reader.ReadBytes(32);
    int[] arr2 = new int[4];
    for(int i = 0 ; i < 4 ; i++) arr2[i] = reader.ReadInt32();
    float fl = reader.ReadSingle();

    var obj = /* something involving ^^^ */
}

B: buffer 56 bytes, and use really nasty unsafe / fixed / pointer-banging code
I strongly suggest the first. In particular, this will also allow you to address endianness if required.
IN THE NAME OF EVERYTHING SACRED TO YOU, DO NOT DO THIS:
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Explicit)]
unsafe struct sample
{
    [FieldOffset(0)] public int @in;
    [FieldOffset(4)] public fixed byte arr[32];
    [FieldOffset(36)] public fixed int arr2[4];
    [FieldOffset(52)] public float fl;
}

static class Program
{
    unsafe static void Main()
    {
        byte[] buffer = new byte[56];
        new Random().NextBytes(buffer); // some data...

        sample result;
        fixed(byte* tmp = buffer)
        {
            sample* ptr = (sample*) tmp;
            result = ptr[0];
        }

        Console.WriteLine(result.@in);
        Console.WriteLine(result.fl);
    }
}

For larger buffers, you can treat ptr as an unsafe array of multiple sample, accessed by index:
int @in = ptr[i].@in;

(etc)
But honestly... there are so many things "evil" with that, I honestly don't know where to begin... just... unless you know absolutely what every line in there is doing, have done it before, and understand all the traps... DON'T EVEN THINK ABOUT IT
Comment: well i'm actually used to pointers, but I agree that it would be better to find a way around them.
I'm hate to write an custom deserialzer, but well that seems to be the right way.
Thank you all for your help
Answer: It depends on the format used to pass the structure over the wire.
If say it's json, then each field will have a key and the array will be surrounded by [].
If say it's xml, then you would expect an arr node with child nodes.
If it's some arbitrary format, you need to know the format.
Deserializers have some default behavior but if the passed data is not in default format, you need to tell them exactly how to deserialize.
Comment: The sender just puts a pointer to the start of the struct and sends byte after byte, i guess this is the same as arbitrary.
so _I_ know how long the array is, but how do I tell the serialiser?
Comment: @ChristianElsner and what do you mean by "a pointer" in this context? A pointer is meaningless once serialized...
Comment: Given your code, it is highly dependent on the implementation of your computer (the C++ one), how your array will be written to the wire. It will be dependent on how your computer stores arrays in memory. If you have control over that udp code, I'd suggest you change it to not use a byte dump, instead decide the format you want to write and then write it.
Comment: I cannot change the C++ code, I'm already very happy that I got read access to figure out how this stuff works...
On the behalf of being documented: Documented by Code
Comment: Well in that case, you can only hope to inspect the byte array, if it contains the 'length of the array' information. If it doesn't (and my guess is it will not), then you cannot do anything about it.
Answer: And how is the raw data documented? I would expect there to be something to tell you here, for example, I might expect it to say the format is (purely an example)

4 bytes NBO Int32 (in)
4 bytes NBO Int32 (length of arr)
len bytes (arr)
4 bytes NBO (length of arr2)
4 * len bytes (arr2, each in NBO Int32)
4 bytes IEEE-754 (fl)

You need to know the format.
Edit: if the C++ arrays are of a known fixed length, then you simply need to know those lengths in advance.

Deserialize an array of struct


bootstrap navbar links not clickable once uncollapsed Rails

Question: http://boiling-garden-2168.herokuapp.com open the link, when the window is small enough so the navbar collapses, and you click the icon-bar to uncollapse it, only my drop down and feedback link are able to be clicked. My login and register links are not able to be clicked on. Any idea why? I've been messing with this stupid bootstrap for days now. I finally got the collapse to work, but they are not clickable now. Also, I need the turbo links..

      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
    Toggle navigation

  </button>

    <% if logged_in? && current_user.status == 'career/education' %>
      <% if current_user.username == 'Curry' %>

<%= link_to 'Add skill', new_skill_path(@skill), class: 'navbar-brand' %>

      <% end %>

<%= link_to 'References', references_path, class: 'navbar-brand' %>

<%= link_to 'My Degree', courses_path, class: 'navbar-brand' %>

<%= link_to 'logout',  logout_path,    class: 'navbar-brand' %>

<%= link_to 'Search Jobs',  jobs_path,    class: 'navbar-brand' %>

<%= link_to '#', class: 'navbar-brand dropdown-toggle', 'data-toggle' => 'dropdown', "data-no-turbolink" => true do %>
        <%= current_user.username %>
      <% end %>

 <%= link_to "My Profile", user_skill_path(current_user) %>

 <%= link_to 'Edit My Profile', edit_user_path(current_user) %>

 <%= link_to 'My Library', user_skills_path(:id => current_user.id) %>

 <%= link_to 'My Docs/resumes',     resumes_path %>

      <%= link_to '#', class: 'navbar-brand', 'data-toggle' => 'dropdown' do %>
      Earn Skills
    <% end %>

        <% Category.all.each do |category| %>

            <%= link_to category.name, category_path(category) %>

          <% end %>

<%= link_to 'All Categories', skills_path %>

    <% elsif logged_in? && current_user.status == 'Employer' %>

<%= link_to 'logout',  logout_path,    class: 'navbar-brand' %>

<%= link_to 'Post Job',  new_job_path,    class: 'navbar-brand' %>

<%= link_to 'view/edit Jobs', job_path(:id => current_user.id), class: 'navbar-brand' %>

<%= link_to 'Search Users',  jobs_path,    class: 'navbar-brand' %>

<%#= link_to 'Our Jobs',     job_path, %>

      <%= link_to '#', class: 'navbar-brand', 'data-toggle' => 'dropdown' do %>
      View Skills
    <% end %>

        <% Category.all.each do |category| %>

            <%= link_to category.name, category_path(category) %>

          <% end %>

<%= link_to 'All Categories', skills_path %>

    <% else %>

<%= link_to 'log in',   login_path,    class: 'navbar-brand' %>

<%= link_to 'Register', new_user_path, class: 'navbar-brand' %>

      <%= link_to '#', class: 'navbar-brand', 'data-toggle' => 'dropdown' do %>
      Earn Skills
    <% end %>

        <% Category.all.each do |category| %>

            <%= link_to category.name, category_path(category) %>

          <% end %>

<%= link_to 'All Categories', skills_path %>

    <% end %>

Beta

<%= link_to 'Give us Feedback', 'http://www.facebook.com/jetpackedu', :target => '_blank' %>

Answer: Your .nav>li element has position: relative which is overlapping your links when collapsed.
Comment: @user3138341 Add the class `clearfix` to your ``
Comment: That sounds really promising. I'm assuming that is a default setting since I that isn't anywhere in the file? What would the recommended position type be? should it be float?
Comment: You sir, are awesome. How did you even know that?


How to remove whiteouts from overlayfs uppper layer?

Question: I have an OpenWrt-based system on an embedded device.
Rootfs is mounted as overlayfs
<code># mount
mtd:ubi_rootfs on /rom type squashfs (ro,relatime)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)
...
</code>
There is a number of changed files:
<code># find /overlay/upper/ -type f
/overlay/upper/etc/passwd
/overlay/upper/etc/sysstat/sysstat
/overlay/upper/etc/bluetooth/csr8x11-mac.psr
/overlay/upper/etc/shadow
/overlay/upper/etc/ethers
...
</code>
I need to revert them
Answer: Remove file from overlay, and then remount rootfs.
<code>rm /overlay/upper/etc/*
mount -oremount /
</code>


Matching %ff in Nginx rewrite rules

Question: I have some dubious requests coming into my server that contain %ff and %FF (e.g., /blog/%ffupdates/. I'm getting thousands of these daily and would like to start redirecting them to a 403. I currently have an endpoint that I use to blackhole things like this and would like to rewrite these URLs to point to that endpoint.
Currently, I am trying:
rewrite ^/.*?%ff.*?$ https://domain.com/forbidden permanent;

I fully understand that this might be too greedy of a match; however, I am just trying to get something to work initially.
Now, when I try this and view the debug log, it seems as though %ff is getting converted to � (yes, that's supposed to be the question mark diamond thingy).
For instance, there are things like this in the log:
*4 "^/.*?%ff.*?$" does not match "/blog/�updates/"

It seems that because %ff is converted, I cannot actually match the string.
I'm running Nginx 1.7.1 with SSL and SPDY.
Any thoughts?
Answer: You should be able to match this by regex. For instance:
location ~ /\xff/ {
    return 403;
}

Comment: Thanks so much! The exact regex did not work, but using `\xff` instead of `\%ff` worked well! Thanks!

Matching %ff in Nginx rewrite rules


discrete version of normal distribution?

Question: Just what the title says. I want to model probability of number of sales on a given day. I can't use poisson/binomial, because there are indications that the standard deviation of the sales might differ between two products with the same average number of sales.
Is there a discrete version of normal distribution, or something like poisson distribution in which you can independently set the variance?
Answer: For count data like you describe, you probably want a negative-binomial distribution.  This is an extension of the Poisson distribution that has an additional parameter that allows for the variance not to be tied to the mean.  This is a distribution that is commonly used for count data, either for straight count data, or in problems where you also have other explanatory variables (where you can use a negative-binomial GLM).  There are some other statistical models that are used for count data, but that is where I would start.  You needn't worry about the connection to the normal distribution here; just look for a distribution that is appropriate to your count data.


Interpreting negative cosine similarity

Question: My question may be a silly one. So I shall apologize in advance.
I was trying to use the GLOVE model pre-trained by Stanford NLP group (link). However, I noticed that my similarity results showed some negative numbers.
That immediately prompted me to look at the word-vector data file. Apparently, the values in the word vectors were allowed to be negative. That explained why I saw negative cosine similarities.
I am used to the concept of cosine similarity of frequency vectors, whose values are bounded in [0, 1]. I know for a fact that dot product and cosine function can be positive or negative, depending on the angle between vector. But I really have a hard time understanding and interpreting this negative cosine similarity.
For example, if I have a pair of words giving similarity of -0.1, are they less similar than another pair whose similarity is 0.05? How about comparing similarity of -0.9 to 0.8?
Or should I just look at the absolute value of minimal angle difference from $n\pi$? Absolute value of the scores?
Many many thanks.
Comment: (cont.) Understanding of positive or negative coefficient is the same in both instances. Negative coef. means that positive deviations/values of one vector tend to pair with negative deviations/values of the other. Whether this means the vectors are "similar" or on the contrary "highly dissimilar" is dependent on what is the meaning of positive and negative deviations/values in the data, for you.
Comment: Cosine similarity tag says: `An angular-type similarity coefficient between two vectors. It is like correlation, only without centering the vectors.` The only difference between the two is that in correlation deviations (moments) - which are being cross-multiplied - are from the mean, while in cosine deviations are from the original 0 - i.e. they are the values as they are.
Comment: @ttnphns Thank you very much for your comment! It does inspire me to think about cosine similarity in a new way. In my use case, perhaps I can think of it as a difference in end results: if the correlation of Doc A and B is negative, and an uni-topical journal X includes Doc A, then it is less likely that X includes B as well, from some mean probability. Does this interpretation sounds valid to you?
Comment: I dare not to say because I don't know your data, meaning of values in it, and your study.
Answer: Let two vectors $a$ and $b$, the angle $θ$ is obtained by the scalar product and the norm of the vectors :
$$ cos(\theta) = \frac{a \cdot b}{||a|| \cdot ||b||} $$
Since the $cos(\theta)$ value is in the range $[-1,1]$ :

$-1$ value will indicate strongly opposite vectors
$0$ independent (orthogonal) vectors
$1$ similar (positive co-linear) vectors. Intermediate values are
used to assess the degree of similarity.

Example : Let two user $U_1$ and $U_2$, and $sim(U_1, U_2)$ the similarity between these two users according to their taste for movies:

$sim(U_1, U_2) = 1$ if the two users have exactly the same taste (or if
$U_1 = U_2$)
$sim(U_1, U_2) = 0$ if we do not find any correlation between the two users, e.g. if they have not seen any common movies
$sim(U_1, U_2) = -1$ if users have opposed tastes, e.g. if they rated the same movies in an opposite way
Comment: From a machine learning standpoint, is a negative cosine similarity benign or bad?
Answer: Its right that cosine-similarity between frequency vectors cannot be negative as word-counts cannot be negative, but with word-embeddings (such as glove) you can have negative values.
A simplified view of Word-embedding construction is as follows: You assign each word to a random vector in R^d. Next run an optimizer that tries to nudge two similar-vectors v1 and v2 close to each other or drive two dissimilar vectors v3 and v4 further apart (as per some distance, say cosine).  You run this optimization for enough iterations and at the end, you have word-embeddings with the sole criterion that similar words have closer vectors and dissimilar vectors are farther apart. The end result might leave you with some dimension-values being negative and some pairs having negative cosine similarity -- simply because the optimization process did not care about this criterion. It may have nudged some vectors well into the negative-values. The dimensions of the vectors dont correspond to word-counts, they are just some arbitrary latent concepts that admit values in -inf to +inf.
Answer: Do not use the absolute values, as the negative sign is not arbitrary. To acquire a cosine value between 0 and 1, you should use the following cosine function:
(R code)
cos.sim <- function(a,b)
{
  dot_product = sum(a*b)
  anorm = sqrt(sum((a)^2))
  bnorm = sqrt(sum((b)^2))
  minx =-1
  maxx = 1
  return(((dot_product/anorm*bnorm)-minx)/(maxx-minx))
}

(Python Code)
def cos_sim(a, b):
    """Takes 2 vectors a, b and returns the cosine similarity according
to the definition of the dot product"""
    dot_product = np.dot(a, b)
    norm_a = np.linalg.norm(a)
    norm_b = np.linalg.norm(b)
    return dot_product / (norm_a * norm_b)

minx = -1
maxx = 1

cos_sim(row1, row2)- minx)/(maxx-minx)
```

Comment: Where do you set minx and maxx? You might apply this min-max normalization to vector dimensions, instead of calculated distance.
Answer: Cosine similarity is just like Pearson correlation, but without substracting the means. So you can compare the relative strengh of 2 cosine similarities by looking at the absolute values, just like how you would compare the absolute values of 2 Pearson correlations.
Answer: This article illustrates why a negative cosine similarity indicates vectors that are not similar (opposite direction in the vector space):
Understanding Vector Similarity
Comment: Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer).

Interpreting negative cosine similarity


Order of Natural Numbers in Algorithms

Question: Could anyone describe, why this is a True statements?
if $f_i$ be a function of natural numbers to natural numbers and $f_i(n)=O(n)$ then $\Sigma_{i=1}^{n} f_i(n)=O(n^2)  $
Comment: The statement is not true as written... see answer below.
Answer: The statement is false as written.  Suppose that each $f_{i}(n)$ satisfies $i^2 n \leq f_{i}(n)\leq 2 i^{2}n$.  Then it is the case that $f_{i}(n)=O(n)$ (you can take the constant for $f_{i}(n)$ to be $2i^2$).  Then, your function $f$ is lower-bounded by $\sum_{i=1}^{n} i^2 n \leq \sum_{i=1}^{n}f_{i}(n)$ and $\sum_{i=1}^{n}i^2 n \sim n^3$.
In order for the statement to be true, you need each $f_{i}(n)$ to be $O(n)$ using one constant for all of them, i.e. $f_{i}(n)\leq Cn$ for all $i$.
EDIT: and, you need the bound to be true for all $n\geq N$ (where the same $N$ works for each $f_{i}$).
Comment: You also need a single constant $N$. Alternatively you can say that the $N_i$ and $C_i$ must be bounded.
Comment: That is true.  Thanks for pointing that out.
Comment: @DaviedZuhraph, Which part does not make sense?  I'm happy to expand if you explain what you do/do not understand.
Comment: @DaviedZuhraph, The easiest way to make it true would be to say, instead of each f_i(n)=O(n), that for every i, f_i (n) <= Cn for all n>N (i.e. the same C and N work for every f_i).
Comment: @DaviedZuhraph, the way it is stated now, it is false.
Answer: For every $i$, there is an $N_i$ and a $C_i$ such that for all $n\ge N_i$, $f_i(n)\le C_in$.
Then, taking $N=\max_iN_i$ and $C=\max_iC_i$, for all $n\ge N$, $\sum_if_i\le \sum_iCn=Cn^2$.
This reasoning does not hold if the $N_i$ or $C_i$ are unbounded.
Comment: There may be a typo in the problem.  I don't think you can take the max (since you must think of n as going to infinity.  For example, suppose that f_i(n) <= 2i^2 n and f_i(n)>=i^2 n.  Then certainly f_i(n)=O(n), but when you sum them, you get a lower bound of sum i^2 n ~ n^3 (summing over i from 1 to n).
Comment: It also works with $C$ being the average of the $C_i$.
Answer: Since you are summing from 1 to n, over a function that already is $O(n)$, you're taking the function $n$ times for every number between $1$ and $n$. This should pop out to you as $n\cdot n = n^2$.

Order of Natural Numbers in Algorithms


Should I use classification or regression model to predict discrete/ordinal movie ratings?

Question: I'm making a ML model that predicts movie ratings from 1-10 (discrete). With scikit, is it better to use a classification model with 10 classes or a regression model that predicts a continuous variable that I can round to the nearest whole number? I like that the regression model takes into account the ordinal nature of the rating.
Is a regression model the better choice? My data is left-skewed with more high ratings than low ones. What are good metrics to check my model's performance?
Comment: Why not try both and compare their performance using standard model fit statistics like cross-validated mean squared error or classification accuracy?
Comment: Good question.. how much data do you have to train with?  I agree with Noah, try both. May be classification but the problem of skewing makes it an imbalanced classification problem, so you will have to take care of that. If you are going for classification, then go for accuracy with confusion matrix as metric. If you are going for regression, go for RMSE, MAPE etc for evaluation of model performance.
Answer: ORDINAL REGRESSION EXISTS!
You realize that there are issues with using classical regression or classification approaches in this situation with and ordinal outcome. Fortunately, you do not have to shoehorn your problem into such models, because there is ordinal regression!
A major proponent of ordinal regression is Frank Harrell, who has much discussion of ordinal modeling in his Regression Modeling Strategies textbook. Reading the pertinent sections there (he has related notes on his website) could be a place to start. His blog also has some posts about ordinal regression, such as this one.


In non-euclidean geometry, can hypotenus of rightangle triangle be shorter than sides?

Question: Disclaimer. This is only a recreational question in geometry...

In euclidean geometry, the following picture is definitely inconsistent!

Of course, the issue is that, the picture suggests that the diagonal is at most as long as the sides, i.e $\mathbf{\sqrt{2} \le 1}$ (a contradiction!).

Question (loose). Is there a (necessarily non-euclidean) geometry in which the picture would be consistent ?

Noneuclidean geometry
To make sense of the above question, one needs to first extend certain euclidean geometry. Viz

A straight line is a geodesic curve.
Two straight lines $\mathcal L_1$ and $\mathcal L_2$ are perpendicular at a point $A$ if their tangents at $A$ are perpendicular
A square $ABCD$ of side length $L$ is a quadruple of four lines (i.e geodesic curves!) $AB,BC,CD,DA$ such that

Perpendicular sides. $AB \perp BC$ at $B$, $BC \perp CD$ at $C$, and $CD \perp DA$ at $D$, $DA \perp AB$ at $A$.
Equal side lengths. $\ell(AB) = \ell(BC) = \ell(CD) = \ell(DA) = L$.

The diagonals of a square are the straight lines (i.e geodesics) $AC$ and $BD$.
Question (refined). Is there geometry (i.e smooth riemannian manifold) in which there exists a square of side length $L$ both of whose diagonals have (equal) length which is $L$ or less ?
Comment: With the refinement to your question, there's a new problem: a (uniform) geometry in which squares — under your definition — exist _is_ Euclidean! One can speak of equilateral right triangles in spherical geometry (the 'octant' triangle), and equilateral right pentagons (or hexagons, etc.) in hyperbolic geometry, but an equilateral right-angled quadrilateral implies a Euclidean space.
Comment: There is no "th" in "hypotenuse". It's spelled like this. Maybe you mix it up with "hypothesis", but that is a different Greek word (both contain "hypo-" meaning "under-", but the following verb is different.)
Comment: Great to know, thanks!
Comment: Hum, interesting. By "uniform", do you mean "isotropic", in the sense that the volume element is position-independent ?
Comment: @StevenStadnicki Also please feel free to propose a modification of the question for which only solutions are "nontrivial" geometries :)
Comment: I don't think it is possible for any 2D plane, the sides must completely overlay with the diagonals to make L(side)=diagonal which means on an extreme saddle diagonals are still slightly longer than sides.
Answer: A hypotenuse by definition is the longest side in a right triangle (which is opposite the right angle). In flat geometry, such triangles can have only one right angle, hence only one hypotenuse.
In geometries where the sum of angles in a triangle is less than $180°,$ there will also be one hypotenuse. However, in geometries where the sum of the angles exceeds this value, then there may well be more than one hypotenuse. Also, since in this kind of geometry, a triangle may be simultaneously right-angled and obtuse angled, then it is possible for a side to be longer than each of the sides opposite the right angle. Thus this answers your question in the positive. However such questions are already moot here since the Pythagorean theorem doesn't hold, so what's the point of defining hypotenuses same as they are defined in flat geometry, where they are singled out there because of their importance and the many relationships they reveal?

OK, I've read the edited question, and the germ of the answer is contained in the above answer -- I'll highlight this. Your question is equivalent to asking if there exist geometries where an isosceles triangle with only one right angle (where the angle is contained between the equal legs) has the base not more than the equal legs. Again, the answer is that that happens in some geometry where the angle sum in triangles is more than $180°,$ for then we would have a case where the base angles are equal to or more than $90°$ each, which would make the legs of the triangle be equal to or even exceed that of the side opposite the unique right angle.
Comment: OK great, this confirms what I thought: there exist positively curved curved manifolds with large squares that have this property!
Comment: @Allwonder Thanks for the input. Some clarification. Forget about the term "hypothenus" as defined in usually in geometry. I've given my own definition in the question. By "hypothenus", I mean the diagonals in ABCD, i.e the coords AC and BD. My use of the term in the question title was only to draw attention. In fact, there is no mention of "triangle" in the body of my question :)
Comment: @dohmatob I didn't see the attached image before. Did you just add it? Also, it seems the question has been largely edited now. Am I right? I'll read it again though and see what comes to me.
Comment: @Allawonda No, the image was always there. The question is not largely edited I just changed all instances of "hypothenus" to "diagonal", to be more explicit.
Comment: @dohmatob OK. That must have been the network or device then. I've now edited my answer.
Comment: @dohmatob Be careful with your assumptions. In a sphere (which is a positively curved manifold), if 4 sides are of equal length and the angles are equal, then the angles must be greater than right angles, so a square as you might be trying to imagine it doesn't exist.
Comment: @MarkS. Such things need not exist in every non-euclidean geometry. The point is that it is possible for such to exist.


How can I estimate a population size from the probability of randomly drawn members?

Question: I have a finite set $X$ of unknown size.  From that I independently draw a multiset of samples $S\subset X$.  For each sample $s\in S$ I can give the exact probability $p(s)$ with which it has been drawn from $X$ such that
$\sum_{x\in X}p(x)=1$ and how often it has been drawn.  I also have a lower bound $l\le p(s)$ for the probability of each sample.
Given this information, how can I estimate the size of $X$?
A mark and recapture approach is not going to work because $|S| \ll |X|$ by several orders of magnitude.  I have drawn about a billion of samples so far without encountering any duplicates.
Comment: Statement not clear (to me anyhow). Perhaps look at [mark-recapture](https://en.wikipedia.org/wiki/Mark_and_recapture#targetText=Mark%20and%20recapture%20is%20a,within%20the%20sample%20is%20counted.)
Comment: @BruceET The population $X$ is much larger than the sample size I can reasonably achieve.  I have so far drawn a few billion samples without any duplicates, so I don't think mark-recapture is feasible.  What part of the statement is unclear?
Comment: "For each sample $S∈s$ I can give the probability $p(S)$ it has to be drawn from $X$ such that ..." Maybe give examples from your work. How do you get the probabilities? Exact or estimated?
Comment: @BruceET I can compute these probabilities exactly.  I am working on the same problem [this question](https://stats.stackexchange.com/q/357170/191568) is about (sampling vertices of a graph that have a given distance from a fixed vertex).  Once I found a vertex with the right distance, I can exactly compute the probability with which it was found.
Comment: @BruceET Also, I'm sorry for the wrong spelling and grammar.  I have fixed the post.
Comment: @BruceET Oh, a mark and recapture approach is likely not going to work because the base population is very large.  I have so far not been able to get any duplicate samples at all.
Answer: DISCLAIMER: Simulation has shown that this is not a good estimator but it might be helpful for further ideas
I propose the following estimator: With sample space $S$ and sample $s_1, ..., s_n$, we could use $\widehat{\#S}= n \times\frac{1}{\sum_{i=1}^np(s_i)}$ as an estimator for $\#S$
The theoretical idea is the following:
We have a random Variable $X$ that has the probability values $p_s:=p(s)$ as the sample space and a distribution, such that $P(X=p_s)=p(s)$, i.e. the numeric value of the sample and its probability coincide.
We then estimate the mean of this Random Variable $X$, i.e.
$E[X]=\sum_{s\in S}p(s)^2$ by taking the sample mean $\sum_{i=1}^np(s_i)$ In addition to that we use the fact that  $nE[X]=1 \iff n = \frac{1}{E[X]}$
So we use an unbiased estimator for $E[X]$ and plug it into the formula
$n=\frac{1}{E[X]}$ (which means that the estimator for $\#S$ is not necessarily unbiased anymore.
Maybe we could also estimate the distribution of $X$ in order to get a correction-factor of our estimate that takes into consideration how much $1/E[X]$ deviates from $E[1/X]=n$.
Comment: I do draw individual elements.  $S\subset X$ is the set of samples I draw of which the probability $p(s)$ for each $s\in S$ is known.  Here, $p(s)$ is the probability of drawing $s$ from $X$.
Comment: Ok then the last paragraph is unnecessary but the rest might still help you. I will simulate this procedure tomorrow to check how well it works and update my post.
Comment: I actually thought about something similar.  We do know about the distribution of probabilities because we sampled them, so I guess there should be a way to make that exact.
Comment: Re your formula: although this statistic is *an* estimator, what properties does it have?  Why should it be any good at all?  I don't follow your remarks about "uniformly distributed," because if that assumption is true, then all you have to do is compute a single probability $p_i$ and recover the population size as $1/p_i.$
Comment: As in the first line: "This is not a known method (at least to me) but just an idea that makes sense to me and might be worth exploring."
Comment: You were very close.  Turns out this can be modeled as a *size biased sample* for which it holds that the harmonic mean of the biased sample equals the arithmetic mean of an unbiased sample over the same space.  The quantity we sample is the probability and the average probability is the reciprocal of the size of the sample space.  Thus, we can compute the sample space size by taking the reciprocal of the harmonic mean of probabilities as sampled.


Install libwebkitgtk for Linux

Question: I ran this command on Linux (CentOS):

sudo yum install libwebkitgtk-1.0-0

but then I get this message:

No package libwebkitgtk-1.0-0 available.

Error: nothing to do

Any suggestions? Trying to upgrade to Java 11.
Answer: ihave tested with webkit2gtk3 on centos8,and it's executed without problem.

yum install webkit2gtk3

Install libwebkitgtk for Linux


Testing for significance between means, having one normal distributed sample and one non normal distributed

Question: I have following problem:
Within an independent groups 1-factor design I have two independent groups, with a sample size of 20 each. The data of the treatment group is not normally distributed, whereas the data for the control group is (checked with Shapiro-Wilk Normality Test). Now I want to check if the differences of the means of both groups are significant.
What is the appropriate test for this? I think it should be the Wilcoxon Rank Sum and Signed Rank Test, but I am not sure...
Could please anybody help me?
Comment: Failure to reject normality doesn't mean the data is normal -  moreover in a tiny sample size of 20, you may not even have reasonably approximate normality in spite of a failure to reject.
Comment: See also https://stats.stackexchange.com/questions/243975/skewness-transformation-for-one-but-not-the-other-variable/243984#243984
Answer: If you are 100% sure that the two samples are drawn from populations with different distributions (one Gaussian, one not), are you sure you need any statistical test? You are already sure that the two populations are different. Isn't that enough? Does it really help to test for differences in means or medians? (The answer, of course, depends on your scientific goals, which were not part of the original question.)
Answer: You probably want the The Wilcoxon Rank Sum, also called Mann-Whitney U here.  The Signed Rank Test is for paired samples, so not appropriate in your case.
Your choice is basically between a t-test or Wilcoxon, and come down to a balance between

On the one hand, t-test is more powerful particularly in small samples (which you have), but does assume normality
On the other hand, Wilcoxon is more powerful when far from normality, and is asymptotically close to the t-test in power (but you are far from the asymptote!)

So the first question you need to ask is, how non-normal are we talking?  If we are talking seriously bad*, e.g. clearly bimodal (or multimodal!), or massive skewed, then the t-test can probably be ruled out.
On the other hand, as a general rule of thumb, if it looks bell shaped, then t-test is probably ok.
Arguably, the proper way to proceed, is to do a study of power for your particular set up before you handle the real data too much.  Presuming you have some vague idea of the shape of the non-normal distribution* you should generate pretend samples from your weird distribution and your normal distribution and see how well the t-test and Wilcoxon work on your Monte Carlo data.
Don't forget you need to check both False Positives and False Negatives.  So run once where you make the null hypothesis true (i.e. the samples have the same mean) and another where they differ by the approximate effect size you are looking for (or the effect size that would be "materially interesting" to you).
*I am assuming you must either have some a priori reason to believe that one sample is non-normal, or it is absolutely hideous - otherwise it would be almost impossible to spot much deviation from normal with only 20 data points.
Answer: If data in the treatment group is not normal while the control group is it sounds like the treatment may only be affecting a subset of the sample or having variable levels of effect. Comparing means under such circumstances would be losing out on this information. You should attempt to offer explanations for why this change of distribution occurred rather than only comparing means. The rank tests assume that both groups come from the same shape distribution. If you believe the distributions are different the tests are not useful for your purposes.
Let us take an example of what can happen with the U-test. We will make our control group come from a normal distribution with mean=0. Meanwhile the treatment will have negative effects on half the subjects and positive effects on the other half. So the treatment group will come from two normal distributions. The first with mean=-5, the second with mean=5. All distributions have sd=1 and both groups have sample size=100. Red shows the treatment group while blue shows the control group:

Results of doing a U-test (which is also called the Wilcoxon test):
<code>        Wilcoxon rank sum test with continuity correction

data:  a and b
W = 4999, p-value = 0.999
alternative hypothesis: true location shift is not equal to 0
</code>
We can see it returns "not significant". Would you really want to conclude the treatment had no effect?
R code for generating the above:
<code>##Generate Data
control<-rnorm(100,0,1) # create control data
treatment<-c(rnorm(50,-5,1),rnorm(50,5,1)) # create treatment data

##Plot data
# Get min/max values (for plotting)
min.val<-min(control,treatment)
max.val<-max(control,treatment)

# make plots
hist(treatment, breaks=seq(min.val-.1,max.val+.1,.5), col="Red",
xlab="Value", ylim=c(0,20),
main="Results"
)
hist(control, add=T, breaks=seq(min.val-.1,max.val+.1,.5),col="Blue")

##perform U-test
wilcox.test(treatment,control)
</code>
Answer: I think in such case when we have two samples one normally distributed and another was not it is more accurate to make transformation for data to get normal distribution for two samples and compare the means by t-test. As t-test is more powerful for small samples. Otherwise we can used non parametric test depend on the type of samples independent  or dependent.


C# (Windows Forms) Input Output Keyboard and Mouse States

Question: How to get keyboard and mouse input (what buttons are currently pressed) && also how to send output (make the mouse click at a specific position in another program). If you could also add comments on what different things do and why you use them would be terrific :D
Cheers! //Daniel
Answer: This may not be a very good solution but bad as i am (didnt understand how to use the other ones that were suggested) i chose the siple way out... i used using Microsoft.Xna.Framework.Input; after getting the xna framework reference, then i simply went ahead and did keyboardstate currentkeyboard = keyboard.getstate :) same with mouse
Answer: .NET only has .NET controls (forms, buttons,etc) based mouse/keyboard hooking built in, so to programmatically respond to those events outside your .NET controls you need a global event hook that can intercept mouse and keyboard activity from anywhere in windows.
HowTo use one keyboard/mouse hook dll to perform the functionality you are requesting (the ability to respond programmatically to mouse/keyboard events globally):
Download "Gma.UserActivityMonitor.dll" from: global mouse/keyboard kooks in c#
Place this dll in C:\Windows\System32
In your project, include a reference (from VS, add...reference and browse to the dll)
In your project code, add "using Gma.UserActivityMonitor;"
In your code, declare these event consumers:
HookManager.MouseMove += HookManager_MouseMove;
HookManager.KeyPress += new KeyPressEventHandler(HookManager_KeyPress);

Here are some method stubs that can be raised when the mouse/keyboard events occur:
private void HookManager_MouseMove(object sender, EventArgs e)
{
}
private void HookManager_KeyPress(object sender, EventArgs e)
{
}

Hope this helps, this is how I did it when I needed to consume global mouse and keyboard events in my code.


Compute average velocity of a particle over a given time interval

Question: I am really stuck with my math problem, would appreciate the answer below.

A particle moves on a line away from its initial position so that after $t$ hours it is $s = 4t^2 + t$ miles from its initial position. Find the average velocity of the particle over the interval $[1, 4]$. Include units in your answer.
Comment: Just to clarify, is $[1,4]$ the interval of time $t$ or the interval of position $s$?
Comment: Look up the definition of "average velocity" in your textbook or course notes. One of the answers below uses what _I_ consider to be the definition of average velocity; with any luck it matches yours.
Answer: $\text{ average velocity over } [1,4]=\frac{s(4)-s(1)}{4-1}$


Why do female footballers play a higher number of international matches compared to a male footballer?

Question: I see female footballers who have played over 300 international games and several who have more than 200 caps. A sample of the top scorers in women's football:
Player, Caps

Abby Wambach, 228
Mia Hamm, 275
Christine Sinclair, 211
Kristine Lilly, 352
Birgit Prinz, 214

The corresponding record holder for men's football is Ahmed Hassan with a comparatively paltry 184. Is there a reason for this difference?
I wondered if it was because the men's football calendar is packed with league fixtures leaving very little room for international matches. But, I believe England and several other countries have professional leagues for women footballers too. So, is there some other reason for the discrepancy?
Comment: the most surprising thing to me is that the top players are midfielders. usually it's the goalkeeper and defenders who have the most caps for their country.
Comment: Hmm, that is a little bit wierd. I've seen those stats as well, but I can't figure out why it is so. Generally, women's careers are shorter, due to a higher (average) number of injuries (especially knee injuries are overrepresented amongst women) and the fact that some choose to end their careers early to create families. Perhaps it could have something to do with the rapid development of the sport to do? Women might get the chance to represent their national teams earlier in their careers? Good question!
Comment: Just to add some source for the numbers mentioned in your post, here is [List of footballers with 100 or more caps](http://en.wikipedia.org/wiki/List_of_footballers_with_100_or_more_caps) from Wikipedia (which lists both men and women).
Comment: Does playing for professional leagues limit (either logistically or contractually) the number of international matches in which a man could play?
Comment: @Phab-I too know her name as Prinz only. Sorry about the typo.
Answer: There are more international competitions for female national teams.
For example the Algarve-Cup, the 4-nations-tournament and the Cyprus Cup.
Most male national teams just playing the World Cup, the continental Cup, the Confed-Cup and the qualifications for them.
Often less games in league:
It's possible to play these additional tournaments, because their schedules are less close than the male ones.
For example the german league (one of the best female leagues) only contains 12 teams (18 in the male league) and they play each team two times (22 matches, 34 for males). So the females have 12 games less in league.
Also in Norway: 12 female teams, 16 male teams.
In addition there is no U21 team for females. In german amateur division the eldest class is A (U19/U18). There's no A (U19/U18) for females, they play in the adults team after B (U17/U16).
An additional factor might be that there are much more "new" teams in male competitions, than in the female competitions.
(A reason why player of "lesser" teams have more games could be, that in "lesser" continental associations are more competitions (eaven for males) and players of "big" clubs wont participate at nonrelevant competitions.)
Comment: @Yaitzme But in Scottish Premier League they play each team 3 times and then play in tow groups (6 teams each) for championship or going down. So they play 38 games each team.
Comment: The Cyprus Cup 2008 runner-up was USA(U-20) according to the wiki page. Also, could you add WHY they play these extra tournaments?
Comment: @Yaitzme Why do they play the World Cup? I guess because they want to win these cups (or for the money)!? It's clear that their schedules must have free time for these cups.
Comment: Of course, I wasn't referring to the world cups. I was wondering how their schedules have free time for these cups. After all, some of them do play in professional womens' leagues similar to (albeit at a smaller scale) to mens' leagues
Comment: @Yaitzme The female leagues often have less teams than the male ones. In Germany 12 female teams in first league and 18 teams in the male league. So there are 12 games less in the schedule. ... added this to my answer.
Comment: Yes, I do know that they have smaller leagues (which is why I mentioned 'albeit at a smaller scale'), but the league sizes don't seem significant enough to cause this much of a differenc.
Comment: Scottish Premier League, for instance, has just 12 teams.
Answer: I think because female football is played by a few number of players than men's one. So it is more difficult to find new strong player to play with national teams. So it easy for the coaches to "use" experienced players to find better results
Comment: Agree with the 1st point. But the 2nd point seems a bit weak, in the sense, the coaches would not depend on media to find/scout players.
Comment: Women and men have different physical peaks.  Men seem to peak later (in their 20's) and decline faster, where women are often on national teams as teenagers and play through their 30's.  The media part doesn't seem to have much ground...
Comment: Yes, that indeed is true. Many countries (often Asian) produce once-in-a-generation figurehead football stars who often go on to play over 150 games. (USA and Donovan is a non Asian example)
Comment: Edit: deleted media coverage meaning
Comment: I note that many of the most capped male players are from "lesser" teams.  This appears to support the theory that when there is a smaller talent pool, it is easier to have a longer career.
Comment: But regardless of the talent pool at hand, that does not explain how a player plays over 350 games !


win32ole process still running in ruby

Question: I know this question has been asked when using VB directly, but I am having trouble terminating a process. I'm using the jruby version of win32ole and ruby 1.9. My current code is something like this:
begin
 excel = WIN32OLE::connect('excel.Application')
rescue
 excel = WIN32OLE::new('excel.Application')
end
excel.Visible = 1
workbook = excel.Workbooks.Open("path to some doc")
ws = workbook.Worksheets(1)
ws.Select
cell_content = ws.Cells(4,4).Value
puts("#{cell_content}")
workbook.Close
cell_content = nil
ws = nil
workbook = nil
excel.ole_free
excel = nil
GC.start

I'm trying to simply open excel, get a value and terminate. But when I look up task manager, I still see the EXCEL.exe running. Due to the begin-rescue it should also open an existing exe but every time I run it, it starts a new process. Once the script stops I manually close excel but I have also tried using excel.Close. Do I need to be calling the ruby equivalent of Marshal.releaseComObject? I don't have a lot of VB experience and I'm pretty new to ruby so I'm sorry if this is a dumb question, but thanks in advance!
Edit:
I have also tried using excel.quit and excel.Quit, sorry I forgot to mention that. Neither seem to be working.
Edit 2:
I'm running on rubymine and using windows xp, using gem: jruby-win32ole
Edit 3:
Code properly terminate process on another computer, so possibly a problem with versions? Worked on jruby 1.5.6, process hangs on 184.108.40.206
Answer: Just hit the same issue, and found a neat solution that I thought I'd document here for the next time someone hits this problem (as excel.Quit does not work if you are calling #exit in your JRuby code)...
You can use the following one-liner in your JRuby code to release all objects allocated on the current thread:
Java::OrgRacobCom::ComThread.Release

You should use this line after you have finished with all your WIN32OLE objects, and before you call #exit.
You should only need to do this if you are calling #exit in your JRuby code, since a normal exit (by reaching the end of your code) does seem to release the COM objects.
The solution came to me after reading about the life-cycle of COM objects in Jacob/Racob, as documented here: JacobComLifetime
Answer: Try excel.Quit, which should close Excel.
Comment: thanks for the input, but it still does not terminate the program
Comment: You can still see the program in the taskbar, or you can see the process in task manager?
Comment: The process in task manager. When I run the script multiple times I get a new process and I have to end up manually ending multiple processes from task manager. Sorry for the confusion, meant process not program

win32ole process still running in ruby


Vee validate in dynamic element

Question: Vee Validate dynamic element with custom mesage in common error box.
I need to show the error message seperatly in the top of the page and show highlights on the input filed if the validation error is present. How to check any validation error is occured in the component.
I want to create it as a componets, The save button is on the main page and validate each of the component before save.

Need to show the error mesage here.

     {{items.assemblyconfigurationname}}
     <input type="text" :name="'assemblyconfigurationvalue_' + index"
         v-validate="'required'" :class="[{ error_input: errors.has('assemblyconfigurationvalue_' + index)}]" v-model="items.assemblyconfigurationvalue">

Answer: You can add another loop in the first div:

Vue.use(VeeValidate)
new Vue({
el: "#app",
  data: {
      configurations: [
       { assemblyconfigurationname: "name1", assemblyconfigurationvalue: 'value1' },
        { assemblyconfigurationname: "name2", assemblyconfigurationvalue: 'value2' }
      ]
  }
})
.error {
  color: red;
}

{{ errors.first('assemblyconfigurationvalue_' + index) }}

      {{items.assemblyconfigurationname}}
      <input type="text" :name="'assemblyconfigurationvalue_' + index"
             v-validate="'required'" :class="[{ error_input: errors.has('assemblyconfigurationvalue_' + index)}]" v-model="items.assemblyconfigurationvalue">

Vee validate in dynamic element