"Works on my machine" - How to fix non-reproducible bugs?

Question: Very occasionally, despite all testing efforts, I get hit with a bug report from a customer that I simply can't reproduce in the office.

(Apologies to Jeff for the 'borrowing' of the badge)
I have a few "tools" that I can use to try and locate and fix these, but it always feels a bit like I'm knife-and-forking it:-

Asking for more and more context from the customer: (systeminfo)
Log files from our application
Ad-hoc tests with the customer to attempt to change the behaviour
Providing customer with a new build with additional diagnostics
Thinking about the problem in the bath...
Site visit (assuming customer is somewhere warm and sunny)

Are there set procedures, or other techniques than anyone uses to resolve problems like this?
Comment: Actually, I just realised that this is a duplicate of http://stackoverflow.com/questions/838770/how-do-you-troubleshoot-with-works-on-my-machine-scenarios
Comment: @jpoh - I saw that, but the answers - and the question itself - seemed to be about addressing the WOMM "attitude" rather than actual bug-killing.
Comment: love the badge, need to get me one of those :)
Comment: Unlocked and re-opened as part of locked question review. If this is a duplicate, close as such and request a merge. This is a common problem with some good answers - seems like "good subjective" to me. Down-vote and flag useless answers for removal.
Answer: One of the attributes of good debuggers, I think is that they always have a lot of weapons in their toolkit. They never seem to get "stuck" for too long and there is always something else for them to try. Some of the things I've been known to do:

ask for memory dumps
install a remote debugger on a client machine
add tracing code to builds
add logging code for debugging purposes
add performance counters
add configuration parameters to various bits of suspicious code so I can turn on and off features
rewrite and refactor suspicious code
try to replicate the issue locally on a different OS or machine
use debugging tools such as application verifier
use 3rd party load generation tools
write simulation tools in-house for load generation when the above failed
use tools like Glowcode to analyse memory leaks and performance issues
reinstall the client machine from scratch
get registry dumps and apply them locally
use registry and file watcher tools

Eventually, I find the bug just gives up out of some kind of awe at my persistence. Or the client realises that it's probably a machine or client side install or configuration issue.
Comment: Also stuff like VNC and remote desktop can help when you want to be able to actually see what the program does and how the user gets there.
Answer: Extensive logging usually helps.
Comment: also ask for a detailed recipe for reproducing the error on clients machine. recent software installs.
Answer: The easiest way is always to see the customer in action (assuming that its readily reproducible by the customer). Oftentimes, problems arise due to issues with the customer's computer environment, conflicts with other programs, etc - these are details which you will not be able to catch on your dev rig. So a site visit might be useful; but if that's not convenient, tools like RealVNC might help as well in letting you see the customer 'do their thing'.
(watching the customer in action also allows you to catch them out in any WTF moments that they might have)
Now, if the problem is intermittent, then things get somewhat more complicated. The best way to get around this problem would be to log useful information in places where you guess problems could occur and perhaps use a tool like Splunk to index the log files during analysis. A diagnostic build (i.e. with extra logging) might be useful in this case.
Comment: We found Webex useful for doing online demonstrations to clients and also for helping clients out with problems.
Answer: I'm just in the middle of implementing an automated error reporting system that sends back to me information (currently via email although you could use a webservice) from any exception encountered by the app.
That way I get (nearly) all the information that I would do if I was sitting in front of VS2008 and it really helps me to work out what the problem is.
The customers are also usually (sorta) impressed that I know about their problem as soon as they encounter it!
Also, if you use the Application.ThreadException error handler you can send back info on unexpected exceptions too!
Comment: Good point - I'm already using MadExcept for all our apps, with emailed bug reports straight back to base. However, in my latest case, the app just quits without warning!
Comment: Unfortunately this only tells you when an error is happening, does not tell you why and what steps were done to make it happen
Comment: +1, though of course for some bugs the behaviour is not an exception, but just "I expected A and instead the wrong thing B happened".
Answer: We use all the methods you mention progressively starting with the easiest and proceeding to the harder.
However you forget that sometimes hardware is at fault. For example, memory could be malfunctioning and some computation-intensive code will behave strangely throwing exceptions with weird diagnostics. Of cource, it works on your machine, since you don't have faulty hardware.
Experience is needed to identify such errors and insist that customer tries to install the program on another machine or does hardware check. One thing that helps greatly is good error handling - when your code throws an exception it should provide details, not just indicate that something is bad. With good error indication it's easier to identify such suspicious issues related to faulty hardware.
Answer: I think one of the most important things is the ability to ask sensible questions around what the customer has reported... More often than not they're not mentioning something that they don't see as relevant, but is actually key.
Telepathy would also be useful...
Answer: We've had good success using EurekaLog with it posting directly to FogBugz. This gets us a bug report containing a call stack, along with related system info (other processes running, memory, network details etc) and a screen shot. Occasionally customers enter further info too, which is helpful. It's certainly, in most cases, made it much easier and quicker to fix bugs.
Comment: Very similar - we use MadExcept posting straight into fogbugz.
Comment: We originally started with MadExcept, but switched to EurekaLog since the output was better (may have changed now since that was a couple of years back).
Answer: One technique I've found useful is building an application with an integrated "diagnostic" mode (enabled by a command line switch when you launch the app). That certainly avoids the need to create custom builds with additional logging.
Otherwise, it sounds like what you're doing is as good an approach as any.
Answer: Copilot (assuming customer is somewhere cold and rainy :)
Answer: The usual procedure for this is to expect something like this will happen and add a ton of logging information. Of course you don't enable it from the beginning, but only when this happens.
Usually customers don't like to have to install a new version or some diagnostic tools. It is not their job to do your debugging. And visiting a client for cases like these is rarely an option. You must involve the client as little as possible. Changing a switch and sending you a log file is OK - anything more than this is too much.
I like the alternative of thinking the problem at the bath. I will start from trying to find out the differences between my machine and the client's configuration.
Answer: As a software engineer doing webstuff (booking/shop/member systems etc) the most important thing for us is to get as much information from the customer as possible.
Going from

it's broke!

to

it's broke! & here are screenshots of
  every option I picked whilst
  generating this particular report

reduces the amount of time it takes us to reproduce and fix an issue no end.
It may be obvious, but it takes a fair amount of chasing to get this kind of information from our customers sometimes! But it's worth it just for those moments you find they're not actually doing what they say they are.
Answer: I had these problems also. My solution was to add lots of logging and give the customer a debug build with all the possible debug information. Then make sure dr Watson (it was on Windows NT) created a memory dump with enough information.
After loading the memory dump in the debugger I could find out where and why it crashed.
EDIT: Oh, this obviously only works if the application terminates violently...
Answer: I think following the trail of the actions user took can lead us to the reasons of failure or selective failures. But most of the times users are at loss to precisely describe the interactions with the applications, the automatic screenshot taking (if it is desktop app. for .net app you can check Jeff's UnhandledExceptionHandler). Logging all the important action which change state of the objects can also help us in understanding it.
Answer: Its very complicated issue . I was thinking writing some procedure for this .  I just made some procedure for this  non-reproducible bug . it might be helpful
When the Bug accorded .. There are several factors it might to occur.
I am Sure all bugs are reproducible . I always keep eye for these kind of issues..

Get the System Information
what other process the customer did before that.
Time period it occurs . its rare or frequent
its next action happened after the issue  ( its always same or different )
Find the factors  for this bug ( as developer )
Find the exact position where this issue happened .
Find ALL THE SYSTEM Factors on that time
check all memory leaks or user error issue or wrong condition in code
List out all facotrs to may cause this issue.
How the each factors are affected this and wat are the data is holding those factors
Check memeory issues happened
check the customer have the current update code like yours
check all log from atleast 1 month and find any upnormal operation happened . keep on note
Answer: I don't have this problem very often, but if I did, I would use a screen sharing or recorded application to watch the user in action without having to go there (unless, as you said, it's warm and sunny and the company pays the trip).
Answer: I have recently been investigating such an issue myself. Over the course of my carrier I have learnt that, while computer systems may be complex, they are predictable so have faith that you can find the problem. My approach to these kinds of issues two fold:
1) Gather as much detailed information as possible from the customer about their failure and analyse it meticulously for patterns. Gather multiple sets of data for multiple failure occurrences to build up a clearer picture.
2) Try and reproduce the failure in house. Continue to make your system more and more similar to the customers system until you can reproduce it, the system is identical or it becomes impractical to make it more similar.
While doing this consider:
1)What differences exist between this system and other working systems.
2)What has recently changed in your product or the customers configuration that has caused the problem to start occurring.
Regards
Answer: Depending on the issue you could get WinDbg dumps, they normally give a pretty good idea of what is going on.  We have diagnosed quite a few problems that weren't crashed from minidumps.
For .Net apps we also was Trace.Writeline then we can get the user to fire up DbgView and send us the output.
Answer: Just a short anecdote (hence 'community wiki'): Last week I thought it was a clever idea in a Django app to import the module pprint for pretty printing Python data only if DEBUG was True:
if settings.DEBUG:
    from pprint import pprint

Then I used here and there the pprint command as debugging statement:
pprint(somevar) # show somevar on the console

After finishing the work, I tested the app with setting DEBUG=False. You can guess what happened: The site broke with HTTP500 errors all over the place, and I did not know why, because there is no traceback if DEBUG is False. I was puzzled that the errors disappeared magically, if I switched back to debug mode.
It took me 1-2 hours of putting print statements all over the code to find that the code crashes at exactly the above pprint() line. Then it took me another half an hour to convince myself to stop banging my head on the table.
Now comes the moral of the story:

Not every thing that looks like a clever idea in the first view is such savvy in the end.
An important point to look at for debugging these errors are all configuration options and platform switches your code by itself makes. This can be quite a lot more than just some user preferences. Document good, if you make an assumption about the user's platform (e.g., if you test for Win/Mac/Linux only, will your code crash on BSD or Solaris?)

Cheers,
Answer: However tough a non-reproducible problem is - we can still have a structured and strategic  approach to solve them - and I can say through experience that it requires out of box thinking in 50% of the cases. Generally speaking, one can categorize the problems into different types which helps to identify what tool to be used. For example if you have a non-reproducible application crash issue or a memory issue you can use profilers and nail down the issue caused in the particular functionality.
Also, one of the most important approach is inforamation rich logging. I also use a lot of enums to describe the state of the process depending on the scenario in question. for exampe, I used like Initiated, Triggered, Running, Waiting Repaired etc to describe the schedules states and saved them to DB at different stages.
Answer: Not mentioned yet, but "directed code review" is one good solution, especially if you didn't do a proper review  (at least 1 hour per 100 lines of code) before release.
I have also seen impressive demos of AppSight Suite, which is basically an advanced environment monitoring and logging tool. It allows the customer to record what happens on his machine in an extensive but fairly compact log file which you can then replay.
Answer: As many have mentioned, extensive logging, and asking the client for the log files when something goes wrong. In addition, as I worked more with web apps, I'll also provide detailed, but succinct deployment documentation (e.g., deployment steps, environmental resources that need to be set up etc).
Here are common problems I've seen that lead to the types of problem you are describing:

Environment not set up properly (e.g., missing environment variables, data sources etc).
Application not fully deployed (e.g., database schema not deployed).
Difference in operating system configuration (default character encoding being the most common culprit for me).

Most of the time, these issues can be identified through the log content.
Answer: You can use tools like Microsoft SharedView or TeamViewer to connect to remote PC and inspect problem directly on site. Of course, you'll need cooperation with customer.


How do I use robocopy with a large number of excluded files?

Question: I want to use robocopy to move a large number of files, except those that are in a whitelist.  The whitelist contains approximately 150 files of different names.  When I copy-and-paste the whitelist's filenames into the command line (using the /xf parameter), robocopy truncates the list.
c:\test> robocopy src dest *.ext /xf exclude1.ext exclude2.ext exclude3.ext ... exclude 299.ext exclude300.ext

Results in:
-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows

-------------------------------------------------------------------------------

  Started : Fri May 24 14:09:31 2013

   Source : C:\test\src\
     Dest : C:\test\dest\

    Files : *.ext

Exc Files : exclude1.ext
            exclude2.ext
            exclude3.ext
            ....
            ....
            exclude200.ext
            exclude201.ext
            exclu

and then:
'exclude250.ext' is not recognized as an internal or external command,
operable program or batch file.
'exclude251.ext' is not recognized as an internal or external command,
operable program or batch file.
'exclude252.ext' is not recognized as an internal or external command,
operable program or batch file.
'exclude253.ext' is not recognized as an internal or external command,
operable program or batch file.

Unfortunately the files in the whitelist are hand-picked and can't be filtered by wildcards.
Is there a way to get around this?
Comment: This accepted answer has the highest point value (which is good).  However, after three years (in 2016), @fara-importanta added an answer suggesting the job file, and included a quick, but very usable mention of that files syntax. see https://serverfault.com/questions/510482/how-do-i-use-robocopy-with-a-large-number-of-excluded-files#813004
Answer: There is a limit on command line length (I think it is something like 2048 characters) in windows.
You should generate a job file with a small subset of the exclusion list specified (using the /save:filename argument) to get the syntax, edit the file to include the full list, and then use the /job:filename argument to run it.
For reference, the documentation for this tool can be found here.
Comment: This accepted answer has the highest point value (which is good).  After three years, @fara-importanta added an answer suggesting the job file, and included a quick, but very usable mention of that files syntax. see https://serverfault.com/questions/510482/how-do-i-use-robocopy-with-a-large-number-of-excluded-files#813004
Answer: Turns out that the robocopy job file syntax is not that complicated.
For your specific situation you can achieve what you want by creating a robocopy job file with the following content:
/XD
exclude1.ext
exclude2.ext
exclude3.ext
....

If you'd want to do the same for files too, then your robocopy job file would look like this:
/XD
exclude1.ext
exclude2.ext
exclude3.ext
....

/XF
file1.ext
file2.ext
file3.ext
....

By using the same logic you can move any other options from the command line to the job file.
Comment: Thank you for the syntax of the job file.  I could not find it elsewhere.  I put a link to this answer in the comments of the accepted answer.
Answer: try using wildcards after the /XF filename1*.ext filename2*.ext filename3*.ext  This will only work if you know that the filename is unique in the entire structure.  You may change the naming convention of the files you want to exclude to get around this limitation.


Como converter uma String para TNotifyEvent no Delphi?

Question: Quero mudar o evento OnTimer de um TTimer no meu projeto em tempo de execução, tentei da seguinte forma: Timer1.OnTimer:= ('close'); Mas o Delphi informa isto: (E2010 Incompatible types: 'TNotifyEvent' and 'string'), como poderei converter a String 'Close' para TNotifyEvent?
Answer: Você deve enviar uma Procedure para o Ontimer, e não uma String.
Se sua intenção com a String 'Close' for fechar o Formulario é simples, crie uma Procedure com o tipo (Sender: TObject) com o comando Close:
procedure FecharFormulario(Sender: TObject);
begin
  Close;
end;

Para o Evento OnTimer você faz:
Timer1.OnTimer := FecharFormulario;

Comment: Ai voltamos a estaca Zero, onde você não deve enviar String para o Evento!
Comment: E se eu quiser dar a função do evento através de parâmetros estabelecidos por um arquivo INI?
Answer: Para usar um arquivo .INI;
Primeiro criar um arquivo do tipo .ini com o conteúdo exemplo:
[P_LOG]
comando = teste
Função para fazer a leitura do arquivo .ini:
function TForm1.LeIni(sIndice, sCampo: string): string;
var
  ArqIni: TIniFile;
begin
  try
    Result := '';
    ArqIni := TIniFile.Create(ExtractFilePath(Application.ExeName) +'Teste.ini');
    try
    Result := Trim(ArqIni.ReadString(sIndice, sCampo, ''));
    finally
    ArqIni.Free;
    end;
  except
    ShowMessage
    ('Não foi possível encontrar o arquivo de Parâmetros .ini');
  end;

end;

Usando a função
procedure TForm1.Button3Click(Sender: TObject);
 var
  ConteudoArquivoINI :String;
begin
 ConteudoArquivoINI := LeIni('P_LOG', 'comando')) the
end;

Answer: Dá pra fazer algo como criar um record para armazenar o nome de cada procedimento:

type
  mrec = record
    nome: string;
    proc: procedure(Sender: TObject) of Object;
  end;
...
var
  s : string;
  procs: array of mrec;
begin
  Setlength(procs, 2);
  procs[0].nome := 'Button8Click';
  procs[0].proc := Button8Click;
  procs[1].nome := 'Button6Click';
  procs[1].proc := Button6Click;
end;
...
procedure ExecutaPeloNome(nome: string);
var
  i: integer;
begin
  for i := 0 to length(procs) - 1 do
    if procs[i].nome = nome then
    begin
      procs[i].proc(nil);
      break;
    end;
end;
...
ExecutaPeloNome('Button8Click');

Honestamente, não acho que vale a pena!
Comment: essa linha: proc: procedure(Sender: TObject) of Object; pode ser: proc: TNotifyEvent;


Como fazer uma API Post em ASP.NET Core sem usar MVC?

Question: Não trabalho com APIs em ASP.NET Core até ter que precisar dela para um projeto escrito em C#. Então, criei com um projeto padrão, com o seguinte controlador:
[Route("api/[controller]")]
[ApiController]
public class MetadataProcessController : ControllerBase {
    ...
    ...

    // GET api/MetadataProcess/5
    [HttpGet("{filename}")]
    public ActionResult<string> Get(string filename)
    {
        return "Hello " + filename;
    }

    // POST api/MetadataProcess
    [HttpPost]
    public ActionResult<string> Post([FromBody] string value)
    {
        return "Hello " + value;
    }

    ...
    ...
}

Fazendo chamada usando Get através da URL /api/MetadataProcess/algumaCoisa o resultado obtido é Hello algumaCoisa no navegador.
No entanto, ao chamar pelo Post usando o Postman, encodando a seguinte entrada:

O response é um erro em Json:

Tentei inserir outros valores no value, mas nada deu certo. O que posso estar fazendo de errado? Gostaria de receber na response um Hello + o que foi enviado na request.
Answer: O payload enviado deve ser uma string e não um objeto. Ou seja:
"C%..."

Ao invés de
{
   value: "C%..."
}

Answer: O problema é que você está enviando um objeto json, porém está pedindo uma string no método. Caso queira receber um objeto, crie uma classe com a propriedade Value:
public class Input
{
    public string Value { get; set; }
}

Caso queira apenas uma string, envie de fato uma string:


Amount of elements in finite vector space.

Question: I'm trying to resolve two exercises from Kostrikin's book.
Ex. 1

How many elements contains vector space $\mathbb{F}_p^n$ (vectors
$(x_1,x_2,\dots,x_n)$ of length $n$) over a field $\mathbb{F}_p$ with $p$
elements? How many solutions has equation
$a_1x_1+a_2x_2+\dots+a_nx_n=0$ (not all $a_i=0$)?

Ex. 2

How many $k$-dimmension subspaces ($1\le k\le n$) contains
$n$-dimension vector space $V$ over a field $F_q$ with $q$ elements.

I think, I resolve first exercise:
$$\left|\mathbb{F}_p^n\right|=p^n$$
because I need to create vector of length $n$. I can choose first element on $p$ ways, second too.... so $p\cdot p\cdot p\cdots p$. Number of solutions is an amount of linear dependent vectors in this space. Dimension of this space is equal $n$, so a maximum set of independent vectors contains $n$ vectors. Number of solution is equal $p^n-n$?
In case of second exercise I have two solutions.
First:
There is only one $k$-dimension subspace? Because all spaces with dimension $k$ are isomorphic.
Second:
Base of $V$ space contains $n$ vectors. So I can choose ${n \choose k}$ vectors from $V$ base and create $k$-dimension subspace. So there is ${n \choose k}$ subspaces.
Are any of my solutions correct?
Thanks.
Answer: Your answer to the first exercise is correct.
For the second exercise, first note that they ask for the number of $k$-dimensional subspaces, not the number of isomorphism classes of $k$-dimensional subspaces. If they were asking for isomorphism classes, then yes you're right there would only be 1. Also, you make the incorrect assumption that every $k$-dim subspace can be obtained as the span of a subset of your basis. This is not true. For example, in $F^2$ (let $F := \mathbb{F}_p$), you can take the basis $\{(1,0),(0,1)\}$, but here subsets of the basis yield only two distinct 1-dim subspaces, even though there are many more. For example, what about the subspace generated by $(1,1)$? In this example, $F^2$ should be thought of as a plane, and 1-dim subspaces are just lines in the plane going through the origin, which are classified by their slope (which may be infinity for the vertical line).
To correctly count the number of $k$-dim subspaces, note that any such subspace has a basis of $k$ vectors, and thus we can begin by counting the number of sets of $k$ linearly independent vectors in $V$, which we will identify with $F^n$. For the first vector you have $p^n-1$ choices (anything but $0$). For the second, you have $p^n-p$ choices (anything but a vector in the span of the first), and so on. Thus, you have
$$\prod_{j=0}^{k-1}(p^n-p^j)$$
possible ordered sets of $k$ linearly independent vectors in $V$. Thus we have a map (of sets):
$$f : \{\text{ordered lists of $k$ linearly independent vectors in $V$}\}\longrightarrow \{\text{$k$-dim subspaces of $V$}\}$$
(where $f(v_1,\ldots,v_k) = \text{Span}\{v_1,\ldots,v_k\}$) which is surjective, but not injective. We would like to count the size of $f^{-1}(U)$, where $U\le V$ is a $k$-dim subspace. Since $f^{-1}(U)$ is just the set of ordered bases of $U$, we find that
$$|f^{-1}(U)| = \text{the number of ordered bases of $U$}$$
Identifying $U$ with $F^k$, we find that the number of ordered bases of $U$ are in bijection with matrices in $GL_k(F)$ (this group acts freely and transitively on the set of such ordered bases, or alternatively, any such ordered basis gives you a matrix in $GL_k(F)$ with elements of the basis as columns). Thus, $|f^{-1}(U)| = |GL_k(F)|$. Since this doesn't depend on $U$, we find that the number of $k$-dim subspaces of $V$ is precisely:
$$\frac{\prod_{j=0}^{k-1}(p^n-p^j)}{|GL_k(F)|}$$
By the same reasoning as above, the size of $GL_k(F)$ is
$$|GL_k(F)| = \prod_{j=0}^{k-1}(p^k-p^j)$$
so:
$$\frac{\prod_{j=0}^{k-1}(p^n-p^j)}{|GL_k(F)|} = \frac{\prod_{j=0}^{k-1}(p^n-p^j)}{\prod_{j=0}^{k-1}(p^k-p^j)} = \prod_{j=0}^{k-1}\frac{p^{n-j}-1}{p^{k-j}-1}$$
Answer: After 4 years I faced this exercise again and I found that first exercise is not solved properly. First part is ok and $\left|\mathbb{F}_p^n\right|=p^n$. Second part is wrong. Number of solutions is not equal $p^n-n$.
My new solution:
Let's begin on count how many solution has this equation:
$$
a_1x_1+a_2x_2=0\;\;\;\;\;\; a_i,x_i\in\mathbb{F}_p
$$
Let's assume that $a_1\not =0$ (For $a_2$ result will be the same). Let's assign any value for $x_2$ (we have $p$ possibilities). Then $a_2x_2'=r$ ($x_2'$ is assigned value). $\mathbb{F}_p$ is a field, so $r$ has additive inverse element $-r$.
$$a_1x_1=-r$$
Basing on the same reason (and $a_1\not=0)$ $a_1$ has multiplicative inverse element $a_1^{-1}$, so we have solution.
$$
x_1=-ra_1^{-1}$$
We have $p$ solutions for this equation.
Let's start with general solution right now.
$$
a_1x_1+a_2x_2+a_3x_3+\cdots+a_nx_n=0$$
Let's assume that $a_1\not =0$ (We could did it for any $a_i$) and let's assign any values for $x_2,x_3,x_4,\cdots x_n$ (We have $p^{n-1}$ possibilities). Then let's evaluate this expression. Result:
$$
a_1x_1+k=0\;\;\;\;\;\;k=a_2x_2'+a_3x_3'+\cdots+a_nx_n'
$$
Where $x_i'$ is assigned value. This equation has only one solution, so general equation has $p^{n-1}$ solutions, not $p^n-n$.
Is there any other way to find this value? On is my solution OK?
Thanks

Thanks @ancientmathematician I tried with rank-nullity theorem. Here is my result:
$A$ is linear transformation $A:\mathbb{F}_p^n\rightarrow\mathbb{F}_p$.
$$
A(x)=\sum_{i=1}^na_ix_i
$$
Domain of $A$ is whole $\mathbb{F}_p^n$, so
$$
\mathrm{dom}{A}=\mathbb{F}_p^n\;\Rightarrow\; \mathrm{dim}\,\mathrm{dom}{A}=n
$$
Image of $A$ is whole $\mathbb{F}_p$, so
$$
\mathrm{im}{A}=\mathbb{F}_p\;\Rightarrow\; \mathrm{dim}\,\mathrm{im}{A}=1
$$
From rank-nullity theorem
$$
\mathrm{dim}\,\mathrm{dom}{A}=\mathrm{dim}\,\mathrm{ker}{A}+\mathrm{dim}\,\mathrm{im}{A}
$$
i can figure out value of kernel dimension
$$
n=\mathrm{dim}\,\mathrm{ker}{A}+1\Rightarrow\mathrm{dim}\,\mathrm{ker}{A}=n-1
$$
Kernel of transformation is set of vectors which value is 0. So i understand i'm looking for $|\mathrm{ker}{A}|$. I'm not sure how to find amount of elements in kernel. Here is my try:
I know dimension of kernel and I know that kernel is linear space, so base of this set has $n-1$ elements. I can take any base so i'll take 'default'
$$
(1,0,0,\cdots,0)\;(0,1,0,\cdots,0)\;(0,0,1,\cdots,0)\cdots(0,0,0,\cdots,1)
$$
All vectors has $n-1$ coordinates. I can generate $p^{n-1}$ vectors basing on this set, so equation from begging of exercise has $p^{n-1}$ solutions.
Is that correct?
Comment: Use the rank-nullity theorem on the map $\mathbb{F}_{p}^{n}\to\mathbb{F}_p$ given by $\mathbf{x}\mapsto\mathbf{a\cdot x}$ (which is a non-zero map).


How does a Support Vector Machine (SVM) work?

Question: How does a Support Vector Machine (SVM) work, and what differentiates it from other linear classifiers, such as the Linear Perceptron, Linear Discriminant Analysis, or Logistic Regression? *
(* I'm thinking in terms of the underlying motivations for the algorithm, optimisation strategies, generalisation capabilities, and run-time complexity)
Comment: See also: http://stats.stackexchange.com/questions/3947/help-me-understand-support-vector-machines
Comment: see also http://stats.stackexchange.com/questions/80398/how-can-svm-find-an-infinite-feature-space-where-linear-separation-is-always-p/168309#168309
Answer: Support vector machines focus only on the points that are the most difficult to tell apart, whereas other classifiers pay attention to all of the points.
The intuition behind the support vector machine approach is that if a classifier is good at the most challenging comparisons (the points in B and A that are closest to each other in Figure 2), then the classifier will be even better at the easy comparisons (comparing points in B and A that are far away from each other).
Perceptrons and other classifiers:
Perceptrons are built by taking one point at a time and adjusting the dividing line accordingly. As soon as all of the points are separated, the perceptron algorithm stops. But it could stop anywhere. Figure 1 shows that there are a bunch of different dividing lines that separate the data. The perceptron's stopping criteria is simple: "separate the points and stop improving the line when you get 100% separation". The perceptron is not explicitly told to find the best separating line. Logistic regression and linear discriminant models are built similarly to perceptrons.
The best dividing line maximizes the distance between the B points closest to A and the A points closest to B. It's not necessary to look at all of the points to do this. In fact, incorporating feedback from points that are far away can bump the line a little too far, as seen below.

Support Vector Machines:
Unlike other classifiers, the support vector machine is explicitly told to find the best separating line. How? The support vector machine searches for the closest points (Figure 2), which it calls the "support vectors" (the name "support vector machine" is due to the fact that points are like vectors and that the best line "depends on" or is "supported by" the closest points).
Once it has found the closest points, the SVM draws a line connecting them (see the line labeled 'w' in Figure 2). It draws this connecting line by doing vector subtraction (point A - point B). The support vector machine then declares the best separating line to be the line that bisects -- and is perpendicular to -- the connecting line.
The support vector machine is better because when you get a new sample (new points), you will have already made a line that keeps B and A as far away from each other as possible, and so it is less likely that one will spillover across the line into the other's territory.

I consider myself a visual learner, and I struggled with the intuition behind support vector machines for a long time. The paper called Duality and Geometry in SVM Classifiers finally helped me see the light; that's where I got the images from.
Comment: +1 from another visual learner ! For the reader, I would like to note that these boundaries evident in the figure above is based on a data set that has been transformed already. Not the raw data set.
Comment: Reading svm for more then two years, today understood how seperation line is identified and few more things. Thanks for clean answer.
Answer: Ryan Zotti's answer explains the motivation behind the maximization of the decision boundaries, carlosdc's answer gives some similarities and differences with respect to other classifiers. I'll give in this answer a brief mathematical overview of how SVMs are trained and used.
Notations
In the following, scalars are denoted with italic lowercases (e.g., $y,\, b$), vectors with bold lowercases (e.g., $\mathbf{w},\, \mathbf{x}$), and matrices with italic uppercases (e.g., $W$). $\mathbf{w^T}$ is the transpose of $\mathbf{w}$, and $\|\mathbf{w}\| = \mathbf{w}^T\mathbf{w}$.
Let:

$\mathbf{x}$ be a feature vector (i.e., the input of the SVM). $\mathbf{x} \in \mathbb{R}^n$, where $n$ is the dimension of the feature vector.
$y$ be the class (i.e., the output of the SVM). $y \in \{ -1,1\}$, i.e. the classification task is binary.
$\mathbf{w}$ and $b$ be the parameters of the SVM: we need to learn them using the training set.
$(\mathbf{x}^{(i)}, y^{(i)})$ be the $i^ {\text {th}}$ sample in the dataset. Let's assume we have $N$ samples in the training set.

With $n=2$, one can represent the SVM's decision boundaries as follows:

The class $y$ is determined as follows:
$$
y^{(i)}=\left\{
                \begin{array}{ll}
                  -1 &\text{ if } \mathbf{w^T}\mathbf{x}^{(i)}+b \leq -1 \\
                  1 &\text{ if } \mathbf{w^T}\mathbf{x}^{(i)}+b \ge 1 \\
                \end{array}
              \right.
$$
which can be more concisely written as $y^{(i)} (\mathbf{w^T}\mathbf{x}^{(i)}+b) \ge 1$.
Goal
The SVM aims at satisfying two requirements:

The SVM should maximize the distance between the two decision boundaries. Mathematically, this means we want to maximize the distance between the hyperplane defined by $\mathbf{w^T}\mathbf{x}+b = -1$ and the hyperplane defined by $\mathbf{w^T}\mathbf{x}+b = 1$. This distance is equal to $\frac{2}{\|\mathbf{w}\|}$. This means we want to solve $\underset{\mathbf{w}}{\operatorname{max}} \frac{2}{\|\mathbf{w}\|}$. Equivalently we want
$\underset{\mathbf{w}}{\operatorname{min}} \frac{\|\mathbf{w}\|}{2}$.
The SVM should also correctly classify all $\mathbf{x}^{(i)}$, which means $y^{(i)} (\mathbf{w^T}\mathbf{x}^{(i)}+b) \ge 1, \forall i \in \{1,\dots,N\}$

Which leads us to the following quadratic optimization problem:
$$\begin{align}
\min_{\mathbf{w},b}\quad &\frac{\|\mathbf{w}\|}{2}, \\
s.t.\quad&y^{(i)} (\mathbf{w^T}\mathbf{x}^{(i)}+b) \ge 1 &\forall i \in \{1,\dots,N\}
\end{align}$$
This is the hard-margin SVM, as this quadratic optimization problem admits a solution iff the data is linearly separable.
One can relax the constraints by introducing so-called slack variables $\xi^{(i)}$. Note that each sample of the training set has its own slack variable. This gives us the following quadratic optimization problem:
$$\begin{align}
\min_{\mathbf{w},b}\quad &\frac{\|\mathbf{w}\|}{2}+ C \sum_{i=1}^{N} \xi^{(i)}, \\
s.t.\quad&y^{(i)} (\mathbf{w^T}\mathbf{x}^{(i)}+b) \ge 1 - \xi^{(i)},&\forall i \in \{1,\dots,N\} \\
\quad&\xi^{(i)}\ge0, &\forall i \in \{1,\dots,N\}
\end{align}$$
This is the soft-margin SVM. $C$ is a hyperparameter called penalty of the error term.
 (What is the influence of C in SVMs with linear kernel? and Which search range for determining SVM optimal parameters?).
One can add even more flexibility by introducing a function $\phi$ that maps the original feature space to a higher dimensional feature space. This allows non-linear decision boundaries. The quadratic optimization problem becomes:
$$\begin{align}
\min_{\mathbf{w},b}\quad &\frac{\|\mathbf{w}\|}{2}+ C \sum_{i=1}^{N} \xi^{(i)}, \\
s.t.\quad&y^{(i)} (\mathbf{w^T}\phi \left(\mathbf{x}^{(i)}\right)+b) \ge 1 - \xi^{(i)},&\forall i \in \{1,\dots,N\} \\
\quad&\xi^{(i)}\ge0, &\forall i \in \{1,\dots,N\}
\end{align}$$
Optimization
The quadratic optimization problem can be transformed into another optimization problem named the Lagrangian dual problem (the previous problem is called the primal):
$$\begin{align}
\max_{\mathbf{\alpha}}  \quad &\min_{\mathbf{w},b}  \frac{\|\mathbf{w}\|}{2}+ C \sum_{i=1}^{N} \alpha^{(i)} \left(1-\mathbf{w^T}\phi \left(\mathbf{x}^{(i)}\right)+b)\right), \\
s.t. \quad&0 \leq  \alpha^{(i)} \leq C, &\forall i \in \{1,\dots,N\}
\end{align}$$
This optimization problem can be simplified (by setting some gradients to $0$) to:
$$\begin{align}
\max_{\mathbf{\alpha}}  \quad & \sum_{i=1}^{N} \alpha^{(i)} - \sum_{i=1}^{N}\sum_{j=1}^{N}  \left( y^{(i)}\alpha^{(i)}\phi\left(\mathbf{x}^{(i)}\right)^T \phi\left(\mathbf{x}^{(j)}\right) y^{(j)}\alpha^{(j)} \right), \\
s.t. \quad&0 \leq  \alpha^{(i)} \leq C, &\forall i \in \{1,\dots,N\}
\end{align}$$
$\mathbf{w}$ doesn't appear as $\mathbf{w}=\sum_{i =1}^{N}\alpha^{(i)}y^{(i)}\phi\left(x^{(i)}\right)$ (as stated by the representer theorem).
We therefore learn the $\alpha^{(i)}$ using the $(\mathbf{x}^{(i)}, y^{(i)})$ of the training set.
(FYI: Why bother with the dual problem when fitting SVM? short answer: faster computation + allows to use the kernel trick, though there exist some good methods to train SVM in the primal e.g. see  {1})
Making a prediction
Once the $\alpha^{(i)}$ are learned, one can predict the class of a new sample with the feature vector $\mathbf{x}^{\text {test}}$ as follows:
\begin{align*}
y^{\text {test}}&=\text {sign}\left(\mathbf{w^T}\phi\left(\mathbf{x}^{\text {test}}\right)+b\right) \\
&= \text {sign}\left(\sum_{i =1}^{N}\alpha^{(i)}y^{(i)}\phi\left(x^{(i)}\right)^T\phi\left(\mathbf{x}^{\text {test}}\right)+b \right)
\end{align*}
The summation $\sum_{i =1}^{N}$ could seem overwhelming, since it means one has to sum over all the training samples, but the vast majority of $\alpha^{(i)}$ are $0$ (see Why are the Lagrange multipliers sparse for SVMs?) so in practice it isn't an issue. (note that one can construct special cases where all $\alpha^{{(i)}} > 0$.) $\alpha^{{(i)}}=0$ iff $x^{{(i)}}$ is a support vector. The illustration above has 3 support vectors.
Kernel trick
One can observe that the optimization problem uses the $\phi\left(\mathbf{x}^{(i)}\right)$ only in the inner product $\phi\left(\mathbf{x}^{(i)}\right)^T \phi\left(\mathbf{x}^{(j)}\right)$. The function that maps $\left(\mathbf{x}^{(i)},\mathbf{x}^{(j)}\right)$ to the inner product $\phi\left(\mathbf{x}^{(i)}\right)^T \phi\left(\mathbf{x}^{(j)}\right)$ is called a kernel, a.k.a. kernel function, often denoted by $k$.
One can choose $k$ so that the inner product is efficient to compute. This allows to use a potentially high feature space at a low computational cost. That is called the kernel trick. For a kernel function to be valid, i.e. usable with the kernel trick, it should satisfy two key properties. There exist many kernel functions to choose from. As a side note, the kernel trick may be applied to other machine learning models, in which case they are referred as kernelized.
Going further
Some interesting QAs on SVMs:

Best way to perform multiclass SVM
Support vector machines and regression
Understanding the different formulations for SVM
What's the difference between $\ell_1$-SVM, $\ell_2$-SVM and LS-SVM loss functions?
To deal with an unbalanced dataset:

Best way to handle unbalanced multiclass dataset with SVM
A priori selection of SVM class weights

How does one interpret SVM feature weights?
Interpretating the C value in a linear SVM
Generalization bounds on SVM
General formula for the VC Dimension of a SVM
What does the "machine" in "support vector machine" and "restricted Boltzmann machine" mean?
How are SVMs = Template Matching?
Single layer NeuralNetwork with ReLU activation equal to SVM?
Comparing SVM and logistic regression

Other links:

Least squares support vector machine

References:

{1} Chapelle, Olivier. "Training a support vector machine in the primal." Neural computation 19, no. 5 (2007): 1155-1178. https://scholar.google.com/scholar?cluster=469291847682573606&hl=en&as_sdt=0,22 ; http://www.chapelle.cc/olivier/pub/neco07.pdf
Comment: In addition to this great answer, I want to recommend this video which walks through the mathematics behind SVM and especially clarifies the question @tosik commented https://www.youtube.com/watch?v=_PwhiWxHK8o
Comment: Hi Franck, many thanks for your answer. Would you mind to explain why vector $w$ is orthogonal to the hyperplane that SVM generates? And how did you calculate the distance between two decision boundaries to be equal to $\frac{2}{\lVert w \rVert}$
Comment: Very nice answer. Just one remark as to this part: $\alpha^{{(i)}}=0$ iff $x^{{(i)}}$ is a **support vector**. For classification, the summation is effectively over support vectors (i.e., $\alpha^{{(i)}} \ge 0$).
Comment: That's the whole svm one hour class.
Comment: Is there a mistake? I thought $\alpha^{(i)} > 0$ for support vectors?
Comment: @Franck Please can you help here? thank you a lot https://stackoverflow.com/questions/65449934/multi-class-svm-one-vs-one-always-giving-the-same-label
Answer: The technique is predicated upon drawing a decision boundary line leaving as ample a margin to the first positive and negative examples as possible:

As in the illustration above, if we select an orthogonal vector such that $ \lVert w \rVert=1$ we can establish a decision criterion for any unknown example $\mathbf u$ to be catalogued as positive of the form:
$$ \color{blue}{\mathbf w}  \cdot {\mathbf u}  \geq C$$
corresponding to a value that would place the projection beyond the decision line in the middle of the street. Notice that $\color{blue}{\mathbf w}  \cdot {\mathbf u} = {\mathbf u} \cdot \color{blue}{\mathbf w}$.
An equivalent condition for a positive sample would be:
$$\color{blue}{\mathbf w}\cdot  \mathbf u + b \geq 0 \tag 1$$
with $C = - b.$
We need $b$ and $\color{blue}{\mathbf w}$ to have a decision rule, and to get there we need constraints.
First constraint we are going to impose is that for any positive sample $\mathbf x_+,$, $\color{blue}{\mathbf w}\cdot \mathbf x_+ + b \geq 1$; and for negative samples, $\color{blue}{\mathbf w}\cdot \mathbf x_- + b \leq -1$. In the division boundary or hyperplane (median) the value would be $0$, while the values at the gutters will be $1$ and $-1$:

The vector $\bf w$ is the weights vector, whereas $b$ is the bias.

To bring these two inequalities together, we can introduce the variable $y_i$ so that $y_i=+1$ for positive examples, and $y_i=-1$ if the examples are negative, and conclude
$$ y_i (x_i\cdot \color{blue}{\mathbf w} + b) -1\geq 0.$$
So we establish that this has to be greater than zero, but if the example is on the hyperplanes (the "gutters") that maximize the margin of separation between the decision hyperplane and the tips of the support vectors, in this case lines), then:
$$ y_i \,(x_i\cdot \color{blue}{\mathbf w} + b) -1 = 0\tag 2$$
Notice that this is equivalent to requiring that $y_i \,(x_i\cdot \color{blue}{\mathbf w} + b)  = 1.$

Second constraint: the distance of the decision hyperplane to the tips of the support vectors will be maximized. In other words the margin of separation ("street") will be maximized:

Assuming a unit vector perpendicular to the decision boundary, $\mathbf w$, the dot product with the difference between two "bordering" plus and minus examples is the width of "the street":
$$ \text{width}= (x_+ \,{\bf -}\, x_-) \cdot \frac{w}{\lVert w \rVert}$$
On the equation above $x_+$ and $x_-$ are in the gutter (on hyperplanes maximizing the separation). Therefore, for the positive example: $ ({\mathbf x_i}\cdot \color{blue}{\mathbf w} + b) -1 = 0$, or $ {\mathbf x_+}\cdot \color{blue}{\mathbf w} = 1 - b$; and for the negative example: $ {\mathbf x_-}\cdot \color{blue}{\mathbf w} = -1 - b$. So, reformulating the width of the street:
$$\begin{align}\text{width}&=(x_+ \,{\bf -}\, x_-) \cdot \frac{w}{\lVert w \rVert}\\[1.5ex]
&= \frac{x_+\cdot w \,{\bf -}\, x_-\cdot w}{\lVert w \rVert}\\[1.5ex]
&=\frac{1-b-(-1-b)}{\lVert w \rVert}\\[1.5ex]
&= \frac{2}{\lVert w \rVert}\tag 3 \end{align}$$
So now we just have to maximize the width of the street - i.e. maximize $ \frac{2}{\lVert w \rVert},$  minimize $\lVert w \rVert$, or minimize:
$$\frac{1}{2}\;\lVert w \rVert^2 \tag 4$$
which is mathematically convenient.

So we want to:

Minimise $\lVert w\rVert^2$ with the constraint:

$y_i(\mathbf w \cdot \mathbf x_i + b )-1=0$

Since we want to minimise this expression based on some constraints, we need a Lagrange multiplier (going back to equations 2 and 4):
$$ \mathscr{L} = \frac{1}{2} \lVert \mathbf w \rVert^2 - \sum \lambda_i \Big[y_i \, \left( \mathbf x_i\cdot \color{blue}{\mathbf w} + b \right) -1\Big]\tag 5$$
Differentiating,
$$ \frac{\partial \mathscr{L}}{\partial \color{blue}{\mathbf w} }= \color{blue}{\mathbf w} - \sum \lambda_i \; y_i \; \mathbf x_i = 0$$.
Therefore,
$$\color{blue}{\mathbf w} = \sum \lambda_i \; y_i \; \mathbf x_i\tag 6$$
And differentiating with respect to $b:$
$$ \frac{\partial \mathscr{L}}{\partial b}=-\sum \lambda_i y_i = 0,$$
which means that we have a zero sum product of multipliers and labels:
$$ \sum \lambda_i \, y_i = 0\tag 7$$
Pluging equation Eq (6) back into Eq (5),
$$ \mathscr{L} = \frac{1}{2} \color{purple}{\left(\sum \lambda_i y_i \mathbf x_i \right) \,\left(\sum \lambda_j y_j \mathbf x_j \right)}- \color{green}{\left(\sum \lambda_i y_i \mathbf x_i\right)\cdot \left(\sum \lambda_j y_j \mathbf x_j \right)} - \sum \lambda_i y_i b +\sum \lambda_i$$
The penultimate term is zero as per equation Eq (7).
Therefore,
$$ \mathscr{L} =  \sum \lambda_i - \frac{1}{2}\displaystyle \sum_i \sum_j  \lambda_i \lambda_j\,\, y_i y_j \,\, \mathbf x_i \cdot \mathbf x_j\tag 8$$
Eq (8) being the final Lagrangian.
Hence, the optimization depends on the dot product of pairs of examples.
Going back to the "decision rule" in Eq (1) above, and using Eq (6):
$$ \sum\; \lambda_i \; y_i \; \mathbf x_i\cdot \mathbf u + b \geq 0\tag 9$$
will be the final decision rule for a new vector $\mathbf u.$
Comment: @mike $b= y_s -\displaystyle \sum_{m\in S} \alpha_m y_m \mathbf{x}_m\cdot \mathbf {x}_s$ with $S$ being the set of indices of the support vectors $(\alpha_i > 0).$ You can find it [here](https://static1.squarespace.com/static/58851af9ebbd1a30e98fb283/t/58902fbae4fcb5398aeb7505/1485844411772/SVM+Explained.pdf).
Comment: @Niki $w$ is not a unit vector. It is $\frac w {\Vert w \Vert}$ that is unitary.
Comment: Nothing original... Just my own notes at a more entry level. Basically from [this video from MIT](https://www.youtube.com/watch?v=_PwhiWxHK8o&feature=youtu.be) with my own illustrations. For errors, please let me know. For insightful answers, and further details go to the expert level (Franck's post and others).
Comment: And how do I compute *b*?
Comment: @AntoniParellada amazing answer Antoni thanks a lot - but aren't you missing a part on the Dual problem and KTT conditions ?
Comment: @XavierBourretSicotte I won't be able to work on it for a while. Please consider writing an alternative answer touching on these issues, and if you do, please let me know so I am aware of it, and can upvote it.
Comment: @AntoniParellada sure - let me know what you think and feel free to correct / edit as I am not math graduate !
Comment: I'm a little confused. If $w$ is assumed to be a unit vector, then $\|w\| = 1$, but then the calculated width $\frac{2}{\|w\|} = 2$ and it would make little sense minimizing $\frac{1}{2} \|w\|^2 = \frac{1}{2}$. Can someone tell me where I went wrong?
Answer: I'm going to focus on the the similarities and differences it from other classifiers:

From a perceptron: SVM uses hinge loss and L2 regularization, the perceptron uses the perceptron loss and could use early stopping (or among other techniques) for regularization, there is really no regularization term in the perceptron. As it doesn't have an regularization term, the perceptron is bound to be overtrained, therefore the generalization capabilities can be arbitrarily bad. The optimization is done using stochastic gradient descent and is therefore very fast. On the positive side this paper shows that by doing early stopping with a slightly modified loss function the performance could be on par with an SVM.
From logistic regression: logistic regression uses logistic loss term and could use L1 or L2 regularization. You can think of logistic regression as the discriminative brother of the generative naive-Bayes.
From LDA: LDA can also be seen as a generative algorithm, it assumes that the probability density functions (p(x|y=0) and p(x|y=1) are normally distributed. This is ideal when the data is in fact normally distributed. It has however, the downside that "training" requires the inversion of a matrix that can be large (when you have many features). Under homocedasticity LDA becomes QDA which is Bayes optimal for normally distributed data. Meaning that if the assumptions are satisfied you really cannot do better than this.

At runtime (test time), once the model has been trained, the complexity of all
these methods is the same, it is just a dot product between the hyperplane the
training procedure found and the datapoint.
Comment: Since you seem very competent in SVM, let me ask you to clarify my doubt: once we found the best separating hyperplane, what do we use it for? We can define SVM as a method that, firstly, chooses the best hyperplane to correctly classify data points, and, secondly, it uses this hyperplane to sever new data points in the two classes. Right? (I've some doubts on the second part)
Comment: @DavideChicco.it Yes, we can use the indicator function to classify new data, which is often the main purpose of the classifier. (Don't take my word for any of this though, I'm new to all of it).
Answer: Some comments on Duality and KTT conditions
Primal problem
Picking up from @Antoni's post in between equations $(4)$ and $(5)$, recall that our original, or primal, optimization problem is of the form:
\begin{aligned}
 \min_{w, b} f(w,b) & = \min_{w, b}  \  \frac{1}{2} ||w||^2
 \\
 s.t. \ \  g_i(w,b) &= - y^{(i)} (w^T x^{(i)} + b) + 1 = 0
\end{aligned}
Lagrange method
The method of Lagrange multipliers allows us to turn a constrained optimization problem into an unconstrained one of the form:
$$\mathcal{L}(w, b, \alpha) =   \frac{1}{2} ||w||^2 - \sum_i^m \alpha_i [y^{(i)} (w^T x^{(i)} + b) - 1]$$
Where  $\mathcal{L}(w, b, \alpha)$ is called the Lagrangian and $\alpha_i$ are called the Lagrangian multipliers.
Our primal optimization problem with the Lagrangian becomes the following: (note that the use of $min$, $max$ is not the most rigorous as we should also be using $\inf$ and $\sup$ here...)
$$ \min_{w,b} \left( \max_\alpha \mathcal{L}(w, b, \alpha)\right)$$
Dual problem
What @Antoni and Prof. Patrick Winston have done in their derivation is assume that the optimization function and the constraints meet some technical conditions such that we can do the following:
$$ \min_{w,b} \left( \max_\alpha \mathcal{L}(w, b, \alpha)\right) =   \max_\alpha \left( \min_{w,b} \mathcal{L}(w, b, \alpha)\right)$$
This allows us to take the partial derivatives of $\mathcal{L}(w, b, \alpha)$ with respect to $w$ and $b$, equate to zero and then plug the results back into the original equation of the Lagrangian, hence generating an equivalent dual optimization problem of the form
\begin{aligned}
 &\max_{\alpha} \min_{w,b} \mathcal{L}(w,b,\alpha)
 \\
 & \max_{\alpha} \sum_i^m \alpha_i - \frac{1}{2} \sum_{i,j}^m y^{(i)}y^{(j)} \alpha_i \alpha_j <x^{(i)} x^{(j)}>
 \\
 & s.t. \ \alpha_i \geq 0
 \\
 & s.t. \ \sum_i^m \alpha_i y^{(i)} = 0
\end{aligned}
Duality and KTT
Without going into excessive mathematical technicalities, these conditions are a combination of the Duality and the Karush Kuhn Tucker (KTT) conditions and allow us to solve the dual problem instead of the primal one, while ensuring that the optimal solution is the same. In our case the conditions are the following:

The primal objective and inequality constraint functions must be convex
The equality constraint function must be affine
The constraints must be strictly feasible

Then there exists $w^*, \alpha^*$ which are solutions to the primal and dual problems. Moreover, the parameters $w^*, \alpha^*$ satisfy the KTT conditions below:
\begin{aligned}
 &\frac{\partial}{\partial w_i}  \mathcal{L}(w^*, \alpha^*, \beta^*) = 0 &(A)
 \\
 &\frac{\partial}{\partial \beta_i}  \mathcal{L}(w^*, \alpha^*, \beta^*) = 0 &(B)
 \\
 &\alpha_i^* g_i(w^*) = 0 &(C)
 \\
 &g_i(w^*) \leq 0  &(D)
 \\
 &\alpha_i^* \geq 0 &(E)
\end{aligned}
Moreover, if some $w^*, \alpha^*$ satisfy the KTT solutions then they are also solution to the primal and dual problem.
Equation $(C)$ above is of particular importance and is called the dual complementarity condition. It implies that if $\alpha_i^* > 0$ then $g_i(w^*) = 0$ which means that the constraint $g_i(w) \leq 0$ is active, i.e. it holds with equality rather than inequality. This is the explanation behind equation $(2)$ in Antoni's derivation where the inequality constraint is turned into an equality constraint.
A intuitive but informal diagram

Sources

Andrew Ng 1 and 2
MIT
Comment: Thank you very much. I read it quickly, and get back to it later with more time, but it sounds great, and touches on missing points in my answer.


Why is git not trusting a trusted cert?

Question: My git server is Gitlab and it's locally (private) hosted and it has a trusted cert from comodo that browsers trust without issue.
If I'm in a situation that I need to use HTTPS instead of SSH (From an Ubuntu 16 box in this case), then I always have to bypass SSL verification by using http.sslVerify=false on my git commands.
If I don't disable the verification, then I get:
fatal: unable to access 'https://gitlab.mysite.cloud/myrepo/somerepo.git/': server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
I feel like I've pulled down from other git servers using HTTPS without having to do anything special so I'm not sure what's up in this case.
From my workstation, I use SSH so I never run into this, but I just tested HTTPS from my Mac workstation and I get the same message.
Does anyone know why git is not trusting my trusted cert?
Comment: I think this thread has some suggestions: https://stackoverflow.com/questions/7814423/ssl-works-with-browser-wget-and-curl-but-fails-with-git
Answer: I needed to inject my intermediary certs. I used https://certificatechain.io/ to easily perform this.
It can also be done manually by concatenating the certs together to form the chain, but the above tool does it quick and easy.
After the chain was installed as the new cert, it's showing as fully trusted.
Answer: To check if at least the clone works without checking said certificate, you can set:
export GIT_SSL_NO_VERIFY=1
#or
git config --global http.sslverify false

Why is git not trusting a trusted cert?


What are the general solutions of the Diophantine equation $ ax+by+cxy+d=0 $

Question: Does the diophantine equation $$ ax+by+cxy+d=0 $$ always have solutions ?
Comment: It depends on $a,b,c,d$. For example, if $a=b=c=2$ and $d=3$, there is no solution (otherwise you would have $2(x+y+xy+1)+1=0$).
Comment: @Crostul is there a general study of this equation ?
Comment: I don't think so. Why are you interested in this equation? Usually "interesting" equations have more indeterminates than parameters.
Answer: I assume $c \ne 0$.  Write the equation as
$$ (cx + b) (cy + a) = ab - cd $$
So there are integer solutions iff you can factor $ab - cd$ into factors congruent to $a$ and $b$ mod $c$.
Comment: Thank you very much for this handy trick @Robert :) It was useful for my case $-10^5x-10^5y+xy=0$


Install drivers on Windows Server using dism while online

Question: We're in the process of migrating Windows Server virtual machines between cloud infrastructure.  In certain circumstances (HyperV Gen2 UEFI) servers, the system will fail to boot unless we install the storage driver ready for post migration boot up.
While this works when doing it offline using (eg the disk attached to another server and injecting the driver) :
<code>dism /image:C:\ /add-driver /driver:E:\win7\amd64\viostor.inf
</code>
To streamline the process we would like to install the driver while the machine is online.  Unfortunately dism is requiring the disk to be offline, returning the error "This command can only be used with an offline image".
We have tried pnputil to install the driver but this does not work, we believe this is because pnputil is for plugged in hardware with no driver currently.
Is there a way to install a driver into an online image?
Answer:
Copy the driver data to the online system
Right Click on the ".INF" file
Select "Install"
Comment: Can you tell i'm a Linux sysadmin  :)
Comment: How do you do this for hundreds of inf files without each one one at a time?
Comment: https://stackoverflow.com/questions/40179884/adding-inf-drivers-using-powershell-possible


not syncing: VFS: Unable to mount root fs on unknown—block(0,0)

Question: My VPS machine refuses to boot. There is an short error according to KVM console:
Kernel panic — not syncing: VFS: Unable to mount root fs on unknown—block(0,0)
Pid: 1, comm: swapper Not tainted 2.6.32-431.11.2.el6.x86_64 #1

I can boot only with rescue mode (it's online VPS machine). I tried to follow similar topics but with no result.
Screen shot of full console errors down below:

Please let me know if I missed some extra info to resolve this problem.
This is CentOS 7, before my machine crashed (suddenly just hang up) I put those commands
vim /etc/sysconfig/selinux
SELINUX=disabled

(Which is already enabled again - no result)
systemctl enable iptables
systemctl start iptables
iptables -F

Followed by:
iptables -t nat -A POSTROUTING -s 192.168.200.024 -o eth0 -j MASQUERADE

And then my machine hangs up for good.
Answer: After connecting through rescue mode and doing chroot command (more or less like this: https://community.rackspace.com/products/f/25/t/69) I was able to launch
Yum update kernel

I'm pretty sure that was Grub2 fault because I was missing on one file from kernel in /boot/.
My server is up and running, but httpd service is still dead.
Thanks anyway community, greetings.
Answer: It could be your /boot drive is full and you need to delete old kernels to free up space. There is an article how to do it in Ubuntu here https://jasoncoltrin.com/?p=1710
Or pretty much you need to boot into advanced boot loader, boot with an older kernel, and then remove the old kernels.
Comment: your link doesn't work
Comment: sorry here you go https://jasoncoltrin.com/2017/01/13/fix-ubuntu-when-the-os-will-not-boot-kernel-panic-kernel-panic-not-syncing-vfs-unable-to-mount-root-fs-on-unknown-block-0-0-error-boot-full-remove-old-kernels-from-command-line/


Decoding JSON input in PHP

Question: <?php
$json = file_get_contents('http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=XXXXX&api_key=XXXX&format=json');
$track_data = json_decode($json);

    foreach ($track_data as $data)
    {
        if (!empty($data)) {
            $text = $data->recenttracks->track->artist->mbid;
        }
        echo ''; echo $text; echo '';
    }
?>

This is the code I'm trying to use. The problem is: nothing shows up... What's wrong with it? :) Here's the JSON input (the content of the URL on file_get_contents): http://pastebin.com/NLHGMapT
Answer: Track is an array:
$text = $data->recenttracks->track[0]->artist->mbid;

also, when you're in the foreach loop you don't need to use recenttracks:
$text = $data->track[0]->artist->mbid;

Comment: Thanks! It works! How can I get - for instance - 10 results? Now I only get the first object as output.
Comment: foreach($track_data as $data) { echo $data->track[0]->artist->mbid }

Decoding JSON input in PHP


When choosing to mail-enable multiple AD objects at the same time from within the EMC, which format is chosen for the alias of each object?

Question: When choosing to mailbox-enable an existing object within Active Directory in the Exchange Management Console (by right-clicking "Recipient Configuration", choosing "New Mailbox" and then selecting the "Existing User" radio button), it's possible to search for multiple users within the forrest to be added which then appear in the list of objects to enable. Unlike when a single object is selected, however, when clicking the "Next" button the EMC doesn't offer the option of choosing aliases for these objects and simply displays the window with the "New" button that creates the mailboxes for these objects. In this case, does EMC automatically set the alias for these objects to be the username of each object in question - or is another format used?
Answer: Based on your description, I tested in my exchange 2010, I created 2 users in AD, screenshot below:
And I mail-enabled these 2 users in EMC, it shows:
Check the alias of these 2 users, it shows user logon names.


Conditionally assign value to an object of class `sf` and `data.frame`

Question: I have a map of Mexico and a data.frame with 300 weather stations. I drew 10km buffers around each station using st_buffer. The buffers are stored in buffers and the map is stored in mex.
I plotted the map and the buffers. My goal is to assign the station number of a given buffer to all the polygons that are touched by that buffer.

The map can be downloaded from this site. The CRS has to be changed from 5332 to 4326 first.
These are the first two buffers:
> dput(buffers[1:2, ])
structure(list(station_number = 1004:1005, station_alt = c(1925,
1844), month = c(9L, 9L), Mean_min = c(11.6, 12.75), Mean_max = c(26.9333333333333,
26.85), months_observed = c(5L, 5L), geometry = structure(list(
    structure(list(structure(c(-102.193501864824, -102.188739639421,
    -102.184005627476, -102.179312845387, -102.174674195097,
    -102.170102428304, -102.165610111091, -102.161209589104,
    -102.156912953352, -102.15273200674, -102.14867823144, -102.144762757164,
    -102.14099633046, -102.137389285095, -102.133951513622, -102.130692440198,
    -102.127620994743, -102.124745588492, -102.122074091026,
    -102.119613808832, -102.117371465453, -102.115353183273,
    -102.113564467008, -102.112010188909, -102.110694575746,
    -102.109621197594, -102.108792958435, -102.108212088624,
    -102.107880139208, -102.107797978126, -102.107965788291,
    -102.108383067551, -102.109048630528, -102.109960612321,
    -102.111116474066, -102.112513010319, -102.114146358253,
    -102.116012008624, -102.11810481849, -102.12041902562, -102.122948264575,
    -102.125685584399, -102.128623467869, -102.13175385226, -102.135068151548,
    -102.138557280014, -102.142211677156, -102.146021333863,
    -102.149975819769, -102.154064311712, -102.158275623224,
    -102.162598234981, -102.167020326114, -102.171529806314,
    -102.176114348636, -102.180761422931, -102.18545832979, -102.190192234944,
    -102.194950204009, -102.199719237488, -102.204486305951,
    -102.209238385282, -102.21396249192, -102.218645717996, -102.223275266261,
    -102.227838484744, -102.232322901016, -102.236716255998,
    -102.241006537204, -102.245182011349, -102.24923125622, -102.253143191741,
    -102.256907110134, -102.260512705114, -102.263950100018,
    -102.267209874814, -102.270283091899, -102.273161320625,
    -102.275836660488, -102.278301762903, -102.280549851515,
    -102.282574740994, -102.284370854233, -102.285933237938,
    -102.287257576532, -102.288340204344, -102.28917811605, -102.289768975321,
    -102.290111121663, -102.290203575419, -102.290046040907,
    -102.289638907696, -102.288983250005, -102.288080824209,
    -102.286934064475, -102.285546076523, -102.283920629526,
    -102.28206214616, -102.279975690846, -102.277666956193, -102.275142247682,
    -102.272408466631, -102.269473091493, -102.266344157511,
    -102.263030234815, -102.259540405001, -102.255884236252,
    -102.25207175709, -102.248113428804, -102.244020116654, -102.239803059918,
    -102.235473840866, -102.231044352758, -102.226526766947,
    -102.221933499182, -102.217277175214, -102.21257059579, -102.207826701155,
    -102.203058535141, -102.198279208964, -102.193501864824,
    22.0859192364704, 22.085534238459, 22.0849172382595, 22.0840699348155,
    22.0829946611303, 22.0816943777556, 22.0801726645306, 22.0784337105961,
    22.0764823027115, 22.0743238119113, 22.0719641785371, 22.069409895692,
    22.0666679911626, 22.0637460078641, 22.060651982863, 22.05739442504,
    22.0539822914556, 22.0504249624898, 22.0467322158238, 22.0429141993409,
    22.0389814030237, 22.034944629927, 22.0308149663093, 22.0266037510087,
    22.0223225441472, 22.0179830952551, 22.0135973109014, 22.0091772219229,
    22.0047349503427, 22.00028267607, 21.9958326034732, 21.9913969279179,
    21.9869878023627, 21.9826173041033, 21.9782974017556, 21.974039922567,
    21.9698565201456, 21.9657586426917, 21.9617575018195, 21.9578640420503,
    21.9540889110588, 21.950442430752, 21.9469345692567, 21.9435749138888,
    21.9403726451761, 21.9373365120024, 21.9344748079369, 21.9317953488116,
    21.9293054516035, 21.9270119146773, 21.9249209994388, 21.9230384134463,
    21.9213692950234, 21.9199181994126, 21.918689086505, 21.9176853101771,
    21.9169096092626, 21.9163641001814, 21.9160502712448, 21.9159689786515,
    21.9161204441842, 21.9165042546133, 21.9171193628082, 21.9179640905543,
    21.9190361330684, 21.9203325652003, 21.9218498493057, 21.9235838447705,
    21.9255298191611, 21.9276824609738, 21.9300358939496, 21.9325836929185,
    21.9353189011326, 21.9382340490429, 21.9413211744729, 21.9445718441351,
    21.947977176437, 21.951527865515, 21.9552142064358, 21.9590261214987,
    21.9629531875695, 21.9669846643751, 21.9711095236842, 21.9753164792958,
    21.9795940177575, 21.983930429731, 21.9883138419203, 21.9927322494785,
    21.9971735488044, 22.001625570641, 22.0060761133856, 22.0105129765217,
    22.0149239940793, 22.0192970680334, 22.0236202015486, 22.0278815319759,
    22.0320693635126, 22.0361721994319, 22.0401787737937, 22.0440780825465,
    22.0478594139329, 22.051512378113, 22.0550269359216, 22.0583934266765,
    22.0616025949599, 22.0646456162951, 22.0675141216445, 22.0702002206599,
    22.0726965236163, 22.0749961619661, 22.0770928074551, 22.0789806897431,
    22.080654612479, 22.0821099677832, 22.0833427490944, 22.0843495623444,
    22.0851276354261, 22.0856748259297, 22.0859896271218, 22.0860711721515,
    22.0859192364704), .Dim = c(121L, 2L))), class = c("XY",
    "POLYGON", "sfg")), structure(list(structure(c(-102.366703187571,
    -102.361953401998, -102.357231241862, -102.352549690896,
    -102.347921620104, -102.343359752058, -102.338876625611,
    -102.334484561146, -102.330195626451, -102.326021603316,
    -102.321973954954, -102.318063794337, -102.31430185353, -102.310698454116,
    -102.307263478792, -102.304006344217, -102.300935975184,
    -102.29806078019, -102.295388628469, -102.29292682855, -102.290682108398,
    -102.288660597189, -102.286867808771, -102.285308626848,
    -102.283987291923, -102.282907390044, -102.282071843364,
    -102.281482902546, -102.281142141029, -102.281050451163,
    -102.28120804222, -102.28161444028, -102.282268489991, -102.283168358188,
    -102.284311539362, -102.285694862952, -102.287314502445,
    -102.28916598624, -102.291244210262, -102.293543452269, -102.296057387819,
    -102.298779107849, -102.301701137812, -102.304815458326,
    -102.308113527261, -102.311586303219, -102.315224270331,
    -102.319017464311, -102.322955499685, -102.327027598133,
    -102.33122261786, -102.335529083924, -102.339935219426, -102.344428977502,
    -102.348998074013, -102.353630020852, -102.358312159789,
    -102.363031696755, -102.367775736476, -102.372531317382,
    -102.37728544667, -102.38202513547, -102.386737433981, -102.391409466519,
    -102.396028466363, -102.400581810326, -102.405057052946,
    -102.409441960217, -102.413724542767, -102.417893088403,
    -102.421936193923, -102.425842796126, -102.429602201935,
    -102.43320411754, -102.4366386765, -102.439896466719, -102.442968556219,
    -102.445846517653, -102.448522451477, -102.450989007725,
    -102.453239406319, -102.45526745587, -102.457067570893, -102.458634787414,
    -102.4599647769, -102.461053858482, -102.461899009434, -102.462497873866,
    -102.462848769613, -102.462950693293, -102.462803323512,
    -102.462407022203, -102.461762834097, -102.460872484312,
    -102.459738374072, -102.458363574556, -102.456751818886,
    -102.454907492285, -102.452835620412, -102.450541855915,
    -102.448032463222, -102.445314301624, -102.442394806679,
    -102.439281969997, -102.435984317449, -102.432510885871,
    -102.428871198315, -102.425075237915, -102.421133420455,
    -102.417056565692, -102.412855867531, -102.40854286313, -102.404129401022,
    -102.399627608343, -102.395049857261, -102.390408730704,
    -102.385716987477, -102.380987526877, -102.376233352903,
    -102.371467538159, -102.366703187571, 21.8658255348988, 21.8654500907327,
    21.8648428753359, 21.8640055607182, 21.8629404523928, 21.8616504829416,
    21.8601392038325, 21.8584107755117, 21.8564699558012, 21.8543220866349,
    21.8519730791717, 21.8494293973302, 21.8466980397919, 21.843786520526,
    21.8407028478924, 21.8374555023831, 21.8340534130662, 21.8305059328018,
    21.8268228122996, 21.8230141730931, 21.8190904795087, 21.8150625097083,
    21.8109413258889, 21.8067382437227, 21.8024648011255, 21.7981327264397,
    21.7937539061222, 21.7893403520278, 21.7849041683784, 21.7804575185102,
    21.7760125914911, 21.7715815686993, 21.7671765904566, 21.7628097228052,
    21.7584929245207, 21.7542380144494, 21.7500566392588, 21.7459602416876,
    21.7419600293812, 21.7380669443942, 21.7342916334436, 21.7306444189888,
    21.7271352712172, 21.7237737810075, 21.7205691339423, 21.7175300854374,
    21.7146649370543, 21.7119815140545, 21.7094871442571, 21.7071886382512,
    21.7050922710163, 21.7032037649975, 21.7015282746776, 21.7000703726872,
    21.698834037488, 21.697822642659, 21.697038947816, 21.6964850911841,
    21.6961625838445, 21.6960723056696, 21.6962145029558, 21.6965887877606,
    21.6971941389471, 21.69802890493, 21.6990908081196, 21.7003769510501,
    21.7018838241781, 21.70360731533, 21.7055427207767, 21.7076847579041,
    21.7100275794504, 21.7125647892714, 21.7152894595944, 21.7181941497166,
    21.7212709260998, 21.7245113838088, 21.7279066692395, 21.7314475040767,
    21.7351242104195, 21.7389267370089, 21.7428446864898, 21.7468673436336,
    21.7509837044501, 21.7551825061087, 21.7594522575916, 21.7637812709972,
    21.7681576934083, 21.7725695392421, 21.7770047229928, 21.7814510922792,
    21.7858964611076, 21.790328643259, 21.7947354857098, 21.799104901993,
    21.8034249054097, 21.8076836419976, 21.811869423165, 21.8159707579007,
    21.8199763844667, 21.8238753014886, 21.8276567983526, 21.8313104848251,
    21.8348263198099, 21.8381946391619, 21.8414061824772, 21.844452118783,
    21.8473240710538, 21.8500141394829, 21.8525149234429, 21.8548195420695,
    21.8569216534119, 21.8588154720916, 21.8604957854188, 21.861957967921,
    21.8631979942385, 21.8642124503512, 21.8649985431035, 21.8655541079981,
    21.8658776152377, 21.8659681739947, 21.8658255348988), .Dim = c(121L,
    2L))), class = c("XY", "POLYGON", "sfg"))), class = c("sfc_POLYGON",
"sfc"), precision = 0, bbox = structure(c(xmin = -102.462950693293,
ymin = 21.6960723056696, xmax = -102.107797978126, ymax = 22.0860711721515
), class = "bbox"), crs = structure(list(epsg = 4326L, proj4string = "+proj=longlat +datum=WGS84 +no_defs"), class = "crs"), n_empty = 0L)), sf_column = "geometry", agr = structure(c(station_number = NA_integer_,
station_alt = NA_integer_, month = NA_integer_, Mean_min = NA_integer_,
Mean_max = NA_integer_, months_observed = NA_integer_), .Label = c("constant",
"aggregate", "identity"), class = "factor"), row.names = 1:2, class = c("sf",
"data.frame"))

I want to write a for loop that assigns the station_number to all the the polygons touched by buffer number i, then i + 1, etc... i.e. Assign station number 100 to all the polygons touched by staion 100's buffer.
To do this, I tried:
mex$station_number <- 0
for (i in 1:300) {
  mex[buffers[i, ], ]$station_number <- buffers[i, ]$station_number
}

However, running the loop (or even a named case) returns:
Error in Ops.sfc(left, right) : operation >= not supported

I expected this to do the following: The polygons touched by the ith buffer will be assigned the ith's station number.
I read that it was a problem with the $ in another forum. I tried escaping it using \ and \\ but it didn't work.
Comment: Try `st_join(mex, buffers)` when they have the same projection.
Comment: It's hard to help without a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). There are example datasets that ship with `sf` that you could use here
Comment: @camille thanks. I updated the question to display my actual data. I didn't do so initially because I thought it was a matter of syntax in my loop. The example should now be reproducible. You only have to set the CRS of the map from 5332 to 4326 using `st_set_crs(mex, 5332)` and `st_transform(mex, 4326)`.
Comment: @TimSalabim that did the trick. Thanks!
Answer: As pointed out by @TimSalabim, this can be done with st_join():
install.packages("lwgeom") # required when st_join(..., largest = TRUE)
mex <- st_join(x = mex, y = buffers, left = FALSE, largest = TRUE)

In fact, this solution is much more accurate than the loop I was writing because of the argument largest. The documentations states:

largest
logical; if TRUE, return x features augmented with the fields
of y that have the largest overlap with each of the features of x

So basically, this leaves me with the buffer that has the largest intersection over a given polygon.


HTML elements only show after i reload page?

Question: I have this javascript code that inserts a label into an existing html page. However, it only shows when i reload the page. Like if i visit the page it doesn't show. once im at the page and reload, it then shows. How do i fix it so it shows right when i visit the page?
$(document).ready(function () {
    insertlabel();
});

function insertlabel() {
    var $label = $('test');
    //place them on the page
    $('.div1').after($label);
}

Comment: please show the html as well
Comment: it would be easier to seek help if you include your markup and post it on jsfiddle or inside SO itself
Answer: I'm not sure if it makes a difference, but I always define my functions inside $(document).ready();
   $(document).ready(function () {
    function insertlabel() {
        var $label = 'test';
        $('.div1').after($label);
    }

        insertlabel();

    });


sns matplotlib output slicing the saved image

Question: I am trying to save sns matplotlib output as jpg file and reopen it with cv2.
but i am facing distinct data loss, would someone help me to resolve, i tried in several savefig options and documentations.
sample code
import pandas as pd
import numpy as np
import cv2
import seaborn as sns
import matplotlib.pyplot as plt
by_c = None

fig = plt.Figure(figsize=(5, 4), dpi=100)
g = sns.FacetGrid(pd.DataFrame(np.random.random(10)*150, columns=['col']), col=None,  row=None, height=3.5, aspect=1)
g.map_dataframe(sns.histplot, x='col')
plt.title('col'+' - '+str(by_c)+'-', fontsize=12)
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.savefig('temp.png')
plt.show()

Out:

Saved picture example of 'temp.png'

out:
reopening image
im = cv2.imread('temp.png')
plt.imshow(im)

Out1:
Image title and lables sliced bit, i am not sure how else i can save it. Would someone please help to resolve it
Comment: to rule out problems in cv2: can you post temp.png in the question as well?
Comment: ok. super. I think you can remove cv2 from the question altogether then...
Comment: @LudvigH, Thanks for support , link really shown exact ans, seems i might not checked properly
Comment: Actually, temp.png is also same @LudvigH, i tried to open it, opencv is simply opening what is saved :-|
Answer: To set the quality of the image use the dpi, and also specify the bbox_inches for a full layout. If not, it will consider the nearest view of the image
import pandas as pd
import numpy as np
import cv2
import seaborn as sns
import matplotlib.pyplot as plt
by_c = None

fig = plt.Figure(figsize=(5, 4), dpi=100)
g = sns.FacetGrid(pd.DataFrame(np.random.random(10)*150, columns=['col']), col=None,  row=None, height=3.5, aspect=1)
g.map_dataframe(sns.histplot, x='col')
plt.title('col'+' - '+str(by_c)+'-', fontsize=12)
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.savefig('temp.png',dpi=300, bbox_inches = "tight")
#plt.savefig('temp.png')
plt.show()

im = cv2.imread('temp.png')
plt.imshow(im)

Resultant Image:
Comment: Thanks for the answer @Roxy, it solved the problem :)
Comment: this sure should fix the issue. but we should try to flag duplicates rather than answering them.

also - please tidy code in answers so they are actually good code samples. (e.g. remove unnecessary cv2 dependency
Comment: Thanks for the update. Done as said. :)
Comment: If it resolves, could you accept it as an answer maybe?


mouseenter mouseleave events conflict ? jquery

Question: I am trying to animate my navigation menu with the help of jquery.
for this purpose, i have written the following code.
html

one

two

three

jquery
    $safed_text = "";

    $('.inactive').on('mouseenter',function(){
        $safed_text = $(this).text();
        $(this).css("font-size", "0.7em");
        $(this).text("comming soon...");
        $(this).css("display", "none");
        $(this).fadeIn("slow");
    });

    $('.inactive').on('mouseleave',function(){
        $(this).css("font-size", "1em");
        $(this).text($safed_text);

    });

the code works for the most part as expected i.e. changing the text of the two last elements when hovered over with the mouse.
However, if one hovers over the two of them to quickly, the text doesnt change as expected and no text is displayed.
Why is this happening ? What kind of workarounds are there ?
Thank you.
https://jsfiddle.net/dtkbf5r8/
Comment: It's working fine. (you didn't include jquery) https://jsfiddle.net/dtkbf5r8/1/
Comment: This is hepnning because you applied both $(this).css("display", "none");
        $(this).fadeIn("slow"); please use one of them
Comment: sorry i forgot to include the jquery in jsfiddle, but no that is not the problem. Once you hover back and forth over one of the last two elements you will notice what i am refering to.
Comment: What us the use of these two lines, your requirement is simple on hover text should change and on leave it should again change?
Comment: Thanks Yogesh Sharma for pointing out the problem. I somehow had in my mind i had to hide the text first before i can fade it in. - this solved the problem.
Comment: happy to hear it's working!!
Answer: Check below solution, there is no need of display:none if your requirement is to show coming soon text on hover and same text as earlier on mouse leave. -

  $safed_text = "";

    $('.inactive').on('mouseenter',function(){
        $safed_text = $(this).text();
        $(this).css("font-size", "0.7em");
        $(this).text("comming soon...");
        //$(this).css("display", "none");
        $(this).fadeIn("slow");
    });

    $('.inactive').on('mouseleave',function(){
        $(this).css("font-size", "1em");
        $(this).text($safed_text);

    });

one

two

three

Answer: Used to .hover jQuery
Bind one or two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements
as like this

$( ".inactive" ).hover(
  function() {
            safed_text = $(this).text();
            $(this).css("font-size", "0.7em");
            $(this).text("comming soon...");
            $(this).fadeIn("slow");
  }, function() {
            $(this).css("font-size", "1em");
            $(this).text(safed_text);
  }
);
nav{
 width:100%;
}

nav ul{
    margin:0;
    padding:0;
    list-style-type:none;
    text-align:center;
    /*border: 1px solid black;*/
    background: #F1F0D1
}

nav ul li{
 display:inline-block;
/* border: 1px solid #878E63; */
 width: 15%;
}
nav ul li a{
 text-decoration: none;
}

nav ul li a p{
 background: #F1F0D1;
 display: block;
 padding: 5% 12%;
 font-weight: bold;
 font-size: 1em;
 color: #878E63;
 text-decoration: none;
 text-align: center;
}

nav ul li a p:hover{
 background-color: #878E63;
 color: #F1F0D1;
}

nueng

dos

drei

Comment: this is very nice as well. I had read before that hover was deprecated but now that i checked the API that turned out to be false. i have to say its a bit hard to read, if one doesnt know that the first function is for mouseenter and the second one for mouseleave.


Where does Solaris 10 keep a log of pfexec attempts?

Question: I assigned a user the "User Security" profile so that they could reset user passwords and unlock accounts.
Does Solaris keep a record of whenever users execute pfexec?
I didn't see any records in /var/adm/messages. I didn't see anything in the audit logs using praudit <audit_log_file> | grep pfexec.
Answer: Found it logged under audit class as. Then using:
auditreduce -c as <audit_log_file> | praudit | grep "profile command"


Updating column with IF Statement MYSQL

Question: This may be completely impossible in pure MYSQL, but hopefully someone can shed some light.
Basially I am trying to create a schedule that will do a test on a table and update a new table with either Cleared OR Uncleared.
Here is a snapshot of table - testpieces
TEST_NO RING ROUTE  TYPE_NO
7256    BT1 TSTS    390397
7257    BT1 TCRT    390397
7258    BT1 TCRT    390397
7259    BT1 TCRT    390397
7260    BT1 TCRT    390397
7261    BT1 TCRT    390397
7262    BT1 TCRT    390397
7263    BT1 TCRT    390397
7264    BT1 TCRT    390397
7265    BT1 TCRT    390397
7266    BT1 TCRT    390397
7267    BT1 TCRT    390418
7268    BT1 TCRT    390418
7269    BT1 TCRT    390418
7270    BT1 TCRT    390418
7271    BT1 TCRT    390418
7272    BT1 TCRT    390418
7273    BT1 TCRT    390418
7274    BT1 TCRT    390418
7275    BT1 TCRT    390418
7276    BT1 TCRT    390418
7277    BT1 TCRT    390418

What I am trying to achieve is to do a check on all ROUTE values for each TYPE_NO and if all values of ROUTE are TCRT then this would be true, or if one single value was TSTS and the rest were TCRT then this would be false.
From table 1 you can see that TYPE_NO 390397 is uncleared because not all ROUTE values are TCRT, one is still TSTS. The second type_no 390418 has a ROUTE of all TCRT, this means that Type_no is cleared.
So, I need to update another table called TypeCleared, and have results like the following..
TYPE_NO   TYPE_CLEARED
390397    UNCLEARED
390418    CLEARED

So lets say TypeCleared table has a column full of single Type_no and the Type_Cleared field is blank.
I tried the following -
 UPDATE TYPECLEARED SET TYPECLEARED.TYPE_CLEARED = "CLEARED" WHERE TYPECLEARED.TYPE_NO = TESTPIECES.TYPE_NO AND ROUTE = "TCRT" ;

   UPDATE TYPECLEARED SET TYPECLEARED.TYPE_CLEARED = "UNCLEARED" WHERE TYPECLEARED.TYPE_NO = TESTPIECES.TYPE_NO AND ROUTE NOT IN ("TCRT");

This sql made the table look like this
 TYPE_NO   TYPE_CLEARED
 390397    UNCLEARED
 390397    CLEARED
 390418    CLEARED

So having failed this way, I thought is there some type of way to create an IF Else statement using user-defined variables.
SET @PIECES =  (SELECT count(test_no) from live_testpiec group by TYPE_NO);

SET @ROUTE =  (SELECT count(ROUTE) from live_testpiec WHERE ROUTING_POS = 'TCRT' group by TYPE_NO);

With the variables I can do an evaluation, if @PIECES = @ROUTE then update that TYPE_NO as Cleared, else Uncleared.
Although, when I try to set these variables, i get the following error -
Subquery returns more than 1 row

Meaning I can't use group by on the type_no, but this is absolutely crucial to evaluate every group of TYPE_NO.
Is there any other way in doing what I am trying to achieve.. hope this makes sense!
Any questions please ask
Answer: http://sqlfiddle.com/#!9/f4af8/2
UPDATE TypeCleared
INNER JOIN (
 SELECT TYPE_NO, SUM(IF(ROUTE='TSTS',1,0)) as criteria
 FROM testpieces
 GROUP BY TYPE_NO
 ) t
ON  TypeCleared.TYPE_NO = t.TYPE_NO
SET TYPE_CLEARED = IF(t.criteria=0,'CLEARED','UNCLEARED')

Updating column with IF Statement MYSQL


A Cauchy Transform characterization for certain analytic functions on the upper plane

Question: I'm trying to prove the following proposition taken from [Bercovici, Hari & Voiculescu, Dan] Free Convolution of Measures with Unbounded Support paper (Section 5, Prop. 5.1). Before enunciate the proposition let's define the $Upper\,cone$ with $\alpha>0$ width as
$$
\Gamma_\alpha=
\Big\{z\in\mathbb{C}\,:\,Im(z)>0\quad\text{&}\quad|Re(z)|<\alpha\,Im(z)\Big\}.
$$
And recall the Cauchy transform given a probability measure $\mu$ on $\mathbb{R}$ being
$$
G_\mu(z)=\int_\mathbb{R}\,\frac{1}{z-t}\,d\,\mu(t),\quad\forall z\notin\mathbb{R}.
$$

Proposition 5.1: Let $G:\mathbb{C}^+\to\mathbb{C}^-$ be an analytic function. Then the following assertions are equivalent.
  $$
(i)\,\text{There exists a probability measure}\,\mu\text{ on }\mathbb{R}\text{ such that }G_\mu=G\,\text{ in }\,\mathbb{C}^+
$$
  $$
(ii)\,\text{For each }\alpha>0 \text{ we have }\lim_{|z|\to\infty,\,\,z\in\Gamma_\alpha}zG(z)=1
$$
  $$
(iii)\text{ We have }
\lim_{y\to\infty}iyG(iy)=1
$$

I have already proved $(i)\Rightarrow\,(ii)\Rightarrow(iii)$. I got stucked trying $(iii)\Rightarrow(i)$.
First I define $\tilde{G}=-G$. So $\tilde{G}:\mathbb{C^+}\to\mathbb{C^+}$ and is still analytic. Next I'm using a representation for Nevanlinna functions that says that for every analytic function $f:\mathbb{C}^+\to\mathbb{C^+}$ we have the following representation
$$
f(z)=az+b+\int_\mathbb{R}\,\frac{1+uz}{u-z}\,d\tau(u)\quad\forall z\in\mathbb{C^+},
$$
where $a>0,b\in\mathbb{R}$ are constants and $\tau(u)\in BV(\mathbb{R})$ is non-decreasing. So, since $\tilde{G}$ happens to be a Nevanlinna function we get that
$$
G(z)=-az-b+\int_\mathbb{R}\,\frac{1+uz}{z-u}\,d\,\tau(u)\quad z\in\mathbb{C^+}.
$$
Now I'm supposed to give a probability measure on $\mathbb{R}$, which I'm trying by denoting $d\mu(t)$ specifically, where a $d\tau(u)$ is involved. I have tried a series of variable changes trying $-az-b+\int_\mathbb{R}\,\frac{1+uz}{z-u}\,d\,\tau(u)=G_\mu(z)$ to hold, but haven't succeeded yet. Another thing I'm also missing is how $(iii)$ could help, since I've already examine $iyG(iy)$ and seems to doesn't give something clear about finding a probability measure. Any help would be appreciated.
UPDATE:
Found that
$$
\frac{1}{u-z}-\frac{u}{1+u^2}=\frac{1+uz}{(u-z)(1+u^2)}
$$
so
$$
\Big(\frac{1}{u-z}-\frac{u}{1+u^2}\Big)(1+u^2)=\frac{1+uz}{(u-z)}
$$
so
$$
\int_\mathbb{R}\frac{1+uz}{(u-z)}\,d\,\tau (u)
=
\int_\mathbb{R}\Big(\frac{1}{u-z}-\frac{u}{1+u^2}\Big)(1+u^2)\,d\,\tau (u)
$$
So it seems that $d\mu(u)=(1+u^2)\,d\,\tau (u)$ should be the probability measure I'm looking for. In this way
$$
G(z)=-az-b+G_\mu (z)-\int_\mathbb{R}\,u\,d\,\tau (u)
$$
So now it suffices to show that $az+b+\int_\mathbb{R}\,u\,d\tau (u)=0$, which happens iff $a=0$ and $b=-\int_\mathbb{R}\,u\,d\tau (u)$. So now I think here is where the fact that $iyG(iy)\to 1$ helps. What do you think? Any help would be appreciated.
Comment: I've also tried with $\tilde{G}=\frac{1}{G}$ and $\tilde{G}=\overline{G(\overline{z})}$, but same results.
Comment: What is $BV(\mathbb{R})$ ? What do we need for $\tau$ being (up to a constant) a probability measure ?
Comment: $BV(\mathbb{R})$ stands for the set of real-valued functions of bounded variation over $\mathbb{R}$. A real-valued function $f$ is said to be of bounded variation over a set $S$ iff $$\sup_{P\in\mathcal{P}}\,\sum_{i=0}^{n-1}|f(x_{i+1})-f(x_i)|<\infty.$$ Where $\mathcal{P}$ stands for the set of all partitions of $S$.
Answer: I got it. First
$$
iyG(iy)=iy\Big(-iay-b+\int_\mathbb{R}\frac{1}{iy-u}d\mu(u)-\int_\mathbb{R}ud\tau(u)\Big)
$$
$$
=iy\Big(-iay-b+\int_\mathbb{R}\frac{u}{y^2+u^2}d\mu(u)+i\int_\mathbb{R}\frac{y}{y^2+u^2}d\mu(u)-\int_\mathbb{R}ud\tau(u)\Big)
$$
$$
=ay^2-iby+i\int_\mathbb{R}\frac{yu}{y^2+u^2}d\mu(u)-\int_\mathbb{R}\frac{y^2}{y^2+u^2}d\mu(u)-i\int_\mathbb{R}yu\,d\tau(u)
$$
$$
=A+iB,
$$
where
$$
A_y=y^2\Big(a-\int_\mathbb{R}\frac{1}{y^2+u^2}\,d\tau(u)\Big)
$$
$$
B_y=-y\Big(b+\int_\mathbb{R}u\,d\tau(u)-\int_\mathbb{R}\frac{u}{y^2+u^2}\,d\tau(u)\Big).
$$
And since $|iyG(iy)|$ is bounded for all $y\ge 0$, so do are $|A_y|,|B_y|$, for all $y\ge 0$. Thus
$$
\lim_{y\to\infty}\frac{1}{|y|^2}\,|A_y|=0
$$
$$
\lim_{y\to\infty}\frac{1}{|y|}\,|B_y|=0
$$
iff
$$
a-\lim_{y\to\infty}\frac{1}{y^2}\int_\mathbb{R}\frac{1}{1+(u/y)^2}\,d\tau(u)=0
$$
$$
b+\int_\mathbb{R}\,u\,d\tau(u)-\lim_{y\to\infty}\frac{1}{y^2}\int_\mathbb{R}\frac{u}{1+(u/y)^2}\,d\tau(u)=0,
$$
where $\frac{u}{1+(u/y)^2}$ and $\frac{1}{1+(u/y)^2}$ are bounded, thus dominated, for every $y\ge 0$, so
$$
\lim_{y\to\infty}\frac{1}{y^2}\int_\mathbb{R}\frac{u}{1+(u/y)^2}\,d\tau(u)=0
$$
$$
\lim_{y\to\infty}\frac{1}{y^2}\int_\mathbb{R}\frac{1}{1+(u/y)^2}\,d\tau(u)=0.
$$
Thereby $a=0$ and $b=-\int_\mathbb{R}\,u\,d\tau(u)$. So $G(z)=G_\mu(z)$, for all $z\in\mathbb{C}^+$.
That $\mu(u)$ is a probability measure follows from the fact that $\lim_{y\to\infty}|iyG(iy)|=1$, because
$$
\lim_{y\to\infty}|iyG(iy)|=1
$$
iff
$$
\lim_{y\to\infty}\Big|-\int_\mathbb{R}\frac{1}{1+(u/y)^2}\,d\mu(u)+i\frac{1}{y}\int_\mathbb{R}\frac{u}{1+(u/y)^2}\,d\mu(u)\Big|=1
$$
iff
$$
\lim_{y\to\infty}\int_\mathbb{R}\frac{1}{1+(u/y)^2}\,d\mu(u)
+
\lim_{y\to\infty}\frac{1}{y}\int_\mathbb{R}\frac{u}{1+(u/y)^2}\,d\mu(u)
=1
$$
iff
$$
\int_\mathbb{R}\,d\mu(u)=1
$$


Find an isomorphism between $C[0,1]$ and a proper subspace of itself

Question: Let $E=C[0,1]$, the vector space of all continuous functions defined on $[0,1]$, equipped with the sup norm. Find an isomorphism between $E$ and a proper subspace of $E$.
Comment: What's $C[0,1]$ here -- continuous functions supported over $[0,1]$?
Comment: yes C[0,1] is the continuous functions over [0,1]
Answer: Let $A$ be the subspace of $C[0,1]$ for which funcions are constant on $[\frac{1}{2},1]$. I think that the map $\phi\colon C([0,1])\to A$ defined by $\phi(f)(x)=f(\frac{x}{2})$ if $x\in[0,\frac{1}{2})$ and $\phi(f)(x)=f(1)$ if $x\in [\frac{1}{2},1]$ should work.
Comment: Your function is not an isomorphism as it is not injective. For instance let $c_0$ denote the constant 0 function. Then $\phi(0) = \phi(\sin)$.
Comment: Ups sorry, I forgot it shoud be an isomorphism. I'll edit it and write an isomorphism.


Heroku failed to connect using Jenkins

Question: I have an application currently deployed to Heroku that I'm trying to connect to Jenkins but I'm getting this error
ERROR: Error fetching remote repo 'Heroku'
hudson.plugins.git.GitException: Failed to fetch from https://git.heroku.com/myApp.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:862)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1129)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1160)
    at hudson.scm.SCM.checkout(SCM.java:495)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1276)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:560)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:485)
    at hudson.model.Run.execute(Run.java:1735)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:405)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress https://git.heroku.com/myApp.git +refs/heads/*:refs/remotes/Heroku/*" returned status code 128:
stdout:
stderr: remote: !   WARNING:
remote: !   Do not authenticate with username and password using git.
remote: !   Run `heroku login` to update your credentials, then retry the git command.
remote: !   See documentation for details: https://devcenter.heroku.com/articles/git#http-git-authentication
fatal: Authentication failed for 'https://git.heroku.com/myApp.git/'

I've run heroku login and when I run heroku apps --all it lists all of my current apps and my username, confirming a successful login
Answer: It depends on which login/local account your Jenkins is running.
If it is not running with the same account, it would not benefit from your successful heroku login command.
Comment: I'm sorry I think I'm lost. How can I see which Heroku account my Jenkins is linked to?
Comment: @Naji This is not about the heroku account, but about the local user account used for running Jenkins itself. Unless everything is running on an AWS instance, as I realize reading your deleted question https://stackoverflow.com/q/48123800/6309
Comment: oh yes I remember now, Jenkins creates a local user account... do you know how I go about accessing that in AWS? Or where you can direct me to find out?
Comment: @Naji Actually, why not create a first job whose only step is to do an heroku login: that would persists the login for the local Jenkins account. Then your other job might succeed.
Comment: If you're not busy, would you start a chat with me?
Comment: Sure let me add some comment in order to trigger the chat notification
Comment: Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/162645/discussion-between-vonc-and-naji).

Heroku failed to connect using Jenkins


Discuss compactness of the set of $L^2$ bounded functions

Question:
Discuss weak and strong compactness of the following subsets of $L^2(0,1)$:
$A=\{u\in L^2(0,1):||u||_{L^2}\le1\}.$

I know some theorems which might be helpful, but I don't know if I applied them correctly.
The set $A$ is a closed unit ball of the Banach space $L^2(0,1)$, which is an infinite dimensional normed space, so by Riesz theorem $A$ is not strongly compact. Moreover, since $L^2(0,1)$ is reflexive, by Banach-Alaoglu theorem its closed unit ball $A$ is weakly compact.
Is this correct?
Comment: Riesz' lemma does the job, but for Hilbert spaces it's even simpler. Just take any orthonormal sequence $(e_n)$. Since $\| e_n-e_m\|=1$ for $n\neq m$, it can't have a convergent subsequence.
Comment: You can, although I don't like it that much. An orthonormal basis incuces an isomorphism $L^2(0,1)\to\ell^2$. On bounded subsets of $\ell^2$, weak convergence is equivalent to pointwise convergence (since finitely supported sequences are dense in $\ell^2$). To extract a pointwise convergent subsequence is elementary, just apply the usual diagonal argument.
Comment: Well, in this case $n=1$. You will also need the Poincaré's inequality to control the $L^2$ norm in terms of the $L^2$ norm of the derivative.
Comment: @MaoWao very good example thank you, so thats prove that the set is not strongly compact, what about weak compact? Can you use the orthonormal sequence in this case too?
Answer: Concerning point A, you solved it correctly via "abstract nonsense". However, I think that it is always better to use concrete examples when possible.
In this case, a concrete example of a sequence contained in $A$ that has no converging subsequences is
$$
f_n(x)=\sqrt n f(nx), $$
where $f$ is any nonzero element of $A$.

Here I omitted an important piece of information.
  The function $f$ is defined on $[0, 1]$, but we implicitly consider that $$f(x)=0,\qquad \text{if }x\notin [0,1].$$
  In particular, for all $x\ne 0$, it holds that $nx>1$ for all sufficiently large $n$, and so $f(nx)=0$ eventually. Therefore
  $$
\lim_{n\to \infty} f_n(x)= 0,$$
  and so $f_n\to 0$ pointwise almost everywhere.

Now the change of variable formula for integrals yields $$\tag{1}\|f_n\|_{L^2}=\|f\|_{L^2},\qquad \forall n\ge 1;$$
so $f_n\in A$ for all $n$. Now suppose for a contradiction that there exists $g\in L^2$ and a subsequence $f_{k_n}$ such that $$\|f_{k(n)}-g\|_{L^2}\to 0.$$
By (1), it must be that $\|g\|_{L^2}=\|f\|_{L^2}\ne 0$; thus, $$g\ne 0.$$ However, any sequence that converges in $L^2$ has a subsequence that converges pointwise almost everywhere, so there exists a sub-sub-sequence $f_{k(h(n))}$ such that
$$
f_{k(h(n))}\to g,\qquad \text{almost everywhere.}$$
And this is a contradiction, for $f_{k(h(n))}\to 0$ almost everywhere by the remark in the colored box, and so it would imply that $g=0$.
Comment: @soundwave: That contradicts the very definition of compactness.
Comment: @soundwave: I really think you should try harder; these are questions with an immediate answer. Think about equation (1).
Comment: @soundwave: Fair enough, that's a rightful question and I'll answer it with a edit.
Comment: @soundwave: No. I truly mean what I wrote, I double-checked.
Comment: I wrote it. If the argument of $f$ is outside $[0, 1]$ then $f$ vanishes.
Comment: Thank you, could you explain what's consequence of having a bounded sequence contained in $A$ that has no converging subsequences?
Comment: Ok thankjs, and why if the limit of $f_n$ is $0$ pointwise, it cannot exist a subsequence with limit $0$ too?
Comment: From (1) i get that $||f_n-f||_{L^2}=0\ \forall n$, so $f_n\to f$? But then you said that pointwise limit of $f_n$ is $0$ and I dont understand why.
Comment: Thank i'm reading, in the box did you mean "In particular, for all $x\notin [0,1]$, it holds that" ?
Comment: Ah, could you please write the computation of the limit? I'm really confused, take $x=n^{-1/2}$, then $f_n(x)=\sqrt{n}f(\sqrt{n})$. As $n$ goes to infinity $f$ goes to $0$ as fast as $\sqrt{n}$ goes to infinity, so who win?
Comment: Ok, but why the limit is $0$ for all $x\ne0$? What about $x\in(0,1)?$