Load RDD from name

Question: In spark, you can do setName on a RDD.
Is it possible to load a RDD from the name ?
Like spark.loadRDD(name) ?
Thanks.
Answer: There is no such option, because the names are not unique identifiers. There are just a method to attach additional information that will be showed in the UI or debugs string.
It is perfectly fine to have:
val rdd1 = sc.parallelize(Seq(1, 2, 3)).setName("foo")
val rdd2 = sc.parallelize(Seq(4, 5, 6)).setName("foo")

and Spark wouldn't "know" which RDD to return.
Additionally there Spark doesn't track RDDs in general. Only objects that are cached or persisted in other ways, are "known" to Spark.
Comment: Thanks ! But it is possible with dataframe, right ? You can createTable and query table if I remember correctly.

Load RDD from name


Go with t-test or Mann-Whitney U test?

Question: I'm measuring performance of 2 methods (method_A and method_B) that try to satisfy customers demands. Both methods produce results between 0 (none of the demands were satisfied) and 1 (all demands were satisfied). Also, both methods run for a certain amount of Time and, after that, they return best possible solution.
I've generated 30 datasets and solved each one with method_A and method_B with different Time limits. The results are summarized below:

My goal is to do some hypothesis testing with the results.
I've considered to do a t-test but before that I've decided to do some normality tests.
Results below:
Histogram of method_A and method_B

Q-Q Plot and Shapiro–Wilk test for method_A

Q-Q Plot and Shapiro–Wilk test for method_B

For small Time values data seem to follow normal distribution so I think that t-test can be done. Am I right?
However, when Time values are large the distribution seem to become non normal.
This is especially visible when average results of both methods are close to 1:

Time equal to 80 and 90 for method_A
Time equal to 140 and 150 for method_B

So the question is: For these scenarios should I do Mann-Whitney U Test?
For some reason, doing 2 different tests (t-test and Mann-Whitney U Test) for same data doesn't seem right...
Overall, what is the best way to do hypothesis testing with this kind of data?
Answer: I would just use the Mann-Whitney test on the raw data. From the wiki:

Unlike the t-test it does not require the assumption of normal
  distributions. It is nearly as efficient as the t-test on normal
  distributions.

In other words, even if you overcome the hurdle of determining exactly in which cases the normal assumption is valid, you don't really gain a lot of power (plus you lose the ability to compare results for different times).
Comment: Yeah, I'm also inclined to follow the "safety first" principle and just use `Mann-Whitney test` and be done with. Thanks
Answer: If you're going to treat the data for each time as a different hypothesis test, then there's probably no theoretical reason why you can't use different tests for different data sets.  But practically speaking, it may be easier to use one test.  Also, because the t-test and Mann-Whitney test very different hypotheses, summarizing results of these different tests can be tricky.
Comment: Thanks for your response. So what would you recommend?
Comment: Mann-Whitney would be better for what you're trying to do.

Go with t-test or Mann-Whitney U test?


Can anyone explain me why my data is not coming to my hbs file

Question: I am trying to send data from my main.js file to bookings.hbs file and it's not working. If I send the same data to my index.hbs file it is working. Can anyone tell me where I am getting the error?
App.js
const express = require("express");
const routes = require('./routes/main');
const hbs = require("hbs");
const mongoose = require("mongoose");
const RoomData = require("./models/rooms");
require("dotenv").config();

const app = express();

// Middleware to parse json
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// Middleware fore static files and routes
app.use('/static',express.static("public"));
app.use('',routes);

// template engine
app.set('view engine', 'hbs');
app.set("views", "views");
hbs.registerPartials("views/partials");

// db connection
mongoose.connect("mongodb://localhost/Hotel-Admin").
then(()=>{

    console.log("Database Connected")
}).
catch((e)=>{
    console.log(e);
})

app.listen(process.env.PORT , ()=>{
    console.log(`Server Started at port ${process.env.PORT}`);
    // console.log(process.env.PORT);
})

Routing file - main.js
const express = require('express');
const routes = express.Router();
const roomData = require("../models/rooms");
const bookings = require("../models/bookings");

routes.get("/", async (req,res)=>{
    const roomA = await roomData.find({"type":"A"});
    const roomB = await roomData.find({"type":"B"});
    const roomC = await roomData.find({"type":"C"});
    res.render("index",{
        roomA:roomA,
        roomB:roomB,
        roomC:roomC,
    });
})

// Sending data to bookings.hbs file but no data is showing there.
routes.get("/bookings", async(req,res)=>{
    const bookingsData = await bookings.find();
    console.log(bookingsData); // Here data is printing in the console
    res.render("bookings",bookingsData); // This not working
})

routes.post("/submit", async(req,res)=>{
    try{
        const bookingData = new bookings({
            name : req.body.name,
            email: req.body.email,
            totalGuests: req.body.totalGuests,
            checkIn: req.body.start,
            checkOut: req.body.end
        });

        console.log(bookingData);

        await bookingData.save().then(()=>{
            res.redirect("/");
        })
    }catch(error){
        console.error(error);

    }
})
module.exports = routes;

bookings.hbs
{{!-- head --}}
{{>head}}

{{!--navbar--}}
{{>navbar data}}

{{!-- Filter Section --}}

      <form action="">
        Start Date
        <input type="date" name="startDate" id="startDate" />

        End Date
        <input type="date" name="endDate" id="endDate" />

        Room Type
        <select id="roomType" name="roomType">
          <option value="All">All</option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
        </select>

          <input id="filter-submit" type="submit" value="Submit" />
          <input id="filter-reset" type="reset" value="Reset" />

      </form>

    {{bookingsData}}   {{!-- Trying to print data just to check whether it is coming, but it's not coming here--}}

      {{#each bookingsData}}

        Booking Details

          Email: {{this.email}}
           Guest Name:{{this.name}}
           Duration:  24 hours
           Room: Savia LR-1
           Amount: ₹1680
           Check In: December 28th 2023
           Check Out:Jab 28th 2024

            <button type="submit" id="bookings-submit-btn">Submit</button>
            <button type="submit" id="bookings-edit-btn">Edit</button>

      {{/each}}

I have tried sending same data to index.hbs file and it was working fine. I don't know what is the issue with this file. Can someone help me please?

I have pasted the file structure and the code. Please help me.
Answer: The mongoose Model.find() returns an array so when you send data to your .hbs file just assign the array to an object property like so:
res.render("bookings", {bookingsData: bookingsData});

or shorthand:
res.render("bookings", {bookingsData});


Fast way to check if object is in the side of a segment

Question: Suppose I have a line segment from $p_1$ to $p_2$. I also have the normal vector to the segment, represented as the blue vector in the image. My question is: is there a fast way to check if a point is in the "left side" of the segment? The "left side" is represented by the yellow area, where the points $b$ and $c$ are. The other points $a$, $d$ and $e$, when checked, should be tagged as outsiders.
I already came up with a solution (that works for my case): drawing a very big rectangle to represent this yellow area and check if the points are inside the rectangle, but I'm looking for a faster way, something simple and fast that I'm able to execute every frame of my application.
Comment: You can find the equation of line $P_1P_2$. Let the equation be $f(x)$.Then for example you have to test $a$. Take the $x$ coordinate of $a$ and plug that into equation of line.  If $f(a_x)\lt a_y$, then the point lies on the right side.Similarly, if $f(a_x)\gt a_y)$, the point lies on the left.
Comment: I thought about this but how would I test $e$? It's on the correct side but not inside the yellow region.
Answer: Translate all points so that $p_1$ goes to the origin $(0,0)$, then rotate/rescale so that $p_2$ goes to $(1,0)$. This is easily done using the complex representation,
$$\bar p\to\frac{\bar p-\bar p_1}{\bar p_2-\bar p_1}=\bar a\bar p+\bar b$$
where the coefficients $\bar a,\bar b$ are computed once for all.
Then a point belongs to the yellow area when
$$0\le x\le 1\land y\le0.$$
Expressed in terms of the original $x,y$,
$$\color{green}{0\le a_xx-a_yy+b_x\le1\land a_yx+a_xy+b_y\le0}.$$

The test costs $8$ arithmetic operations and three comparisons per point. (In fact a little less because in some cases you can conclude with partial evaluation.)
Unless preprocessing of the points is allowed, I don't think you can solve this much faster.

On second thoughts, you can spare a little more. Assume that $|a_x|>|b_x|$. Then rewrite the conditions as
$$0\le x-\frac{a_y}{a_x}y+\frac{b_x}{a_x}\le\frac1{a_x}\land\frac{a_y}{a_x}x+y+\frac{b_y}{a_x}\le0$$ and finally, with new constants
$$\color{green}{u\le x-ry\le v\land rx+y\le w}.$$
At most $4$ arithmetic operations and $3$ comparisons per point. If on average a fraction $\alpha$ of the points fall inside of the whole stripe defined by the segment, the test can be organized to require $2(1+\alpha)$ operations and $\dfrac32(1+\alpha)$ comparisons.
Answer: Let's write $\vec b$ for the blue vector. For a point $x\in\Bbb R^2$, we want to check three things: that the angle between $\vec b$ and $(x-p_1)$ is obtuse, that the angle between $(x-p_1)$ and $(p_1-p_2)$ is acute, and that the angle between $(x-p_2)$ and $(p_1-p_2)$ is acute. We can calculate these with the scalar product: the set of points "left" of the segment is
$$\left\{x\in\Bbb R^2\left|\begin{array}{l}
\langle x-p_1,\vec b\rangle\leq 0\\
\langle x-p_1,p_1-p_2\rangle\geq 0\\
\langle x-p_2,p_2-p_2\rangle\geq 0
\end{array}\right.\right\}$$
This should be relatively light on calculations, as the scalar product is a quadratic expression in the coordinates of the points involved.
Answer: This $2D$ formula:
$$res=(y2−y1)⋅(x3−x1)−(x2−x1)⋅(y3−y1)$$
will give a positive value if $(x3,y3)$
is at right of line $P1→P2$, or a negative value for point at left.
Notice that changing the segment direction ($P2→P1$ instead of $P1→P2$) changes the sign of $res$.
EDIT
Let's define that a point $X=\{x3,y3\}$ is outside of the segment $P1,P2$ if it does not lies inside the two lines passing through end points and perpendicular to the segment.
This can be tested by watching the two angles $\angle X\;P1\;P2$ and $\angle X\;P2\;P1$
The angles can be calculated by the Law of Cosines or its cousin Dot Product.
If both angles are $<=\pi /2$ then the point is "inside" the segment.
Comment: Would $e$ be considered correct according to this formula?
Comment: The formula works with a line instead of segment. I don't know how left/right of a segment would be different from a line. For point $e$, just test it; it will surely work.
Comment: This was the reason I asked for a segment instead of a line, I want $e$ to be correctly tagged as an outsider.


How to fix these errors so I can finally use 'webdriver.Chrome()'?

Question: I want to essentially "click" a button on a webpage using python. I am trying to use the selenium package (as seen in this example how_can_i_essentially_click_a_button_on_a_webpage/) but then I get the following message right after running the code:
I really don't understand what's going on.
I would appreciate any help if possible.
from selenium import webdriver
browsre = webdriver.Chrome()

Traceback (most recent call last):
  File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] El sistema no puede encontrar el archivo especificado

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    browsre = webdriver.Chrome()
  File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Comment: Your issue is `chromedriver' executable needs to be in PATH`...
Answer: Where is your chromedriver.exe located? Is it located in the path that is specified in yours tests?
Try this in your code:
 browser = webdriver.Chrome('/path/to/chromedriver')

Comment: Did this work for you? If so, could you please accept this as an answer? (Click the 'check' icon beside the answer)
Comment: Sorry, it doesn't work that way. Thanks anyway
Answer: Looking into

'chromedriver' executable needs to be in PATH

it seems that your script is not able to find the chromedriver.exe under PATH so you need to add the folder, containing the chromedriver.exe to your system PATH

If you're running your test via PyCharm you can do the same in Run/Debug configurations:

and last, but not the least, you can amend the driver initialization line to contain the full path to your chromedriver.exe
driver = webdriver.Chrome("c:\\path\\to\\chromedriver.exe")

References:

Selenium Webdriver using Python: Tutorial with Example
Selenium With Python
Comment: It worked perfectly, thank you.


Can we characterize the nature of the curve $\int x^{-1 + \epsilon} dx$ as it becomes non-polynomial?

Question: The polynomial family of curves $y=x^n$ all have a common quality to their shape, their growth rate (e.g. considering big-O and little-o notation in complexity theory) and we all know that when $n\ne -1$ then $\int x^n \mathrm{d}x$ is another polynomial, and we also know that $\int x^{-1}\mathrm{d}x$ is not another polynomial, but the logarithm, which is qualitatively different when considering shape, growth rate, etc.
What bugs me, put verbally and non-rigorously is this: we have a situation that for all polynomials except one, integrating that polynomial yields another polynomial, but this special case discontinuously changes the nature of the curve.
Considering $\int x^{-1+\epsilon}\mathrm{d}x$ as $\epsilon \to 0$, it seems that for any infinitesimal-but-nonzero $\epsilon$ the curve before and after integration has all of the characteristics of being polynomial, so how do we describe the qualities of the curve changing as we approach the limit?
It seems that, by choosing suitably small $\epsilon$ I can construct a single-term polynomial that approximates the logarithm to an arbitrary degree of accuracy, but that sounds absurd. (Maybe my intuition is just wrong.)
Is there a rigorous characterization of how we transition from polynomials to logarithms in this way, and does it say anything interesting? Or is it just that my gut is wrong and what seems absurd to me is actually trivial?
Comment: Look at the _definite_ integral version to see the cleaner picture.
Answer: Years ago  I was puzzled by what I think is the same issue: The discontinuity of $\int x^n$ as a function of $n$ at $n=-1$. Then I realized
"Advanced" explanation: The problem goes away when you realize that $\int f$ is really not a function, rather it's an equivalence class of functions modulo constants. If you regard $\int$ as a mapping from, say, $C((0,\infty))$ to $C^1((0,\infty))/\Bbb R$ then $\int x^n$ is continuous at $n=-1$.
More elementary version of more or less the same explanation: The problem goes away if you consider the "$+c$", choosing it properly. Define $$I_n(x)=\frac1{n+1}(x^{n+1}-1)\quad(n\ne-1).$$Then $$\lim_{n\to-1}I_n(x)=\log(x)\quad(x>0).$$
Exercise: Figure out how this answer is really the same as metamorphy's commment...


How can I get a directory listing from DOS in Perl?

Question: I need to get directory names from the path passed to the Perl script as run time argument.
Here is the code I'm using:
$command ="cd $ARGV[0]";
system($command);

$command="dir /ad /b";
system($command);
@files=`$command`;

But it still returns the directory names inside the directory from which I'm running this Perl script.
In short, how do I get the directory names from a target directory whose path is passed to this Perl script?
Comment: while its entirely your choice, i still would advice against using system calls like that unnecessarily since Perl has its in built ways to do that. you make your code not portable.
Answer: judging from what you are trying to do in your question post
$dir = $ARGV[0];
chdir($dir);
while(<*>){
 chomp;
 # check for directory;
 if ( -d $_ ) {
    print "$_\n" ;
 }
}

on the command line
c:\test> perl myscript.pl c:\test

There are other methods of doing a listing of directory. See these from documentation

perldoc -f opendir, perldoc -f readdir
perldoc perlopentut
perldoc -f glob
perldoc perlfunc (look at operators for testing files. -x, -d, -f etc)
Answer: Your problem is that running "cd" via "system" does not change the working directory of the perl process. To do so, use the "chdir" function:
chdir($ARGV[0]);

$command="dir /ad /b";
system($command);
@files=`$command`;

Comment: To clarify, `system` in the question's code starts a child process, namely `cd`, which __does__ change __its own__ working directory. Then the child process ends; but environmental changes such as working directory and environment variables have no effect on the parent process, i.e. the Perl script.
Answer: This should also work
$command = "dir /ad /b $ARGV[0]" ;
Answer: use File::DosGlob (core since before perl v5.5) to avoid gotchas like skipping files matching /^\./.
perl -MFile::DosGlob=glob -lwe "chdir 'test_dir'; print for grep {-d} <*>"


How to redirect Port 2083 to 2082

Question: how to redirect Cpanel port 2083 to 2082 ? i want my Cpanel not use SSL
18.104.22.168:2083

to
22.214.171.124:2082

Comment: In WHM Tweak setting -> Require SSL. Uncheck it. That should be enough.
Comment: I know that but i want when i connect to 2083 will redirect to 2082 .
Comment: Try something like this with iptables: iptables -p tcp --dport 2083 -j REDIRECT --to-port 2082
Answer: If your looking to do this through a rerouting, you could use IP Tables if this is Linux. Also, could you provide a bit more detail, like system info.

How to redirect Port 2083 to 2082


Apache 2 can't find python packages under Django project directory

Question: I am running Apache2 and Django in a Ubuntu Docker container. Apache can find and is trying to run the Django project but cannot find the python packages contained in under the project directory. It is returning an Import error. See attached picture.

ImportError at /
Missing required dependencies ['numpy']
Request Method: GET
Request URL:    http://localhost:8005/
Django Version: 2.1.7
Exception Type: ImportError
Exception Value:
Missing required dependencies ['numpy']
Exception Location: /var/www/html/django_demo_app/INDmain/Lib/site-packages/pandas/__init__.py in <module>, line 19
Python Executable:  /usr/bin/python3
Python Version: 3.6.7
Python Path:
['/var/www/html/django_demo_app/INDmain',
 '/var/www/html/django_demo_app/INDmain/Lib/site-packages',
 '/var/www/html/django_demo_app/INDmain/Scripts',
 '/usr/lib/python36.zip',
 '/usr/lib/python3.6',
 '/usr/lib/python3.6/lib-dynload',
 '/usr/local/lib/python3.6/dist-packages',
 '/usr/lib/python3/dist-packages',
 '/var/www/html/django_demo_app/INDmain',
 '/var/www/html/django_demo_app/INDmain',
 '/var/www/html/django_demo_app/INDmain/main']
I had the same issue when Apache/Django tried to find the requests package under /var/www/html/django_demo_app/INDmain/main/Lib/site-packages so I added the directory to the path and Apache/Django found the package. Now it is finding the pandas package but cannot find the dependency numpy package located in the same directory. What could be causing Apache and/or Django to fail to see these packages?
Project layout
INDmain
--> Include
--> INDmain
--> Lib
--> main
--> Scripts
--> tcl
db.sqlite3
manage.py

My configuration/settings files are below. Common settings are not shown for brevity.
Apache .conf file
WSGIPythonPath /var/www/html/django_demo_app/INDmain

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/django_demo_app

    Alias /static "/var/www/html/django_demo_app/INDmain/main/static"

    WSGIDaemonProcess INDmain python-path=/var/www/html/django_demo_app/INDmain:/var/www/html/django_demo_app/INDmain/Lib/site-packages:/var/www/html/django_demo_app/INDmain/Scripts
    WSGIProcessGroup INDmain
    WSGIScriptAlias / /var/www/html/django_demo_app/INDmain/main/wsgi.py

</VirtualHost>

settings.py
import sys

sys.path.append('/var/www/html/django_demo_app/INDmain')

ALLOWED_HOSTS = ['localhost']

# Application definition

INSTALLED_APPS = [
        'django.contrib.admin',
            'django.contrib.auth',
                'django.contrib.contenttypes',
                    'django.contrib.sessions',
                        'django.contrib.messages',
                            'django.contrib.staticfiles',
                                'main.apps.MainConfig',
                                ]

ROOT_URLCONF = 'INDmain.urls'

WSGI_APPLICATION = 'main.wsgi.application'

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [
        os.path.abspath(os.path.join(BASE_DIR, "static")),
        ]

wsgi.py
"""WSGI config for INDmain project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/"""

import os
from django.core.wsgi import get_wsgi_application
import sys

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'INDmain.settings')

application = get_wsgi_application()

sys.path.append('/var/www/html/django_demo_app/INDmain')

sys.path.append('/var/www/html/django_demo_app/INDmain/main')

Comment: In Django's [deployment docs](https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/modwsgi/), it suggests using `python-home` to specify the virtual env, instead of adding it to `python-path`.
Comment: As an aside, I'd be wary of adding `INDmain` and `INDmain/main` to the python path. It means that some modules will be importable from two separate places (e.g. `main.foo` and `foo`), which can lead to strange behaviour.
Comment: Added the python-path for the daemon mode and now the website just hangs... Does't send a response.   `WSGIDaemonProcess INDmain python-home=/var/www/html/django_demo_app/INDmain python-path=/var/www/html/django_demo_ap
p/INDmain
    WSGIProcessGroup INDmain
    WSGIScriptAlias / /var/www/html/django_demo_app/INDmain/main/wsgi.py process-group=INDmain`
Comment: @Alasdair I have added the project layout above.
Comment: What is `Lib`, how did you create it? Perhaps you want `python-home=/var/www/html/django_demo_app/INDmain/Lib`.
Comment: @Alasdair Lib was created for a venv that I used in development that resided in the under the project folder. I have made the change to this. `WSGIDaemonProcess INDmain python-path=/var/www/html/django_demo_app/INDmain:/var/www/html/django_demo_app/INDmain/Lib` Removing the python-home attribute keeps the Apache web server from not sending a response. I am now back to it not finding the requests package (first import) in site-packages.
Comment: Sorry, I don't have any more specific suggestions. As I said in my first comment, I still think you should be using `python-home` to point to your virtualenv. The only value for `python-home` I've seen you try, `python-home=/var/www/html/django_demo_app/INDmain`, is incorrect, because that is not the virtualenv.
Answer: So to answer my own question...
I did not want to run this under a virtual environment since the web app is the only thing being run in this Docker container. Therefore, I installed all of the needed python library packages within the base image. My Dockerfile, requirements.txt and Docker compose files are as follows.
Dockerfile
FROM ubuntu

RUN apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get autoremove -y && apt-get autoclean -y
RUN apt-get install -y apt-utils vim curl apache2 apache2-utils
RUN apt-get -y install python3 libapache2-mod-wsgi-py3
RUN ln /usr/bin/python3 /usr/bin/python
RUN apt-get -y install python3-pip
RUN ln /usr/bin/pip3 /usr/bin/pip
ADD ./requirements.txt .
RUN pip install -r requirements.txt

ADD ./web_site.conf /etc/apache2/sites-enabled/000-default.conf
ADD ./INDmain /var/www/html/INDapp/INDmain
EXPOSE 80 3500
CMD ["apache2ctl", "-D", "FOREGROUND"]

requirements.txt
django
ptvsd
requests
pandas
openpyxl
xlrd

docker-compose.yml
version: "2"

services:
  ind-web-app-ubuntu:
    image: ind-web-app-ubuntu
    container_name: ind-web-app-ubuntu
    ports:
      - '8005:80'
      - '3500:3500'
      - '8006:81'
    restart: always

My ending project layout.
INDmain
--> INDmain
--> main
db.sqlite3
manage.py

My configuration/settings files. Common settings are not shown for brevity.
Apache .conf file
WSGIPythonPath /var/www/html/INDapp/INDmain

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/INDapp

    Alias /static "/var/www/html/INDapp/INDmain/main/static"

    WSGIScriptAlias / /var/www/html/INDapp/INDmain/INDmain/wsgi.py

</VirtualHost>

settings.py
import sys

sys.path.append('/var/www/html/INDapp/INDmain/main')

ALLOWED_HOSTS = ['localhost']

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
        'django.contrib.auth',
            'django.contrib.contenttypes',
                'django.contrib.sessions',
                    'django.contrib.messages',
                        'django.contrib.staticfiles',
                            'main.apps.MainConfig',
                            ]

ROOT_URLCONF = 'INDmain.urls'

WSGI_APPLICATION = 'INDmain.wsgi.application'

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.abspath(os.path.join(BASE_DIR, "static")),
    ]

wsgi.py
"""WSGI config for INDmain project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/"""

import os
from django.core.wsgi import get_wsgi_application
import sys

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'INDmain.settings')

application = get_wsgi_application()

Installing the python packages within the existing python environment solved the problem of not finding the python modules in underlying directories for Django and Apache. It took a significant amount of effort to get all of the pieces talking to each other, so hopefully this will help others with similar needs.


Is it bad practice to add markup to title or label fields?

Question: The title might not make sense because I'm not sure what the correct wording is. But here is the example that explains what I mean.
I am creating a block view to go at the bottom of a node page that links in extra info relevant to the node (a users blog post on their profile page).
I titled the block Blog Posts but it was small and smashed up against the bottom of the content above it. So I tried calling it
Blog Posts
 and it displayed as an
. So I got more creative and now the title is

Blog Posts
. It looks nice and works the way you would expect (with the html being rendered properly).
This method kind of seems like a bad hack, but inexperienced as I am with Drupal, I'm not sure why.
Is this bad practice, and why?
Comment: At least from an SEO point of view it's bad practice to use h-tags for anything other than continuous text. Use a div instead.
Answer: That'll work, but best practice is to theme it. The following answer describes how to theme a custom block: https://drupal.stackexchange.com/a/39270/23063
Answer: it is seriously bad practice... since you wrote markup in the title, it is stored in database. Storing unnecessary markups in database is BAD PRACTICE. That is why we have CSS for designing. Drupal also has jQuery which lets you change elements easily.


Pegar o id do audio tocado

Question: Preciso pegar o ID do audio que o usuário da play, imaginei que algo assim funcionaria:

document.addEventListener('play', function(e){
   $(this).attr('id');
}, true);

<audio controls id="musica1">
   <source src="https://65381g.ha.azioncdn.net/9/9/5/3/onlinepontocom-01-mais-uma-vez.mp3" type="audio/mpeg">
</audio>
<audio controls id="musica2">
   <source src="https://65381g.ha.azioncdn.net/9/9/5/3/onlinepontocom-01-mais-uma-vez.mp3" type="audio/mpeg">
</audio>

Ele até detecta o clique no play, mas não retorna o ID, existe algum forma?
Answer: É que aí vc tem que entender qual a diferença do this, do event.target e do event.currentTarget no escopo de um evento?, se der um console.log($(this)) verá que não é o retorno que estava esperando. Como pode ver no exemplo abaixo, se utilizar o parâmetro e mais a propriedade target, conseguirá obter o elemento que foi clicado em tela, pegando assim o valor do seu id:

document.addEventListener('play', function(e) {
  console.log(e.target.getAttribute('id'))
}, true);

<audio controls id="musica1">
   <source src="https://65381g.ha.azioncdn.net/9/9/5/3/onlinepontocom-01-mais-uma-vez.mp3" type="audio/mpeg">
</audio>
<audio controls id="musica2">
   <source src="https://65381g.ha.azioncdn.net/9/9/5/3/onlinepontocom-01-mais-uma-vez.mp3" type="audio/mpeg">
</audio>

OBS: No caso utilizando jQuery: $(e.target).prop('id');
Answer: Faz dessa forma. Assim ele verifica o play em qualquer elemento de audio e te mostra a id atribuída ao elemento.
    $('audio').on('play', function(){
        var id_aud = $(this).attr("id");
    });

<audio controls id="musica1">
   <source src="https://65381g.ha.azioncdn.net/9/9/5/3/onlinepontocom-01-mais-uma-vez.mp3" type="audio/mpeg">
</audio>
<audio controls id="musica2">
   <source src="https://65381g.ha.azioncdn.net/9/9/5/3/onlinepontocom-01-mais-uma-vez.mp3" type="audio/mpeg">
</audio>

Pegar o id do audio tocado


If $n$ is odd then $\mathbb{R}P^n$ is orientable

Question: Show that if $n$ is odd then $\mathbb{R}P^n$ is orientable.
Comments:
I have the following: The antipodal map $\alpha: S^n \longrightarrow S^n$, $\alpha (x) = -x$ is orientation-preserving if and only if n is odd.
I'm trying to use the map $\pi: S^n \longrightarrow  \mathbb{R}P^n$
and the above fact to find orientation form of $\mathbb{R}P^n$. But I can not fit these facts. What is the orientation form?
Comment: @I4teLearner : no, that's not quite right : any pulled back form is invariant under the action of the antipodal map, so any form that isn't invariant isn't pulled back. The point of the suggestion is to show that this is in fact an equivalence
Comment: @I4teLearner : this is essentially Lee Mosher's answer. Note that if $\pi^*\omega$ is nowhere vanishing and $\pi$ is surjective, then $\omega$ is also nowhere vanishing. So by the fact that the image contains a nonvanishing form, there must also be a nonvanishing top form on $\mathbb RP^n$
Comment: @I4teLearner: oh I didn't realize that was your question - I thought you knew how to do that from your earlier comment. For that you can either look at Lee Mosher's comment below the answer here; or you can look at my answer there : https://math.stackexchange.com/questions/2840494/differential-forms-on-the-circle-mathbbr-mathbbz/2840571#2840571  - it's a slightly different case but exactly the same proof
Comment: Use the induced map $\pi^* :\Omega^n(\mathbb{R}P^n)\to \Omega^n(S^n)$ : what's its image ?
Comment: If $n$ odd, what will be a orientation form of $\mathbb{R}P^n$ ?
Comment: @Maxime Ramzi could you please elaborate a bit your suggestion? I believe we can say that such map is surjective? thanks
Comment: @Maxime Ramzi thanks for your suggestion but I still fail to understand. would you be so kind as to detail the steps of your method. so far I understand that the image of that map is all the antipodal map invariant top forms of S, among which  there is the standard volume form, which is everywhere not vanishing. we are then saying that it is necessarily the pullback of a non vanishing top form in RP,  which then has to exist? your suggestions are very insightful, it could be grear if you could post a complete answer. thanks a lot!!!
Comment: @Maxime Ramzi thanks this starts to make sense for me. But how can we be sure that we can write such top form on $S^n$ as $\pi^{*}\omega$ i.e. that each smooth top form on $S^n$  which is invariant w r.t the antipodal map is the pullback of some smooth top form on $\mathbb{R}P^n$ ? thanks for your patience and sorry for the nuisance
Comment: @Maxime Ramzi thanks a lot! what clicked for me, among the rest, is the fact that the projection is a local diffeomorphism
Comment: @I4teLearner : yes, that's a really important point - that's why the answer is not quite the same (though related) for quotients by non discrete Lie group actions
Answer: You seem most interested in the case where $n$ is odd, and proving in that case that $\mathbb RP^n$ is orientable, so I'll provide an answer for that case.
Fix an orientation on $S^n$, which means that for each $x \in S^n$ we have an orientation $\mathcal O_x$ of the tangent space $T_x S^n$, and these orientations vary continuously as $x \in S^n$ varies.
To define an orientation on $\mathbb RP^n$, consider an arbitrary point of $\mathbb RP^n$, which I'll represent as unordered pair of antipodal points of $S^n$. Using equivalence class notation, for each $x \in S^n$ I'll write this as $[x]=[-x]=\{x,-x\}$. So, we have to define an orientation $\mathcal O_{[x]}$ of the tangent space $T_{[x]} (\mathbb RP^n)$: define
$$\mathcal O_{[x]} = D_x\pi(\mathcal O_x)
$$
The key issue is whether this is well-defined independent of the choice of the two representatives $x$ and $-x$ of $[x]$, and that is true because
\begin{align*}
D_{-x}\pi \, (\mathcal O_{-x})
&= D_{-x}(\pi \circ \alpha) \, (\mathcal O_{-x}) \\
&= D_{\alpha(-x)} \pi \circ D_{-x} \alpha \, (\mathcal O_{-x}) \\
&= D_x \pi \circ D_{-x} \alpha (\mathcal O_{-x}) \\
&= D_x \pi \, (\mathcal O_{x})
\end{align*}
where the first equation holds because $\pi = \pi \circ \alpha$, the second equation is the chain rule, the third equation uses that $\alpha(-x)=x$, and the fourth equation uses that $\alpha$ preserves orientation and so $D_{-x}\alpha(\mathcal O_{-x}) = \pi(\mathcal O_x).$
Comment: The equation $\mathcal O_{[x]} = D_x\pi(\mathcal O_x)$ literally says that the orientation on $\mathbb RP^n$ at the point $[x]$ is inherited, via the derivative map $D_x$, from the given orientation $\mathcal O$ on $S^n$ at the point $x$. Continuity of the orientation $\mathcal O_{[x]}$ on $\mathbb RP^n$ then follows from continuity of the orientation $\mathbb O_x$ on $S^n$ (after well-definedness has been checked), by applying that formula in any compatible coordinate charts for $S^n$ and $\mathbb RP^n$.
Comment: @Lee Mosher. How are you sure that this orientation on the tangent space at $\mathbb{R}P^n$ varies continuously? Is this just inherited?
Comment: Could I solve this problem using an orientation form?


Is there a connection between the diagonalization of a matrix $A$ and that of the product $DA$ with a diagonal matrix $D$?

Question: Given a diagonalizable matrix $A = P_0\Lambda_0 P_0^{-1}$ and a diagonal matrix $D$ with $\det D=1$, is there any connection between $P_0$ and the matrix $P$ of the diagonalization of $DA = P\Lambda P^{-1}$?
Comment: related: [Eigenvalues of product of a matrix and a diagonal matrix](http://math.stackexchange.com/q/20302/163)
Comment: So $D$ can have complex entries, or are you only considering $(1,-1)$ diagonals?
Comment: @J.M.: yes, complex entries as well. The 2x2 case $D=$diag$(e^{-ix}a,e^{+ix}/a)$ would already be sufficient, though a more general solution might be interesting as well...
Comment: Just curious, does this work all the time? It doesn't look like it would after I tried a few values. If $A=\begin{bmatrix}
1 & 2\\
3 & 2
\end{bmatrix}$ and $D=\begin{bmatrix}
5 & 0\\
0 & \frac{1}{5}
\end{bmatrix}$, the eigenvalues of $A$ are $4$ and $-1$ but the eigenvalues for $DA$ are $6.06$ and $-0.66$. So how could the  $\Lambda$ be the same for $A$ and $DA$?
Comment: @xEnOn: It usually isn't; the question denotes them by $\Lambda_0$ and $\Lambda$, respectively.
Answer: I know that if A is diagonalizable, and D a diagonal matrix D it is not even true that DA need to be diagonalizable. An example is:
$$
D= \begin{bmatrix} 2 & 0 \\ 0 & 1/2 \end{bmatrix}, \,\,
DA = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}
$$
and of course $A=D^{-1}DA$.
I leave it as an exercise for the reader to verify that indeed $A$ is diagonalizable and $DA$ not.
Although not a complete answer to the question (since this example doesn't say anything about the case where both A and DA are diagonalizable) it at least shows that the question should be posed more carefully.
Also the fact that you want $\det D = 1$ will ensure that the product of the elements in the diagonal of $\Lambda_0$ will be the same as those in $\Lambda$, but I guess you don't need that info since you care about $P$ and $P_0$
Comment: assumption failed... ok, thanks
Answer: The columns of $P_0$ are the eigenvectors of $A$. The columns of $P$ are the eigenvectors of $DA$. So write down some $2\times2$ matrix $A$ and see whether there's any relation between its eigenvectors and those of $DA$.
Comment: You might also try finding an example where $DA$ is not diagonalizable but $A$ is.


Como abrir conexão com 2 tabelas no php

Question: Estou com dificuldade de conseguir conectar duas vezes no meu banco de dados, cada vez irá conectar a uma tabela
o código e o seguinte:
Categorias

Categorias

    <?php
      require_once "conecta_db.php"; //CHAMA O ARQUIVO DE CONEXÃO COM BD

      $tb = "categorias";
      $sql = "SELECT * FROM ".$tb;
      $result=mysqli_query($con,$sql);

      while($linha = mysqli_fetch_assoc($result))
      {
    ?>

            <a class="portfolio-link"  href="<?php echo "categorias.php?idcat=".$linha["idcat"];?>">

<?php echo utf8_encode ($linha["nome"]); ?>

                            <?php echo ""; ?>

<?php echo utf8_encode ($linha["descricao"]);?>

   <?php } // fecha while
     // Free result set
     mysqli_free_result($result);
     mysqli_close($con);
   ?>

Serviços

     <?php
        require_once "conecta_db.php"; //CHAMA O ARQUIVO DE CONEXÃO COM BD

       $tbb = "servicos";
       $sqll = "SELECT * FROM ".$tb;
       $resultt=mysqli_query($con,$sql);

       while($linha = mysqli_fetch_assoc($resultt))
       {
     ?>

            <a class="portfolio-link"  href="<?php echo "categorias.php?idcat=".$linha["idsv"];?>">

<?php echo utf8_encode ($linha["nome"]); ?>

                            <?php echo ""; ?>

<?php echo utf8_encode ($linha["descricao"]);?>

      <?php } // fecha while
       // Free result set
       mysqli_free_result($result);
       mysqli_close($con);
      ?>

Comment: Qual o erro está sendo mostrado?
Comment: Warning
: mysqli_query(): Couldn't fetch mysqli in
C:\xampp\htdocs\tcc\startbootstrap-agency-gh-pages\index.php
on line
167

Warning
: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in
C:\xampp\htdocs\tcc\startbootstrap-agency-gh-pages\index.php
on line
169

Warning
: mysqli_free_result(): Couldn't fetch mysqli_result in
C:\xampp\htdocs\tcc\startbootstrap-agency-gh-pages\index.php
on line
193

Warning
: mysqli_close(): Couldn't fetch mysqli in
C:\xampp\htdocs\tcc\startbootstrap-agency-gh-pages\index.php
on line
194
Answer: neste excerto

$tbb = "servicos";
$sqll = "SELECT * FROM ".$tb;
$resultt=mysqli_query($con,$sql);

while($linha = mysqli_fetch_assoc($resultt))
{

voce declarou as variaveis como $tbb e $sqll, mas utilizou-as de outra forma.
tente assim:

$tbb = "servicos";
$sqll = "SELECT * FROM ".$tbb;
$resultt=mysqli_query($con,$sqll);

while($linha = mysqli_fetch_assoc($resultt))
{
Comment: esta dando o seguinte erro: Warning
: mysqli_query(): Couldn't fetch mysqli in
C:\xampp\htdocs\tcc\startbootstrap-agency-gh-pages\index.php
on line
167

Warning
: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in
C:\xampp\htdocs\tcc\startbootstrap-agency-gh-pages\index.php
on line
169
Warning
: mysqli_free_result(): Couldn't fetch mysqli_result in
C:\xampp\htdocs\tcc\startbootstrap-agency-gh-pages\index.php
on line
193

Warning
: mysqli_close(): Couldn't fetch mysqli in
C:\xampp\htdocs\tcc\startbootstrap-agency-gh-pages\index.php
on line
194

Como abrir conexão com 2 tabelas no php


Automated Rules Discount

Question: I have installed 'Ubercart Discount Coupons' module and managed to add a rule to configure the automated discount. But now all the normal code type discounts have stopped working....
Only when I remove the automated discount rule the normal code discounts will works.
I am struck on the production site.
Screenshots:
Comment: If you don't have any custom on that rule, you can revert it to default value. Did you try that?
Comment: Sorry.. I did not get you.. what is custom on rules? please explain it to me.
Comment: In other words, do you want to have a general automated discount that applies to all transactions AND specific discounts that are applied with coupon codes? If so, have you looked at the order your rules are applied?
Comment: Yes, I am trying to configure one automated discount and normal code based discounts.
Comment: Currently the problem is when I add a rule for automated discount, the normal code based discounts stops working.
Comment: And the discount will be applied to products of one particular taxonomy term automatically, and other products will have product specific code based discount
Comment: Can you either supply a screengrab of your rules or show an example of the product price and discounts structure you want to achieve?
Comment: Hi Longboardnode, I have updated the screenshots above. Thanks
Answer: I guess I figured out the problem.
This Issue was in the 'Coupon module settings'.
Solution:
1. Go to: admin/store/settings/coupon
2. Enable 'Allow multiple coupons to apply to a single order.' check-box.
3. Save.
This solved my problem.
Thanks,
Anand
Answer: Previous answer of AnAnD worked for me as well.
As of 2018 (Drupal 7.59, Ubercart 3.11) I found the setting under Administration > Store > Configuration > Coupon module settings.

Automated Rules Discount


What is the expected value of the expected of x conditional of y? $E(E(X|Y))$ and also if possible $E(X^2|Y)$?

Question: What is the expected value of the expected of x conditional of y? $E(E(X|Y))$ and $E(E(X^2|Y))$?
I was doing this question. And got this result. But got stumped at the next question. Which asks me to find the expected value of the conditional probability.

I guessed and computed it like this. Getting $E(E(X|Y)) = 2.020$

I guessed and got $E(E(X^2|Y))= 4.840$
Comment: Maybe you could clean up a bit and remove these non-self explanatory Excel screen shots and replace them with two lines of computations each.
Comment: The characterization in this question is not quite right: "$E[E[X^2|Y]]$" asks not for the expectation of a "conditional probability"; rather, it asks for the expectation of a *random variable* (namely, the variable $E[X^2|Y]$). There's nothing new in that: the calculation is carried out exactly as it would be with any random variable.
Comment: But sheb they explain my working out. I don't think it's better to include some form of evidence of effort and reasoning.
Comment: It's far easier to read a calculation in $\LaTeX$ than it is to read an Excel sheet.
Answer: Your parentheses do not match, almost nowhere, this makes your question ambiguous. If you mean $E_Y(E_X(X|Y))$, then your answer is the law of iterated expectations.
Basically $E_Y(E_X(g(X)|Y))=E(g(X))$
Comment: So it's just  E[E(X^2|Y)] = E(X^2) = 1*0.34 + 4*0.51+9*0.15? which is also = 4.841

And E[E(X|Y)] = E(X) = 1*0.34 + 2*0.51+3*0.15 which is also 2.020
Comment: Sheb? responds plox how's this?


Lets Encrypt renew protocol steps

Question: I have a custom client that i use to get Lets Encrypt certificates but i can't work out the proper protocol to renew the certificates. The versions of the spec that i have found seem very vague on the exact renewal process.
Is the renewal process any different from a new certificate request? Are there steps i can skip or is it totally different?  I am currently using the DNS based verification if that makes a difference. At the minute i am just requesting a new certificate following the full process but i am not sure if that the correct way or over kill or a very bad thing to do.
Answer: This will depend on your client, however, the steps should be similar to the initial request. The difference is that you don't have to regenerate a private key or a CSR if you saved them and your private key did not get compromised.
This makes it very easy to automate the renewal process.
Comment: I can save what ever details i need and it really should not depend on the client when you are talking protocol level.  I am trying to implement the offical protocol if that helps. i assume with your steps it would follow the normal request signing steps  Do you still need to go though the domain verification steps and use the same url and rest api or is it a different api endpoint and api call?
Answer: I believe they will be adding automatic renewal scripts in the near future, there is a basic bash script posted on the front page of the website at the moment.

Lets Encrypt renew protocol steps


mini batch matrix form of neural network

Question: I am studying neural network. I read a lot about mini-batch gradient descent. So now, I was implementing it in TensorFlow.
But I have some questions regarding the matrix formulation of the problem/vectorization.
Notation
First some notation
$w_{ij}^l$ is the weight on the connection connecting node $j$ in layer $l$ to node $i$ in layer $l+1$.
If we have $4$ nodes and $3$ features we could have:
$W^{(1)} = \begin{bmatrix}
    w_{11}^{(1)}       & w_{12}^{(1)}    & w_{13}^{(1)}  \\
    w_{21}^{(1)}       & w_{22}^{(1)}    & w_{23}^{(1)}  \\
    w_{31}^{(1)}       & w_{32}^{(1)}    & w_{33}^{(1)}  \\
    w_{41}^{(1)}       & w_{42}^{(1)}    & w_{43}^{(1)}
\end{bmatrix}$
At the same time, suppose we have a batch size of $5$, then the input matrix might be
$X = \begin{bmatrix}
    x_{11}       & x_{12}    & x_{13}  \\
    x_{21}       & x_{22}    & x_{23}  \\
    x_{31}       & x_{32}    & x_{33}  \\
    x_{41}       & x_{42}    & x_{43}   \\
    x_{51}       & x_{52}    & x_{53}
\end{bmatrix}$
where $x_{ij}$ is the input in sample $i$ of feature $j$.
What I don't understand
Everywhere I go I see $f(W^TX +\mathbb{b})$ as the formula. However this clearly doesn't make sense here, as we would have incompatible shapes!! $W$ has shapes $(\text{number nodes}, \text{number features})$, while $X$ has shape  $($ batch size, number features $)$.
Ideally we would like, for each sample, to have something like this (I only write the first two columns). But how do we get there? Is this the correct way?
$A^{(1)} = \begin{bmatrix}
    w_{11}^{(1)}x_{11}       + w_{12}^{(1)}x_{12}   + w_{13}^{(1)}x_{13} & w_{11}^{(1)}x_{21}       + w_{12}^{(1)}x_{22}   + w_{13}^{(1)}x_{23}\\
    w_{21}^{(1)} x_{11}      + w_{22}^{(1)}x_{12}    + w_{23}^{(1)}x_{13}  & w_{11}^{(1)}x_{21}       + w_{12}^{(1)}x_{22}   + w_{13}^{(1)}x_{23}\\
    w_{31}^{(1)}x_{11}       + w_{32}^{(1)}x_{12}    + w_{33}^{(1)}x_{13}  & w_{31}^{(1)}x_{31}       + w_{32}^{(1)}x_{32}    + w_{33}^{(1)}x_{33}\\
    w_{41}^{(1)}x_{11}       + w_{42}^{(1)}x_{12}    + w_{43}^{(1)}x_{13} &  w_{41}^{(1)}x_{41}       + w_{42}^{(1)}x_{42}    + w_{43}^{(1)}x_{43}
\end{bmatrix}$
Answer: I don't see the problem.  Here's a neural net with three layers:
$$
\begin{array}{c}
y = \beta_0 + \mathbf{V}_1\beta \\
\mathbf{V}_1 = a(\gamma_1 + \mathbf{V}_2\Gamma_1)\\
\mathbf{V}_2 = a(\gamma_2 + \mathbf{V}_3\Gamma_2)\\
\mathbf{V}_3 = a(\gamma_3 + \mathbf{X}\Gamma_3)
\end{array}
$$
Where $\mathbf{X}$ is your data.
Say that $\mathbf{X}$ is $N \times p$.  That means that $\Gamma_3$ is $p \times p_3$, $\mathbf{V}_3$ is therefore $N \times p_3$ and $\Gamma_2$ is $p_3 \times p_2$, $\mathbf{V}_2$ is therefore $N \times p_2$ and $\Gamma_1$ is $p_2 \times p_1$, and $\beta$ is $p_1 \times 1$ (assuming a univariate response).
For a minibatch, just swap out $N$ with $B<N$.  It doesn't change the dimensions of the weights, just that of the derived variables/hidden layers $\mathbf{V}$
Your problem is that you were thinking of $X$ as row-oriented vs column oriented, I think.  That's why your matrices weren't conformable.  But minibatch has nothing to do with that -- minibatch chops off observations, not features.  Dropout, on the other hand, chops off features.  In so doing it propagates the deleted columns upward/downward on the forward backward passes.
Comment: Inevitably!  I am of the opinion that the tensor-based and index based way that neural nets are taught makes them seem needlessly complex, especially to people with a wit of math background.
Comment: By knowing $X$ is $N \times p$ and $\Gamma_3$ is $p\times p_3$, we know that $V_3$ is $N \times p_3$
Comment: IDK but I'm fairly confident that you could use commutative rules for matrices to make this work in row-wise representations of data.
Comment: Yeah.  Editing..
Comment: Any tensor can be represented in two dimensions. If you are writing code in assembly or for a GPU, the tensor representation might be optimal. But if you're relying on either blas or sparse matrix libraries, I think the 2d representation is better. But ultimately the two are mathematically equivalent.
Comment: If you're an R user, you might be interested in my package here:  https://github.com/cranedroesch/panelNNET.  It is in no way ready for release, but it implements the ideas that I'm talking about.
Comment: Sorry, just to clarify, here $\gamma_i$ are the biases, right?
Comment: Right.  Although that terminology is STUPID.  They should be called "intercepts".
Comment: right, like in linear regression!
Comment: Also $p_3$ is the number of nodes in hidden layer 1 ?
Comment: Hidden layer 1 (or, the first from the bottom) *is* $\mathbf{V}_3$ in my terminology.  It is nothing but a set of derived variables.  That is what neural nets are.  Iterative sets of derived variables, eventually related to the outcome by OLS or logistic regression.
Comment: Makes sense, it is basically a linear regression where instead of using the input $x$ you use a transformation of it, and you do this transformation through various layers.

But what I don't understand is how the computer multiplies these matrices. $X$ is $N\times p$ and that's okay. The weight matrix of the first hidden layer, $\Gamma_3$ is $p \times p_3$ and that is okay. But why do we know that $V_2$ is $N \times p_3$?
Comment: Yeah, basically.
Comment: My doubt is that when I did linear algebra, I was told that by multiplying a vector/matrix with another matrix ON THE LEFT, I could do a transformation. Intuitively, I would transformate the input $X$ to the hidden nodes, not the opposite!
Comment: Also, shouldn't $V_2$ be $N \times p_2$?
Comment: And shouldn't $V_1$ be $N \times p_1$?
Comment: Hey if I've answered your question, give me that check mark!
Comment: I think it makes sense, but then it means most implementations online are wrong.. which is quite weird
Comment: One last thing. Does this mean that you can "solve" a whole batch in one go using matrix notation?
Comment: You could if the activation function wasn't nonlinear.  That nonlinearity means that there isn't a closed form solution.  And what do you mean that online implementations are wrong?  They are probably internally consistent, but use a vocabulary that works better for computer scientists.
Comment: well they use tensorflow and they seem to end up with different shapes.. Maybe I'm just still confused


How to get an image on top of another website

Question: I'm trying to prototype a sort of torch that would 'light up' webpages. I've done this by placing a black image with a transparent hole in the middle, over a background.
I'm struggling to think of a way to post the code in a way that's tangible but here is the files (whole lot under 2mb, open in chrome): https://www.dropbox.com/sh/1cyl710mmhtbo51/843TzPcuQ_
I'm now trying to replace the website backgrounds, which in my example are images, with real sites. I've tried iframes, but found that to be unsuccessful as you can't embed google etc.
Can anyone think of a way in which I could have my dark image hovering over a live website?
This only need work for the demo on my own laptop.
Comment: You could maybe use jquery to load a remote page into a div $('#div').load('http://example.com')?
Comment: I'm going to test this now Jake, thanks for the suggestion!
Answer: If it only needs to work on your machine, just copy the source of the page into an HTML file and save it. Then you can edit it any way you want. You may have to adjust URLs so that images and CSS work properly.
Comment: Not sure this is going to work with the variety of websites I'm hoping to demo over.
Answer: I'm not sure this is what you're looking for, anyway;
jsfiddle
<code>document.body.appendChild(lightContainer);
lightContainer.appendChild(light);
lightContainer.onmousemove = function(e) {
  var posX = e.clientX;
  var posY = e.clientY;
  light.style.left = -5000 + posX +'px';
  light.style.top = -5000 + posY + 'px';
};
</code>
You don't see anything underneath it because I couldn't find a transparent image.
In the content div you can place anything you want.


how to create realtime notification in django without using django channels

Question: For every action such as-

log in
sign up
password reset

Notifications should be seen to the user with a notification bell icon (just like Facebook)
where real-time notifications are shown according to each action performed.
Also, an email should be sent to that user.
Note - (YOU CAN USE ANY DJANGO LIBRARY EXCEPT DJANGO CHANNELS)
this is the question that I want to solve. please help me.
Answer: You can use the Google Firebase Cloud Messaging service. There a lot of packages that work with this service. I recommend you to use fcm-django package for simplicity.


In the Eclipse WindowBuilder editor, the Design tab isn't showing anything

Question: When I create a jframe within a java project it shows me all the code in the Source part but when I go to Design it shows nothing? Would like some help on how to get the whole interface where you customise the GUI.
Comment: This is a good question (see answer below) and I hope it will not be closed like the [questions that asked it before](https://twitter.com/howlger/status/1309413178552582145).
Answer: That's a known issue of the Eclipse 2020-09 release which is already fixed (see Eclipse bug 567071).
Update to WindowBuilder 1.9.4 either via the Eclipse Marketplace or via Help > Install New Software... and working with the update site http://download.eclipse.org/windowbuilder/latest/.
Comment: You legend, appreciate it a lot


Android dual sim support

Question: Does android natively support the dual sim feature?
Or is android extended by manufacturers to do so?
In particular, I'd like to make a sim switching app just like the ones in Samsung phones.
Also can anyone tell me in which system apk are the status bar and notifications located?
I'm trying to reverse engineer the Samsung sim switching feature.
Thanks.
Comment: See this related question: http://stackoverflow.com/questions/11305407/android-dual-sim-card-api
Answer: No, dual SIM is not supported in Android out of the box. It is a custom modification by manufacturers, and there is no public API to control it.
The status bar and notifications are location in SystemUI.apk, but I doubt you'll be able to get much out of them. Any APIs used in their are unlikely to be available to third parties.
Comment: Actually, status bar and notification pull-down are in SystemUI.apk which can be decompiled to smali code. Of course, it's a system package so it may or may not be available depending on whether you have root.

Android dual sim support


Dimension of tangent spaces

Question: Consider the set
$$ S^{2} = \{ (x,y,z) \in \mathbb{R} \mid x^{2} + y^{2} + z^{2}=1 \}$$
as a manifold with two charts given by the stereographic projections from the points N $= (0,0,1)$ and S $= (0,0,-1)$.
The chart obtained from the projection from N is a homeomorphism
$$ \phi : S^{2} \setminus \{N\} \longrightarrow \mathbb{R^{2}} $$
and, if $p\in S^{2} \setminus \{N\}$, the tangent spaces $T_{p}S^{2}$ and $T_{\phi(p)}\mathbb{R^{2}}$ are both vector spaces of dimension 2.
Consider now the differential of $\phi $ in $p$, the linear application
$$ d \phi_{p}:T_{p}S^{2}\longrightarrow T_{\phi(p)}\mathbb{R^{2}}.$$
In my opinion, this application should be represented by a $2 \times 2$ matrix. Nevertheless, I am working out a solved exercise in which that application is represented by a $3 \times 2$ matrix, whose coefficients are functions of $x,y$ and $z$.
Why is this? Is it because $\phi$ is viewed as a function from a subset of $\mathbb{R^{3}}$ to $\mathbb{R^{2}}$? Why then this apparent inconsistency?
Comment: Well, the domain of this map isn't exactly an *open* subset of $\mathbb{R}^3$, but yeah, the tangent space is probably being viewed as a subspace of $\mathbb{R}^3$, spanned by the vectors $\frac{\partial\phi}{\partial x}$ and $\frac{\partial\phi}{\partial y}$.
Comment: Actually, make that $\frac{\partial\phi^{-1}}{\partial x}$ and $\frac{\partial\phi^{-1}}{\partial y}$.
Answer: The two-dimensional tangent space $T_pS^2$ is naturally a subspace of the three-dimensional space $T_p\mathbb R^3$.  Since stereographic projection extends to (a neighborhood of $p$ in) $\mathbb R^3$, I suspect that you have computed the derivative of the extension.  This restricts to the derivative you are after along the embedding $T_pS^2 \hookrightarrow T_p\mathbb R^3$.
Note that $T_pS^2$ doesn't have a canonical basis.  Without choosing a basis, linear maps $T_pS^2 \to \dots$ cannot be written as matrices.  For any choice of basis they can be.  For example, if $p = (x,y,z) \neq S,N$, you could decide to use latitude and longitude $-z(\partial_x + \partial_y) + r \partial z$ and $y \partial_x - x \partial_y$, where $r = \sqrt{x^2 + y^2}$ is the distance to the pole (and $\partial_x,\partial_y,\partial z$ are the standard basis in $T_p\mathbb R^3 \cong \mathbb R^3$).  Or you could decide that you prefer unit vectors, and rescale the vector pointing along latitude lines $y \partial_x - x \partial_y \leadsto r^{-1}(y \partial_x - x \partial_y)$.

Dimension of tangent spaces


Properties Handling With Seam In A Spring-like fashion

Question: One of the Spring features I like the most is how you can handle properties loaded from a file. You only to need to set up a bean like the one below
<bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location" value="/WEB-INF/app.properties" />
</bean>

Now you are able to inject the properties values loaded from the app.properties into your beans by using either xml (see below) or annotations.
<bean class="com.example.PersonDaoImpl">
    <property name="maxResults" value="${results.max}"/>
</bean>

results.max is one of the properties.
I'm great fan of this feature because it enables me to create quite flexible applications that I can turn on/off some functionality by only changing one property - without redeploying the app.
Now I'm working with JBoss Seam and I've been struggling to find a way to do something similar using this framework.
Does anyone know how to do it? If not, does anyone have any idea of how I could handle properties in a nice way using Seam (I have seen some ways - but none of them were good enough).
Thanks.
Answer: If there's no appropriate way using you software stack (is there really no dependency injection!?). I'd say: Use Google Guice (https://code.google.com/p/google-guice/ , https://code.google.com/p/google-guice/wiki/Motivation?tm=6)!
Bad thing with Guice: You may have to read a lot to understand how it works, and what you can do with it. But after it's running you will simply inject your Properties object where you need it:
class YourClass {
  @Inject Properties myProperties;

  @Inject
  public YourClass() { ... }

  public void someMethod() {
    use the property
  }
}

or if you need the properties inside the constructor, you could also do:
class YourClass {
  final Properties myProperties;

  @Inject
  public YourClass(Properties myProperties) {
    this.myProperties = myProperties;
  }

  public void someMethod() {
    use the property
  }
}

Using Guice maybe enforces you to refactor your whole app.
But if you already have some DI framework, you should simply use that :)


Sum of angles in $\mathbb{R}^n$

Question: Given three vectors $v_1,v_2$ and $v_3$ in $\mathbb{R}^n$ with the standard scalar product the follwing is true
$$\angle(v_1,v_2)+\angle(v_2,v_3)\geq \angle(v_1,v_3).$$
It tried to substitute $\angle(v_1,v_2) = cos^{-1}\frac{v_1 \cdot v_2}{\Vert v_1 \Vert \Vert v_2 \Vert}$ but I could not show the resulting inequality. What is the name of the inequality and do you know reference that one can cite in an article?
Answer: I'd like to suggest "triangle inequality in spherical geometry".
Comment: Any reference for this?
Comment: I don't find a reference for this either!
Answer: You can reduce the problem to $\mathbb{R}^3$, and there wlog v2=(0,0,1)
then one gets an easy to prove inequality if one writes everything in polar coordinates.

Sum of angles in $\mathbb{R}^n$


Find a flaw with my proof of countability of reals in the interval $[0,1)$

Question: According to my understanding, if you can find a counting scheme where eventually any element of a set will be counted, you prove the countability of a set in some loose sense. Examples: proving coutability of cross product of two countable sets or countable union of countable sets.
In case of reals in the interval $[0,1)$, I was thinking that we can too find a counting scheme. First let us count the decimals having only one free place (starting from the decimal to the right) to have any digit and rest all zero like 0.0,0.1,0.3 etc. Second let us have two free places, so the possibilities will be 0.01,0.89 etc. Similarly 3 places and so on. Also let us take care to remove any numbers having insignificant zeros as they are redundant, like 0.5600 etc..In each steps we have finite no of values to count and if we follow this scheme, eventually all the reals will be included(or will they be?).If not! which part of the proof changed from the countable union of countable set proof where everything will be included eventually?
And what about this other scheme :
"First count the
decimals that have only one nonzero digit, then those with at
most two nonzero digits, and so on; we have then broken the
set into a countable collection of countable sets"?
Answer: I think I have found an answer. There will be many reals which have infinite no. of non zero numbers in decimal places which will never by exhausted by my counting schemes making the proofs invalid.
Comment: That's correct.  What you have done, in effect, is counting the _finite_ subsets of the natural numbers (corresponding to which decimal places or which binary places in base 2 are nonzero), whereas there are also _infinite_ subsets (infinitely many nonzero decimal or binary digits).  The infinite subsets are what's uncountable; but the countability of the finite subsets can be used to prove that the _algebraic_ numbers are countable.
Comment: Just after writing down the question, it came to me. Should I delete the post?
Comment: Congratulations, you answered your own question in just 4 min!
Comment: @Bhaswat Usually it's a good practice to keep the post together with the answer, however, this particular question (even in this form) was asked here many times.


About definite integral and Gauss hypergeometric function

Question: I feel very shameful asking questions on this forum, but while solving complex mathematical papers, sometimes I just cannot understand how the authors have proceeded. :(
Not sure if this is the case with everyone or is it just me
$$G(\theta) = 1+d\cos(n\theta)$$
$$\boxed{I = \int^{2\pi}_0 G(\theta)^{2/n} d\theta}$$
Authors claim that this integral can be simplified to:
$$= \pi\Big[
(1-d)^{2/n}{_2F_1}\Big(\frac{1}{2},-\frac{2}{n},1,\frac{2d}{d-1}\Big)+
(1+d)^{2/n}{_2F_1}\Big(\frac{1}{2},-\frac{2}{n},1,\frac{2d}{d+1}\Big)\Big] $$
$$= 2\pi - \frac{\pi(n-2)}{n}d^2 + \mathcal{O}(d^4)$$
where ${_2F_1}$ is the Gaussian hypergeometric function.
I have no idea where this come from. I looked at the book thoroughly : "Table of integrals, series, and products / I.S. Gradshteyn and I.M. Ryzhik ; Daniel Zwillinger" but could not find.
PS. There are some other details later, which I am unable to grasp fully. Also I can't find how $\mathcal{O}(.)$ comes from. Please find the figure attached.
Answer: Assuming $|d|<1$, you can write $(1 + d \cos(n\theta))^{2/n}$ as a binomial series
$$ (1+d \cos(n\theta)^{2/n} = \sum_{k=0}^\infty {2/n \choose k} (d\cos(n\theta))^k$$
and integrate term-by-term.  Assuming $n$ is a nonzero integer,
$$ \int_0^{2\pi} \cos(n\theta)^k \; d\theta = \cases{0 & if $k$ is odd\cr
                                         {k \choose k/2} 2^{1-k} \pi & if $k$ is even}$$
and then your integral becomes
$$ \sum_{j=0}^\infty {2/n \choose 2j} {2j \choose j} 2^{1-2j} \pi d^{2j} = 2\,\pi\,
{\mbox{$_2$F$_1$}(-1/n,(n-2)/(2n);\,1;\,{d}^{2})}
$$
I don't know where the other hypergeometric expression comes from, but I hope this helps.
Comment: If $d > 1$, $1 + d \cos(n\theta)$ can be negative, and that will give your integral an imaginary component when $n$ is divisible by $4$.
Comment: Thanks for the answer. Do you have any comment on the $\mathcal{O}(d^4}$ i.e. Big-O notation here?
Comment: I have actually two objections. First that since $n\geq2$, we $2/n$ is not always an integer quantity. But, may be for simplifications authors in the paper ignore this fact. Second, $d>0$, and it can even be $>1$ as well :(
Comment: I want $n$ to be an integer, not $2/n$.
Comment: @RobertIsrael Why only divisible by 4? The argument of the integrand is either $0$ or $2 \pi/n$, the imaginary part doesn't cancel out when $d > 1 \land n > 2$. For $0 < d < 1$, your result extends to real $n$, because the integral and ${_2F_1}$ are analytic at infinity.
Comment: If $n$ is not divisible by $4$, $z^{2/n}$ where $z$ is negative has a real branch.  The question did not specify which branch to use.
Answer: I don't see why it would be shameful to ask for a clarification, especially since the series expansion in (13) appears to contain a mistake. I'll use the closed form given by Robert Israel. The coefficient at $d^2$ in the expansion around $d = 0$ is
$$\frac
 {2 \pi \left( -\frac 1 \eta \right)_{\hspace{-2px}1}
  \left( \frac 1 2 - \frac 1 \eta\right)_{\hspace{-2px}1}}
 {(1)_1} =
\frac {\pi (2 - \eta)} {\eta^2}.$$
For $d = 1$, Gauss's theorem gives
$$2 \pi \,{_2F_1} \!\left( -\frac 1 \eta, \frac 1 2 - \frac 1 \eta; 1; 1 \right) =
\frac
 {2 \pi \Gamma(1) \Gamma \!\left( \frac 1 2 + \frac 2 \eta \right)}
 {\Gamma \!\left( \frac 1 2 + \frac 1 \eta \right)
  \Gamma \!\left( 1 + \frac 1 \eta \right)},$$
and (14) is the expansion around $\eta = \infty$.
Comment: Thanks for the response. What does $\mathcal{O}(d^4)$ mean here and how can I solve this thing numerically (I mean on Matlab)
Comment: It's the [big O notation](https://en.wikipedia.org/wiki/Big_O_notation). The argument of ${_2F_1}$ is $d^2$, the next term in the Taylor expansion is of order $d^4$. I'm not sure whether you want to compute the integral or something else numerically.


How do I run a command from a base64 encoded string in bash?

Question: I would like to run a command from a base64 encoded string in bash. For example bHMgLWwgLwo= would be equal to ls -l. How do I do this?
Comment: But that is exactly what the first link is - "*How can I decode base64 string on Linux command and then execute the decoded string?*" - isn't it?
Comment: https://stackoverflow.com/questions/42011572/decode-from-base64-and-execute-command ? (related: https://askubuntu.com/questions/178521/how-can-i-decode-a-base64-string-from-the-command-line )
Comment: @TessellatingHeckler Not exactly, I want to decode a string and run that decoded string. I found a solution though I'll post as an answer shortly.
Answer: You can run a base64 encoded string in bash by piping the output of the base64 package for coreutils to bash. For example the command base64 -D <<< bHMgLWwgLwo= | sh would run the command ls -l.
Comment: on my version the option is `-d`
Answer: If you need to do it with bypassing the special characters.
echo bHMgLWwgLwo= | base64 -d | sh


Input to execute a dos command bat

Question: I want something like this
if user inputs NK then execute IDK
if user inputs CHKDSK then execute CHKDSK
if user inputs TRUMP then execute start
Answer: Easy? right?
<code>set/p input=
:: ^ gets input

if "%input%" == "NK" start IDK
if "%input%" == "CHKDSK" start CHKDSK
if "%input%" == "TRUMP" start IDK
:: ^ check input
</code>

Input to execute a dos command bat


HTML Helpers em ASP.NET MVC 4

Question: Vi alguns HTML Helpers assim: @Html.LabelFor(x => x) e @Html.LabelFor(model => model.Propriedade), porém, não entendo esse parâmetro que devo passar, x => x, o que é isso?
Comment: Entendi, mas aonde o DisplayName entra nisso? O resultado em HTML não devia ser:
Propriedade do model?
Comment: Adicionei uma resposta mostrando como o `LabelFor` chega até o `DisplayName` da propriedade indicada pela lambda. Se sobrar alguma dúvida é só falar! Abç
Comment: Continuo sem entender o uso do lambda, para mim, faria mais sentido assim:
@Html.LabelFor(Model.Propriedade)
Comment: Dessa forma, você estaria passando o valor da propriedade para o helper. Imagine que exista essa propriedade na classe do modelo: `[Display(Name="Nome da pessoa")] public string Name { get; set; }`, com o valor `"Miguel Angelo"` atribuido a ela... Se fosse da forma que você disse, não haveria diferená entre `@Html.LabelFor(Model.Name)` e `@Html.LabelFor("Miguel Angelo")`. Não é o valor da propriedade que queremos passar, mas sim, algo que seja capaz de identificar **de qual propriedade** obter o `DisplayName`, que é informação dada através do atributo `Display`: `"Nome da pessoa"`.
Comment: Eu consegui entender o resultado disso, porém, não consigo entender a sintaxe do lambda, oque quer dizer x => x.Propriedade, por que X? por que não Y? Como o C# reconhece X como o Model?
Comment: O nome da variável, é você que inventa. Pode ser `x`, `y`, `m`, `model`... qualquer coisa. O C# sabe qual é o tipo, pois ele é capaz de "adivinhar" através de um processo de inferência de tipo. Eu vou editar a minha resposta mostrando como o C# faz isso passo a passo.
Comment: @andré Dê uma olhada no [tour]. Você pode aceitar uma resposta se ela resolveu seu problema. Você pode votar em todos os posts do site também. Alguma lhe ajudou mais? Precisa que algo seja melhorado?
Answer: Objetivo do parâmtero x => x....
Esse parâmetro é usado para que o helper, no caso LabelFor saiba qual é a propriedade do seu objeto Model para a qual ele deve renderizar uma label. A partir desse momento, o LabelFor é capaz de obter os metadados da propriedade indicada. No caso ele vai estar interessado em uma metadado chamado DisplayName.

caso 1:
 @Html.LabelFor(x => x)

Isso quer dizer: renderize um label para o objeto Model como um todo. A regra para obter os metadados do model raiz depende de uma hierarquia de renderização. Essa forma é mais comum dentro de Editor Templates e Display Templates, pois dentro dos templates essa hierarquia está disponível.
caso 2:
 @Html.LabelFor(x => x.MinhaPropriedade)

Isso quer dizer: renderize um label para a propriedade MinhaPropriedade. O método LabelFor sabe como extrair essa informação a partir dos metadados da propriedade, sendo que uma das formas é colocar o atributo Display(Name = "Label da propriedade)" na propriedade.

Como o LabelFor obtem o display name?
Agora que já expliquei o objetivo da lambda sendo passada para o helper, vou explicar o funcionamento, ou seja, como um helper faz para chegar até os metadados da propriedade em questão.
O helper, quando chamado, terá acesso ao objeto HtmlHelper<TModel>, e à lambda passada por parâmetro. Eis a definição do método LabelFor:
public static MvcHtmlString LabelFor<TModel, TValue>(
    this HtmlHelper<TModel> html,
    Expression<Func<TModel, TValue>> expression)

HtmlHelper<TModel>: esse objeto é o Html (da expressão @Html....) sobre o qual o extension-method LabelFor está sendo aplicado (vale para outros html-helper quaisquer). Este é um objeto genérico, em que TModel é o tipo do modelo sendo usando pela view.
Esse objeto possui em sua estrutura, todos os metadados do modelo sendo trabalhado: html.ViewData.ModelMetadata.
lambda: esse parâmetro é passado como uma lambda, mas na verdade o tipo do objeto que o LabelFor recebe é Expression<Func<TModel, TValue>>. Esse tipo é capaz de representar a lambda passada na forma de uma AST (Abstract Syntax Tree) que irá conter em sua estrutura a propriedade deve ser usada na forma de um PropertyInfo (reflection). A partir daí, o helper é capaz de associar o PropertyInfo aos metados disponíveis no objeto html.ViewData.ModelMetadata e obter o DisplayName.

Como o C# faz para saber o tipo da lambda?
O C# faz isso através de um processo de inferência de tipos.
Sabemos que o método LabelFor é genérico com os tipos TModel e TValue, e também que ele recebe dois argumentos, ambos utilizando esses tipos genéricos:

this HtmlHelper<TModel> html
Expression<Func<TModel, TValue>> expression

Imagine a seguinte view contendo cshtml, cujo tipo do modelo seja MeuModelo e tenha uma propriedade MinhaProp do tipo string:
@model MeuModelo
@Html.LabelFor(x => x.MinhaProp)

O C#, sabe que o LabelFor é um método de extensão, e vai traduzir a chamada do método para:
System.Web.Mvc.Html.LabelExtensions.LabelFor(Html, x => x.MinhaProp)

Como o código acima não define os tipos genéricos TModel e TValue para o método LabelFor, então o C# vai ter que inferir ("adivinhar") quais são os tipos. Isso é feito através dos argumentos sendo passados para o método:

O argumento html está recebendo o valor de Html. Isso quer dizer que HtmlHelper<TModel> é igual a HtmlHelper<MeuModelo>. É possível ver que TModel tem que ser MeuModelo.
parâmetro      |  html  |  HtmlHelper<TModel>
valor passado  |  Html  |  HtmlHelper<MeuModelo>

conclusão: TModel = MeuModelo

O argumento expression é do tipo Expression<Func<TModel, TValue>>... só que como o C# já sabe que TModel é igual a MeuModelo, então pode substituir no tipo do parâmetro que fica assim:
Expression<Func<MeuModelo, TValue>>
Esse tipo significa "expressão que recebe MeuModelo e retorna TValue". Agora só falta saber qual é o tipo de TValue.
O parâmetro está recebendo x => x.MinhaProp. Essa lambda recebe x e retorna x.MinhaProp. Então é possível construir a seguinte tabela para analisar os tipos:
          |  Expression<Func<MeuModelo, TValue>>  |  x => x.MinhaProp
----------+---------------------------------------+---------------------
  recebe  |              MeuModelo                |     x
  retorna |              TValue                   |     x.MinhaProp

Na primeira linha é possível ver que x é d tipo MeuModelo. Sendo assim, x.MinhaProp é do tipo string. E finalmente TValue é do tipo string.

A inferência de tipos acabou, com as seguintes conclusões:

TModel é o tipo MeuModelo
x é do tipo MeuModelo
TValue é o tipo string

E agora é possível preencher os tipos genéricos do LabelFor:
System.Web.Mvc.Html.LabelExtensions.LabelFor<MeuModelo, string>(Html, x => x.MinhaProp)

Comment: Entendi. Obrigado pela ajuda.
Answer: LabelFor usa o seu Model configurado na View para renderizar um Label.
Exemplo:
// Model
public class SeuModel
{
    [DisplayName("Propriedade do model")]
    public string SuaPropriedade { get; set; }
}

Gera um Label na sua View relacionado a propriedade do seu Model:
// View
@model SeuModel
@Html.LabelFor(m => m.SuaPropriedade)

O "m" é o SeuModel. O parâmetro em forma m => m.SuaPropriedade é uma expressão lambda.
Resultado em html:
Propriedade do model

Answer: A ideia aqui foi dar uma ideia geral sobre lambda que o que foi usado no parâmetro referido. Leia as outras respostas para obter informações mais completas sobre todo o recurso, especial a do Miguel Angelo.
Isso chama-se lambda. Veja a documentação do C# sobre o assunto. Ela é uma função sem nome que é usada como uma expressão. É uma forma de passar ações que devem ser realizadas por algum outro algoritmo em determinado momento. Desta forma quando você declara a lambda você não está executando nada, está apenas definindo o que ela deve fazer. O código que ela a recebe em momento adequado a chamará como se fosse um método normal e neste momento é que aquela ação será executada. A execução exata disto é um pouco diferente de uma chamada normal, mas desta forma fica fácil você entender. Desta forma você passa informações de uma forma um pouco mais rica, você não está passando simplesmente valores, você passa toda uma estrutura de dados.
Neste caso você está dizendo que simplesmente está pegando o parâmetro x que a lambda está recebendo e usado este valor como Label naquele lugar. Este x receberá um valor passado pelo engine do ASP.Net MVC. Ele sabe o que passar e ele sabe quando usá-lo, ele só não sabe o que fazer com esta informação antes de usá-lo. No caso nem está fazendo nada importante mas poderia executar uma série de coisas com ele.
No segundo exemplo já faz um pouquinho mais. O parâmetro é model mas você não que usar o model pura e simplesmente, provavelmente nem daria, você está pegando um membro de model. Você está pegando model.Propriedade e é o valor deste membro que será usado no Label.
Lambda pode receber outros nomes.
Comment: No C#, uma lambda pode ser convertida em duas coisas: `Delegate` ou `Expression`. Sua explicação considera o primeiro caso, e é totalmente válida para entender lambdas. Ocorre que `LabelFor` (do `ASP.NET MVC`) se utiliza do segundo caso, no qual a lambda é convertida em uma AST, da qual metadados podem ser extraídos (e.g. label, se é required, formato, etc.), sendo que `x` é do tipo do próprio modelo, que é definida pelo usuário dentro do arquivo da view. P.S. Odeio ser crítico, ainda mais de alguém que ajuda tanto! No mais, gostei da referência à origem matemática das lambdas.
Comment: @MiguelAngelo você tem razão, dei uma melhorada. Você deve ser crítico, isto é qualidade e não defeito. De qualquer forma vou deixar mais como um complemento, a sua está bem melhor para o contexto.

HTML Helpers em ASP.NET MVC 4


How to create custom ECK entity class (per bundle)

Question: With ECK I created Entity type Vehicle, and added 2 bundles, Car and Truck
Goal is to have a class Car so I can use Car::create() and similar entity functions, and also implement my own functions.
As far as I came is creating Vehicle class, and it's working, but I'm struggling with bundles.
Answer: I guess it is impossible to do what you want. A bundle is not a sub-class of an entity as you seem to be assuming.
Classes are always defined in code and are always provided by a module. ECK uses a workaround but in fact only defines one entity type: EckEntity, it then performs some tricks to let Drupal see this as different entity types.
Creating entities for every bundle dynamically (since a user can add / remove bundles) would be difficult and appears to be only possible using dirty tricks like this:
// With a property
$myclassname = "anewclassname";
$myproperty = "newproperty";
eval("class {$myclassname} { protected \${$myproperty}; }";

From: https://stackoverflow.com/a/15579465/1293725
I am pretty sure Drupal does not support this (luckily).
Bundles are stored as properties on the entity, often (always?) as the type property, have a look at this example:
// Create node object with attached file.
$node = Node::create([
  'type'        => 'article', // < - this is the bundle
  'title'       => 'Druplicon test',
  'field_image' => [
    'target_id' => $file->id(),
    'alt' => 'Hello world',
    'title' => 'Goodbye world'
  ],
]);
$node->save();

From: https://drupal.stackexchange.com/a/189095/9921
So in your case, you would need to do this:
$car = Vehicle::create([
  'type'        => 'car',
   ...
]);

Or define a new class for your bundles, but you would need to either use the eval method above to create a class for all your bundles, or define them in code and loose flexibility. Then in that class extend the Vehicle class and in the constructor provide the type or something. For the sake of readability of your code I guess it would be best to just follow conventions and not create classes for bundles.


No users with ALL PRIVILEGES

Question: I've encountered an issue after upgrade of MySQL server.
Probably, upgrade procedure went south.
The result was that none of the users had ALL PRIVILEGES grant.
All the administrators had GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, TRIGGER ON and GRANT OPTION
It looks very much like ALL PRIVILEGES translated into individual privileges, but obviousely something is missing. After reviewing the privileges listed, i've found that all the users were missing EVENT privilege.
mysql> SELECT * FROM mysql.user WHERE Event_priv='Y'\G
Empty set (0.01 sec)

Now, this privilege was added in MySQL 5.16 and is defined as enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', so probably UPDATE on existing users have failed (or is missing in the upgrade scripts).
After realizing what was wrong, i started to look for a solution here (I mean, if NO user has this privilege, how do i GRANT it?), and did not find a problem exactly like this one.
Answer: You should be aware of the --skip-grant-tables MySQL startup option - it allows for bypassing the permission checks for recovery purposes. A daemon started with this option would allow a root login without a password with ALL PRIVILEGES granted. You can change anything you like from there on.
Note: as running with a passwordless root account is likely to present a security risk, you should make sure to specify --skip-networking as well.
Comment: @poncha - If it would be just for the privileges, you would need to restart only once - a `FLUSH PRIVILEGES` would re-read the mysql.users table and put the privileges back in effect. Of course, since you're starting with skip-networking and do not want any succeeding connection attempts in the meantime anyway (they would get rejected due to failed authentication), this would actually mean restarting twice. On the other hand, it is a generic approach working with any kind of privilege / authentication problems.
Comment: This would require restarting a database server though (twice - second time to get back to normal state), which is time consuming, and means downtime
Comment: But this is worth mentioning, of course ;) so +1
Answer: So i thought i'd ask, but then i thought "wait a second, what if..."  and attempted to UPDATE the users table myself... and VOILA! MySQL actually LET ME do it!
So here it is:
Question: How to recover a missing EVENT privilege?
Answer:
 mysql> UPDATE mysql.user SET Event_priv='Y' WHERE User='root';
 Query OK, 1 row affected (0.00 sec)

 mysql> FLUSH PRIVILEGES;
 Query OK, 0 rows affected (0.14 sec)

Then login again to MySQL and that's it - SHOW GRANTS shows root having ALL PRIVILEGES again.

So (and this is my guess, correct me if i am wrong), as long as you still have UPDATE privilege that affects mysql privilege tables, you can pretty much grant any privilege to yourself or others by manually).
I'm sure this is conceptually OK (since i do have UPDATE...), but as a side note i'd say this is kinda weird that i can alter my own privileges to a larger set.
Comment: +1 for finding your own answer !!!

No users with ALL PRIVILEGES


How to make Youtube videos have different player?

Question: How can I make Youtube videos as below design:

Now please note that picture just an example basically I want simply to change Youtube video design on website where I will embed the video. Please also be aware that any information would count as help since I don't know from what to start and any example would be equal as answer.
Comment: What have you tried so far? I don't belive you can do it since you embed a iframe
Comment: Probably can be done, but I doubt YouTube makes it easy. Best bet is to probably use a 3rd party application. Google [custom youtube player](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=custom%20youtube%20player) and look around, there appears to be several options.
Comment: you can embed video on only the popular way as people used to do on Youtube api page i found actually more than 4 ways to do it and found some articles how to do with JW payer so basically if i want custom design i need create custom JW player theme which is not easy thing so this idea is plan b now @Mark M gave very simple idea how to search basically with my keywords i didn';t get similar results will check it out further thank you
Answer: i don't think you can change the youtube player, but what you could do is
dig on the video and get the real link for mp4 file (you can try the YouTube-Downloader) by jeckman or something Similar then you could do a video player like Videojs or any other player with that link without saving the file on your server
Answer: There's two way you can change the way how Youtube controls looks like.
1.add parameters.
In the video page you want to use, clickshare and embed, below the  code.
You can change video size, show suggested videos when this one finishes or not, hide controls.

put a ? after the url to add your first parameter autoplay=1, if you want to put more parameters, add & followed by other parameter.
https://www.youtube.com/embed/0ES4oNo8B5I?autoplay=1&controls=0

This code means autoplay video and hide controls.
Here's parameters reference you can look up.
YouTube Embeded Player
2.This one needs more tech like jQuery. There's no short way to cover this, so I put the link here.
Making a Custom YouTube Video Player With YouTube's APIs


Laravel Foreach: Undefined Variable

Question: Im trying to pull all customer information, it should work as its is a simple foreach looping over information. Totally confused as to why I'm getting an undefined variable, in theory should this not work?
Route File:
 Route::group(array('before' => 'auth'), function() {
      // Get Customer (GET)
      Route::get('/customer/clientlist', array(
        'as' => 'clientlist',
        'uses' => 'CustomerController@getCustomers'
        ));
    });

Model:
class Customer extends Eloquent {
     //Mass assignment for security
     protected $fillable = array('address', 'city', 'postcode',
                          'phone', 'mobile', 'contact', 'user_id');
    //protected $table = 'customers';
    public function user() {
       return $this->hasMany('User');
    }
  }

Controller:
class CustomerController extends BaseController {
    public function getCustomers() {
      $customers = Customer::all();
      //var_dump($customers);
      return View::make('customer.clientlist', array('customers'=>$customers));
    }
  }

View home:
@extends('layout.main')
@section('content')

  @if(Auth::check())

Welcome, {{ Auth::user()->username }}

      <button type="button" class="c-add btn btn-danger pull-right">
        Add Client
      </button>

{{-- Close Row --}}

    @include('customer.client-add-form')

{{-- Close client form --}}

Direct Furniture

Address: 595 Boom Road

City: Manchester

Postcode: BT11 9AB

Tel: 028 9011 1162

Mobile: 078 902 815 611

Contact: Brian McNally

Direct Furniture

      <address>
        795 Folsom Ave, Suite 600

        San Francisco, CA 94107

        Phone: (123) 456-7890

        Mobile: (123) 456-7890
      </address>
      <address>
        Contact

        Andrew Ellis
      </address>

    @include('customer.clientlist')

«

1

2

3

4

5

»

  @endif

{{-- Close Container --}}
@stop

View clientlist:
@foreach($customers as $customer)

{{ $customer->name }}

    <address>
       795 Folsom Ave, Suite 600

       San Francisco, CA 94107

       Phone: (123) 456-7890

       Mobile: (123) 456-7890
    </address>
    <address>
       Contact

       Andrew Ellis
    </address>

@endforeach

This is the error exception Im currently getting, I cant understand as to why I keep getting this, if I comment out the controller and put static information into the view it does work.
ErrorException

Undefined variable: customers (View:/Users/Sites/nit/app/app/views/customer/clientlist.blade.php)
  <?php echo $__env->make('customer.clientlist', array('customers'=>$customers), array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
Answer: I see the problem - you are including the customer.clientlist file in itself.
In your controller you call
return View::make('customer.clientlist', array('customers'=>$customers));

then in your view you call it again
@include('customer.clientlist', array('customers'=>$customers))

creating an infinite loop. I'm guessing it should be
@include('customer.viewclientlist', array('customers'=>$customers))

And as mentioned by @Joseph Silber - you dont actually need to pass in the array on the include anymore - so make it this to clean up your code:
@include('customer.viewclientlist')

Comment: so update the view name to -> viewclientlist? Will this also not have to be updated in the controller too, so it does not throw an undefined view name?
Comment: You need to update the @include() filename to be whatever your file is "View client list" that you put in your question. If you are not sure - update your question with the exact file names of your views and I'll tell you what to write.
Comment: The Shift Exchange, I updated the route -as statement, controller, main view and changed the name of the file to viewclientlist. Updated above.
Comment: Crippy - let me put it to you another way - You are doing "Return view::make('File1'). Then inside "File1" you are doing @include(File1). It should be @include(File2). You need to fix up your code to not have an infinite loop.
Comment: The Shift Exchange - I am doing "Return view::make('File1')". Inside my "File1" it contains the @foreach. Im including the "File1" template inside my "home" view as "@include(File1)" to render the foreach as a set of results. Is this totally wrong, now a little confused, appreciate your time over this.
Comment: Please put the EXACT filenames in your question. i.e. where you have "View which pull clientlist:" heading - change the heading to the EXACT file name. Same as "View viewclientlist:" - change the headings to the exact file names
Comment: And is "clientlist.blade.php" exactly as you have posted? Is there any more code inside that view file?
Comment: And when you "var_dump($customers)" inside your controller - does that work?
Comment: No it doesn't, still returning the ErrorException
Comment: change "var_dump($customers)" to "dd($customers->toArray())" - what does that show you? Do you see an array of customers?
Comment: Nothing again The Shift Exchange, Im gonna go break it down again and try rebuild it, I have followed the documentation, just puzzling! Really appreciate your help with it.
Comment: Yeah - I was going to suggest that - strip everything away - start fresh - and slowly build it back up until the error re-appears. Good luck!
Comment: Thanks again, really appreciate the time spent over it!

Laravel Foreach: Undefined Variable


vim uses /tmp for shell functions

Question: When vim uses the shell given a colon !command, it does so through the /tmp filesystem. How do you force vim to use ~/.vim/tmp/ instead? It also uses /tmp for help files when zcat is required to read some of the manuals.
TMPDIR doesn't work for this case.
Answer: Have you tried setting the TMPDIR environment variable?  That's the standard way (across most "Unix style" programs I've had to worry about it for) of specifying an alternate location for temporary files.
Comment: Actually, this works. I was thinking you were referring to vim's 'directory' setting. Thanks.
Comment: I've clarified my wording to make it clear I was referring to the env var.

vim uses /tmp for shell functions


Microsoft Exchange 2013 Shared calendars on Mobile Devices

Question: I have an Exchange 2013 server with a user shared calendar. Can't configure an iPhone to view the shared calendar. It doesn't appear on the MS Outlook app, nor the MS OWA app.
Any suggestions:
My goal is to share a calendar and set permission for some users to view only and others to edit, all to have smartphone access.
Answer: Not possible natively. The only way to access a shared calendar is to have full access to the mailbox and its password.
There are some third party apps which can access it for you, I haven't tried any, but I know they (did) exist. Check the App Store.
Simon.