MVC pattern: which is better? For views or controllers to create and reference the other?

Question: We are making a rather large Swing application which has to implement the MVC pattern.
The application currently looks like this:

There are quite a few views. They are created in a hierarchical manner where one main view contains (and creates)
 several views which all contain their own set of sub-views, etc. Each of these views retrieve information from the model
independently from the other views, by calling the models static methods when necessary.
There are also quite a few controllers which are all totally separated from each other. Each controller
belongs to a view. Each view creates its own controller, and adds the controller as a listener to user input.
The controllers receive events from the views and then modify the model through the models static methods.
When the views dispatch events which do not affect the model, but only affect
the views, the views take care of these events themselves - without informing the controllers about the events.
That is, the controllers are totally unaware of the views, and the controllers purpose is only taking care of the manipulation of the model.
|EDIT: the controllers are currently attachments to their views; they only contain logic for event-handling. That is, the controllers are not components themselves, and do not contain components. They are implemented in the same manner as the following example: MVC example |
The model in the application is very passive, and does not even have listeners (it represents a database).
It receives updates from the controllers.

In this example, the views own the controllers. Would it be better in the general case if the controllers owned and created the views, and if one let the views be unaware of the controllers, instead of the opposite? In that case, why?
How would this be designed? If not, is there a better design in which the controllers are still unaware of the views? Or perhaps, is the best design neither of them?
EDIT:
As stated in the Original MVC definition:
the line "The View takes responsibility for establishing this intercommunication..."
seems to indicate that the view creates the controller, or at least has the initial reference to the controller, and not vice versa.
So this is at least a possible way to do it (it is a valid MVC pattern), but the main question remains; which is better, and how would the best design look like?
Especially when dealing with many controllers that are closely related to their respecive
views?
EDIT: Another example of a view which references a controller: Oracles example
Answer: As seen in this outline, the controller has the model and the view(s). Any sub-views are managed by the respective parent view. Sub-views may forward events to the parent as discussed here. There's a simple example here with more links.
Comment: Ok, so I assume the design would look like the following:
All controllers are created in some main class.
All controllers are added as listeners to the main view.
The subviews would call parent.stateChanged(e);
to forward the events. The main view would fire event changes and would use an EventListenerList
(should the main view implement some interface?).
The controllers would ignore the received events which didn't concern
them (important: how would they know what to ignore?). Is this it? Thanks
Comment: No, the controller often listens to the view(s) and the view(s) always listen to the model. This [game](http://robotchase.sourceforge.net/) shows multiple views listening to one model. As discussed [here](http://stackoverflow.com/questions/3066590/gui-problem-after-rewriting-to-mvc/3072979#3072979), the actual observer mechanism is an implementation detail; several approaches are mentioned there. You may want to define your own `ApplicationEvent` analogous to `AWTEvent`.
Comment: @trashgod _No, the controller often listens to the view(s) and the view(s) always listen to the model._. Sorry, but I don't see the difference between this and what I suggested in my previous comment? Do you mean that (as opposed to what I wrote) there should be only one controller?
Comment: Ah, I misunderstood; you're right about controller(s) listening to view(s). I've never needed more than one application controller; it may be nothing more than a panel of components, each having its own model and view, that affect the application model. If you need more than one controller, you might look at [`Action`](http://download.oracle.com/javase/tutorial/uiswing/misc/action.html) "to separate functionality and state from a component."
Comment: @Trashgod in this application, as it is now, the controllers are not panels or extending or using any swing components. The controllers only contain the logic for manipulating the model. They receive events from their respective view, and behave accordingly. This is because the GUI has no clear distinction (in terms of panels or sections) of what parts are controls and not. So the controllers only act as event-handlers for the actions from the GUI which affect the model. If we placed all the controls in one controller, this one would become huge.
Comment: @trashgod ...continued... Also, since the respective controls are currently coupled with their views, this whole change would decrease the apps cohesion, wouldn't you say? Is the used pattern not a "real" MVC pattern perhaps?
Comment: @trashgod the same way that this examples controller is implemented, that is. [MVC example](http://www.leepoint.net/notes-java/GUI/structure/40mvc.html)
Comment: I think we are in agreement. Indeed, the [outline](http://stackoverflow.com/questions/2687345/java-mvc-how-to-divide-a-done-text-game-into-mvc/2687871#2687871) that I cited above was actually based on the [diagram](http://www.oracle.com/technetwork/articles/javase/index-142890.html) linked from the article you cited. In words, a controller _has-a_ view to which it listens. I agree that there can be more than one controller, as you have described them.
Comment: @trashgod the article with the diagram really helped me! =) And also the article linked from that article: the original MVC definition [Original MVC definition](http://st-www.cs.illinois.edu/users/smarch/st-docs/mvc.html). Still, I am not sure how your design would look like for the case with many controllers? How would the controllers know which events to ignore? More importantly, why is it better, as you suggested, for the controllers to own the views and not the opposite?
Comment: A controller _has-a_ view is how I interpret the solid arrows representing association in the [diagram](http://en.wikipedia.org/wiki/Model-view-controller). A controller invokes a view's methods, not the converse. One versus many controllers is probably an implementation detail; either way works. The important thing is the loose coupling afforded by the observer pattern, represented by the dotted lines.
Comment: @trashgod There are also different variations to the MVC model; like the one in [the link you posted](http://www.oracle.com/technetwork/articles/javase/index-142890.html):  `public PropertiesViewPanel(DefaultController controller) {

        this.controller = controller;
`. Here the view clearly has a reference to the controller. But the question is: which is better, why, and what does the best design look like? Why is your suggestion better than the one in the question? Hope I'm not being a pain =)
Comment: Not at all, but I'm not sure there's definitive answer. Better designers than I have wrestled with the problem. I see MVC more as a guiding principle than a formula. In the [example](http://www.leepoint.net/notes-java/GUI/structure/40mvc.html), the model is created and then passed to the `CalcView` constructor. Instantiation of the model without reference to a view is one test of the model's independence. That instantiation can be in the view; sorry if seemed to suggest otherwise. [Swing itself](http://java.sun.com/products/jfc/tsc/articles/architecture/#separable) is a good example.


How to extract and manipulate data within a Nifi processor

Question: I'm trying to write a custom Nifi processor which will take in the contents of the incoming flow file, perform some math operations on it, then write the results into an outgoing flow file. Is there a way to dump the contents of the incoming flow file into a string or something? I've been searching for a while now and it doesn't seem that simple. If anyone could point me toward a good tutorial that deals with doing something like that it would be greatly appreciated.
Comment: maybe better to start from ExecuteScript, or ExecuteGroovyScript processor. Groovy is based on java - should be easy. As example of processor take the source of any simple processor like this: [EncodeContent.java](https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EncodeContent.java)
Answer: The Apache NiFi Developer Guide documents the process of creating a custom processor very well. In your specific case, I would start with the Component Lifecycle section and the Enrich/Modify Content pattern. Any other processor which does similar work (like ReplaceText or Base64EncodeContent) would be good examples to learn from; all of the source code is available on GitHub.
Essentially you need to implement the <code>#onTrigger()</code> method in your processor class, read the flowfile content and parse it into your expected format, perform your operations, and then re-populate the resulting flowfile content. Your source code will look something like this:
<code>    @Override
    public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
        FlowFile flowFile = session.get();
        if (flowFile == null) {
            return;
        }

        final ComponentLog logger = getLogger();
        AtomicBoolean error = new AtomicBoolean();
        AtomicReference<String> result = new AtomicReference<>(null);

        // This uses a lambda function in place of a callback for InputStreamCallback#process()
        processSession.read(flowFile, in -> {
            long start = System.nanoTime();

            // Read the flowfile content into a String
            // TODO: May need to buffer this if the content is large
            try {
                final String contents = IOUtils.toString(in, StandardCharsets.UTF_8);
                result.set(new MyMathOperationService().performSomeOperation(contents));

                long stop = System.nanoTime();
                if (getLogger().isDebugEnabled()) {
                    final long durationNanos = stop - start;
                    DecimalFormat df = new DecimalFormat("#.###");
                    getLogger().debug("Performed operation in " + durationNanos + " nanoseconds (" + df.format(durationNanos / 1_000_000_000.0) + " seconds).");
                }
            } catch (Exception e) {
                error.set(true);
                getLogger().error(e.getMessage() + " Routing to failure.", e);
            }
        });

        if (error.get()) {
            processSession.transfer(flowFile, REL_FAILURE);
        } else {
            // Again, a lambda takes the place of the OutputStreamCallback#process()
            FlowFile updatedFlowFile = session.write(flowFile, (in, out) -> {
                final String resultString = result.get();
                final byte[] resultBytes = resultString.getBytes(StandardCharsets.UTF_8);

                // TODO: This can use a while loop for performance
                out.write(resultBytes, 0, resultBytes.length);
                out.flush();
            });
            processSession.transfer(updatedFlowFile, REL_SUCCESS);
        }
    }
</code>
Daggett is right that the ExecuteScript processor is a good place to start because it will shorten the development lifecycle (no building NARs, deploying, and restarting NiFi to use it) and when you have the correct behavior, you can easily copy/paste into the generated skeleton and deploy it once.
Comment: The Developer Guide was originally written before Java 8 was supported (or even existed) and lambdas were available. The more verbose behavior is still valid, and can illustrate what is happening for developers unfamiliar with lambdas as well. The documentation is treated as code, and community improvements are always welcomed.
Comment: I'm curious why the Nifi developer guide uses the OutputStreamCallback.process() function, if it can be replaced by a lambda? Is there a reason or a case where the lambda cannot be used?


EmEditor Auto-deploy all settings

Question: I have created a Windows 10 Export (to reg file) of my optimal EmEditor set-up for my team.
Is there a silent way from command line (equivalent of Tools - Import and Export - Import all settings from a registry file) to deploy to all users in a batch file/script using EmEditor and command line switches?
Currently using v20.1 and users do not have admin rights on their machines. Would like to be able to deploy this silently moving forwards (via logon script if possible).
Answer: I wrote a batch file that you can run in Command Prompt.
If you save this file as EEImportReg.bat, and if the EmEditor settings have been exported to C:\ExportedFolder (where exported.reg file exists), you will run this as:
EEImportReg.bat "C:\ExportedFolder"
I would recommend running this batch file before you run EmEditor.
@echo off
if not exist "%1\exported.reg" (
    echo "%1\exported.reg" does not exist.
    exit /b
)
reg.exe import "%1\exported.reg"
xcopy "%1\AppData" "%appdata%\Emurasoft\EmEditor" /s /y /q

EmEditor Auto-deploy all settings


Solving a time dynamic system of differential equations

Question: I have the following system with a starting point  $x(t_0)$
$$
\dot x =
\begin{pmatrix}
\frac{1}{t +1} & 0 \\
1 & \frac{1}{t +1}
\end{pmatrix}
\cdot x
$$
I wrote the equations as follows:
$$
\dot x_1 = \frac{1}{t +1}x_1 \implies x_1(t) = x_1(t_0)\cdot \frac{t+1}{t_0 +1} \\
\dot x_2 = \frac{x_2(t)}{t+1} + x_1(t)
$$
from there I solved for the case x1 = 0
$$
\dot x_{2_h} = \frac{x_2}{t+1} \implies x_{2_h} = x_2(t_0) \cdot \frac{t+1}{t_0 +1}
$$
Now I got stuck. I looked up the solution and saw that the general solution $ x_{2}$
is calculated as follows:
$$ x_2(t) = \frac{t+1}{t_0+1}x_2(t_0) + \int_{t_0}^t \frac{t+1}{\tau + 1}x_1(\tau)d\tau$$
which means that the particular solution is calculated:
$$
x_{2_p} = \int_{t_0}^t \frac{t+1}{\tau + 1}x_1(\tau)d\tau
$$
I don't understand why the particular solution is calculated like that. maybe some steps are missing?
I would appreciate very much an explanation.
thank you for your time!
Answer: $\dot x_2 = \frac{x_2(t)}{t+1} + x_1(t)$ can be rewritten
$$\left(\frac{x_2}{t+1}\right)'(t)=\frac{x_1(t)}{t+1},$$
whence that strange solution:
$$\frac{x_2(t)}{t+1}-\frac{x_2(t_0)}{t_0+1}=\int_{t_0}^t\frac{x_1(\tau)}{\tau+1}d\tau.$$
Note however that:

since $\frac{x_1(t)}{t+1}=\dot x_1(t),$ this expression can be simplified:
$$\frac{x_2(t)}{t+1}-\frac{x_2(t_0)}{t_0+1}=x_1(t)-x_1(t_0);$$
a more usual way to solve for $x_2$ would be to set $x_2(t)=(t+1)C(t),$ and solve for $C:$
$$\dot x_2 = \frac{x_2(t)}{t+1} + x_1(t)\iff((t+1)C(t))'= \frac{(t+1)C(t)}{t+1} + x_1(t)$$$$\iff (t+1)C'(t)+C(t)=C(t)+ x_1(t)\iff\dots.$$


Chart.js com Angular usando o ng-include. Gráficos não aparecem

Question: Olá.
No meu index.html tenho isto

no graficost.html tenho isto:

Line graphSessions

Settings 1

Settings 2

                <canvas id="lineChart"></canvas>

no body do index.html declaro o chart.js e o grafico.js (onde crio os graficos) assim:

quando chamo a index.html, renderiza a página graficos.html chamada pelo ng-include mas me aparece este erro no console do Chrome:

Chart.min.js:13 Uncaught TypeError: Cannot read property 'length' of null

Por isso não mostra os graficos que estão no graficos.js
Comment: Verifique como está o escopo na sua aplicação.
Como você está injetando o controller? Ng-Controller ou pelas Rotas?

Qual é o código que trabalha com seu canvas?
Comment: Acredito que não é um problema no controller, pois a página graficos.html que estou chamando no ng-include, é exibida, porem os gráficos feitos em JS, não.
Comment: A falta dele vai fazer com que os dados não sejam passados. Ele incluiu com ng-include porque achou o arquivo no caminho informado.
Comment: Verdade... coloquei o ng-controller na pagina que veio por include e fiz o module e controller no grafico.js.. Obrigado!
Comment: Ok, vou colocar como resposta aqui.
Answer: Verifique como está o escopo na sua aplicação.
Veja onde o controller está injetado, se não estiver injetado corretamente o canvas não vai buscar os dados.
Use ng-controller dentro do ng-include ou mesmo dentro do arquivo incluído ou use as rotas para injetá-lo.


Como fazer pra toda vez que passar "true", ele imprimir o objeto instanciado inteiro?

Question: import java.util.ArrayList;

public class Loja {

    private ArrayList<Produto> ListaDeProdutos = new ArrayList<>();

    public void cadastrarProduto(Produto produto){
        ListaDeProdutos.add(produto);
    }

    public void listarProdutos(){
        ListaDeProdutos.forEach(P -> System.out.println(P.toString() + "\n"));
    }

    public void listarDiscos(){
        ListaDeProdutos.forEach(P -> System.out.println(P.toString().contains("Banda")));
        //eu quero que ele imprima todo o conteúdo setado, não apenas "true"
    }
}

Teste
public class Teste {
    public static void main(String[] args) {
        Loja l1 = new Loja();
        l1.cadastrarProduto(new Livro("Java - Use A cabeça", 01, 120.00f, "Fulano de tal", "DevMasters", 400, "PROGRAMAÇÃO"));
        l1.cadastrarProduto(new Livro("LIVRO DE C", 02, 80.00f, "Deitel", "Dev Masters", 800, "PROGRAMAÇÃO"));
        l1.cadastrarProduto(new Livro("PYTHON", 03, 100.00f, "Lokão dazideia", "Dev Masters", 200, "PROGRAMAÇÃO"));
        l1.cadastrarProduto(new Disco("Back in Black", 04, 100.00f, "AC/DC", "Hard Rock", 15));
        l1.cadastrarProduto(new Disco("Sattelite", 05, 20.00f, "P.O.D.", "White Metal", 11));
        l1.cadastrarProduto(new Disco("Musashi", 06, 15.00f, "Rashid", "Rap", 14));
        l1.listarDiscos();
    }
}

Saída
false
false
false
true
true
true

Answer: A pergunta não dá muitos detalhes, mas seria algo assim:
for (Produto produto : ListaDeProdutos ) {
    if (produto.nome.contains("Banda")) {
        System.out.println(produto.nome);
        System.out.println(produto.preco);
        System.out.println(produto.genero);
    }
}

Coloquei no GitHub para referência futura.
Achei melhor fazer. O uso de stream pode parecer bonitinho, mas é mais lento, tem semântica diferente do laço normal, embora nesse exemplo não cause problemas, mas tem uma série de implicações que quase ninguém entende e o normal é causar problemas, sendo que quase sempre não há ganho real a não ser, em alguns casos, deixar um código com menos linhas, o que nem sempre é bom. Nesse caso isto nem ocorreria de fato, então é pura perda de tempo.
Também não use o tostring() para isso, não faz o menor sentido criar algo de lógica geral para atender um requisito específico. É um abuso usá-lo para formatar dados, pior ainda mandar um função de depuração ser usado com complexidade O(n).
Na verdade aí pode ter um erro conceitual. Não sei se Loja deveria imprimir alguma coisa, ela processar é ok, imprimir já é um detalhe de plataforma onde roda e talvez deveria ser manipulado em outro lugar. Para exercício pode fazer assim, mas saiba que em código real não é assim que se faz.
Comment: Como eu fiz....
Comment: Desculpa pela falta de detalhe, foi a pressa. Mas acha que falta eu descrever mais?
Comment: Eu poderia ter dado uma resposta melhor se tivesse mais informação.
Comment: Sua resposta foi excelente. Desculpa pela inexperiência.
Comment: `public void listarDiscos(){
     for (Produto produto : ListaDeProdutos ) {
         if (produto.toString().contains("Banda")) {
             System.out.println(produto.toString());
         }

     }
    }`
Comment: consegui adaptar ao meu problema e deu certo. :)
Comment: Não deu certo, funcionou, certo é outra coisa, você está abusando do `ToString()`: https://pt.stackoverflow.com/q/212754/101
Comment: Verdade. Como eu poderia fazer então?
Answer: O método contains retorna um boolean, por isso o código só imprime true ou false. Se quer imprimir os produtos que satisfazem uma condição, pode fazer um for simples como sugeriu o Maniero.
Outra opção é transformar a lista em um stream e usar filter para filtrar os produtos que satisfazem a sua condição e em seguida imprimi-los:
ListaDeProdutos.stream()
    // filtrar produtos
    .filter(p -> p.toString().contains("Banda"))
    // imprimir
    .forEach(System.out::println);

Mas se você quer filtrar os produtos por um tipo específico (no caso, Disco), poderia usar instanceof para testar se o produto é uma instância de Disco:
ListaDeProdutos.stream()
    // filtrar produtos que são Disco
    .filter(p -> p instanceof Disco)
    // imprimir
    .forEach(System.out::println);

Comment: @EmersonAraujo neste caso está abusando do `toString()` e de *streams*.
Comment: @EmersonAraujo De fato, o melhor é usar atributos da classe (como o nome, tipo, etc) para verificar o que ela representa, em vez de `toString()`. Outra dica é ler as [convenções de código](https://www.oracle.com/technetwork/articles/javaee/codeconventions-135099.html) - nomes de variáveis, por exemplo, devem começam com letra minúscula, então seria melhor ter `listaDeProdutos` (com `l` minúsculo). Com `L` maiúsculo fica parecendo nome de classe e pode confundir outros já acostumados com tais convenções - veja mais em https://pt.stackoverflow.com/q/153540/112052
Comment: Era exatamente o que eu queria. Muito obrigado. Assim eu não abuso do `toString()`
Comment: eu ainda estou começado a entender sobre **POO** e **Java**, desculpe se eu estou errando muito.
Comment: Vou ler sim, obrigado pelas dicas.


Knockout JS with Mappings recursive templating

Question: I'm using knockout JS with the mappings plugin:
https://github.com/SteveSanderson/knockout.mapping/tree/master/build/output
It seems I'm unable to access data.
Here is a working example with pure knockout and pure JSON:
http://jsfiddle.net/u0hv6wxe/2/
And here is a broken example with knockout and mappings not rendering anything:
http://jsfiddle.net/95zztzkq/1/
The reason I'm using the mappings is to prevent creating a model with thousands of properties coming from ajax.
Docs on the plugin:
http://knockoutjs.com/documentation/plugins-mapping.html
The JS:
var initialData = {
    '@type': 'type1',
    'contents': [
        {
            '@type' : 'type2',
            'stringx': 'test'
        },
        {
            '@type' : 'type2',
            'stringx': 'test2'
        }
    ]
};
defaultData = ko.mapping.fromJS(initialData);
ko.applyBindings(defaultData);
console.log(defaultData['@type']());
console.log(defaultData.contents()[0]['@type']());
console.log(defaultData.contents()[1]['@type']());

The Templates:

I've been stuck for 2 days on this issue, all help is greatly appreciated!
Thanks :)
Comment: use  `()` while reading a value in view . it will fix the issue working fiddle here http://jsfiddle.net/95zztzkq/4/ .
Comment: @supercool Just came to the same conclusion myself - it's the lack of parentheses when accessing an observable in an expression that seems to be causing the problem here.  I'd post that up as the answer
Comment: @JamesThorpe yes issue is a small one . humm i posted as answer :) cheers
Answer: While checking conditions in view we need to read a observable value using () which will fix the issue
View :

working fiddle here
Comment: Worth noting that it's only because you're accessing an observable in a complex expression, ie `if: $data['@type']()=='type1'`.  If it was an observable that returned a boolean accessed by itself, you can choose to either have or not have the brackets, eg `if: $data['bool']` or `if: $data['bool']()` would both work.
Comment: yes agreed in that case . As for note sake when comparing with some other value either in view/viewModel we tend to use `()` #someUsefulInfo for later


vmware disk becomes read-only on linux guest

Question: I have Linux CentOS as guest OS on VMWare Workstation, the host is Windows Home.
The Disk becomes read-only, every-time i untar a huge file (which results in hundreds of small files) somewhere in the file system on the VM.
What could be causing this?
Is it because the linux vm guest sees a very huge number of files getting created quickly (as a result of the untar ), and it cannot keep up for some reason and then switches to Read-Only?
I can replicate this issue every-time.
What could be done to solve this.
Comment: What VMware product are you using?  You've tagged this with both server and workstation?
Comment: Shane> I'v corrected the tags. The product is VMware-workstation.
Comment: This can be caused by a know bug,  file systems may become read-only after encountering busy I/O retry or SAN or iSCSI path failover errors.
You cant try to remount File system by
mount -o remount /
Please refer to https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2001611
Answer: Linux will remount it's partitions in r/o mode to avoid data corruption, if it encounters unstable disk performance (EIO errors). Check the underlying storage and the disk image settings.
Comment: well, my reply stands - you have a disk access problem. Try to use a separate disk for the VM, or get a faster disk (or set up RAID). There might also be tweaks in VMW WS that will provide better disk performance, but I'm not familiar enough with the product
Comment: dyasny> i have added more relevant details to the question now (sorry, shud have done that upfront) - the underlying host is simply a desktop  with windows home os.


Playing ghost notes on the drums

Question: I've been playing the drums (acoustic set) for almost a year now and have made good progress.  I am learning from online lessons and loving it, but this has got me stuck.
I'm finding it hard getting into playing ghost notes.
How do I get started on playing ghost notes on the drums?
As far as I understand it's a softer hit on the snare, but is it actually a hit?  Is it a rebound?
Comment: @Karlo [What is a ghost note ?](https://music.stackexchange.com/q/2115/70803).
Comment: What is a ghost note?
Answer: It is a hit.  The force behind this hit depends on style and intended volume, but in general it is a note, it needs to be played in a controlled way, and it needs to be in time.  There are plenty of "accent tap" or "bucks" exercises which will be helpful to practice.  Of course, a prerequisite is to practice taps (ghost notes) on their own.  They're ultimately just notes, except quieter, and this is achieved primarily by not moving the stick as far.
The hard part of playing ghost notes among accents is what is traditionally called the "downstroke"- that is, you stop the stick at a low height, ready to play a tap, immediately after playing a loud accent.  Doing this without excessive tension is really is a matter of fine muscle coordination.  Then there is the "upstroke" after the tap (ghost note) is played.  This isn't really too complex, you just lift the stick right after playing the note.  A note played that low doesn't give much rebound.
In my very first drum class, we practiced playing "upstrokes" (low to high), "downstrokes" (high to low), "full strokes" (high to high, though I think we used a different name back then), and "taps" (low to low).  These really are the basics of snare drum technique.
Now, of course, when I go to play drums, I don't think about any of this.  You focus on fundamentals in deliberate practice, so that they become natural, and then you don't have to think about them anymore, except for the occasional refresher practice.
Answer: A rebound (bounce) can only occur after the drum has already been hit. So sometimes a ghost note will be a rebound. But it can't always be, as there's no hit prior to bounce from.
It's a more gentle hit, and could be achieved by a sideways brushing action unlike a direct downwards hit from above. Or hitting the edge of the skin rather than the more usual middle.
Answer: In my opinion, ghost note feels more like lightly tapping the drum head with stick than full hit. If there is a hit right before it, it should be played as a downstroke (stop the stick right above the head when it rebounds) instead of playing the ghost note as rebound.

Playing ghost notes on the drums


Debian kernel upgrade issue

Question: I was checking my Debian 11 bullseye kernel if i have fix for Dirty Pipe vulnerability. Seems that kernel version 5.10.102 has the fix for that.
Problem is that i cannot get upgrade for that kernel version. At least with apt-get update command.
Do i have to manually upgrade my kernel or is there some repository which i have to add to my sources.list?
Also apt-get update or apt-get dist-upgrade does not give OS upgrade to version 11.2 which seems to be latest version of Debian. uname -rs gives me Linux 5.10.0-11-amd64
Answer: The fixed kernel version (5.10.103-1) is available in the Bullseye security repository. Add this line to your sources.list:
deb http://deb.debian.org/debian-security/ bullseye-security main

Comment: Finally got time to try this. Unfortunally this did not do the trick. I have above repo in `sources.list` but highest kernel version i get is `5.10.0-13-amd64`

Debian kernel upgrade issue


Can such Routing be done in MVC 4.0

Question: Can I have a path configured as :
<code>        routes.MapRoute(
        name: "Default",
        url: "{id}.zeko.com",
        defaults: new { controller = "App",
                        action = "GetDetailsById",
                        id = UrlParameter.Optional
                      }
               );
</code>
I want the id as a parameter to my method. Tell me where am I wrong?
Answer: ok figured it out myself.....just we have to spilt the domain we have got after each id is created.
Answer: I'm not entirely sure that this is possible. I believe the routing engine in MVC does not handle domain requests by default. What you can do is add an IIS handler that processes the requests beforehand, or what I have done in Web Forms (and I am not exactly sure how you would accomplish this in MVC) is to call a method to strip out the subdomain in my "Page_Load" method and then work with that variable as required. Below is an example of the function I use, keep in mind my application only expects to work with a single subdomain such as "subdomain.maindomain.com":
<code>private static string GetSubDomain(Uri url)
    {
        try
        {
            string host = url.Host;
            if (host.Split('.').Length > 2)
            {
                int firstIndex = host.IndexOf(".");
                string subdomain = host.Substring(0, firstIndex);

                return subdomain;
            }
        }
        catch
        {

        }

        return string.Empty;
    }
</code>
Answer: I found this post for you, however it requires knowing each possible subdomain in advance, where as my previous answer allows for dynamic subdomains. Hope these helped!
Is it possible to make an ASP.NET MVC route based on a subdomain?

Can such Routing be done in MVC 4.0


How to isolate $x$ from $x^y=z$?

Question:
$x^y=z$

How would I isolate $x$ from the equation above so that I get $x=...$ ?
I couldn't find anything on the internet and I have no idea how to solve this. Any help is appreciated.
Answer: If $$x^y=z$$ then $$x^{y^\frac{1}{y}} = z^\frac{1}{y}$$ and since $$x^{y^\frac{1}{y}} = x^{y \cdot \frac{1}{y}} = x^1 = x $$ we thus have $$x = z^\frac{1}{y}$$
which is also known as $$x = \sqrt[y] z$$

How to isolate $x$ from $x^y=z$?


What do the 3/4 and 4/4 numbers mean?

Question: In music notation, I've always been looking for a simple explanation of those numbers that appear on the far left of musical piece, such as 3 over 4 or 4 over 4.
I have a hunch they affect the tempo, but I'm not sure if they affect the way the piece would sound.
Would the piece sound differently if I change the numbers?  Or is that not applicable?
Answer: These numbers are time signatures. In brief, they tell you how many beats are in a measure. (This answer might not work as well for people not familiar with music that doesn't have a strong rhythmic component.)
To start this off, think of a waltz. You might count it out like this: One two three one two three (and so on). That's 3/4 time; each measure is three quarter-notes long (or the equivalent number of notes of other lengths).
Most music is in 4/4, also known as common time, where measures are four quarter-notes long. One two three four one two three four (and so on), or perhaps : One two three four (etc), or any other such variation; which beats are stressed doesn't change the time signature, but how many notes you can fit into a measure will.
Tempo is the speed of a piece, and is independent of the time signature. (Think of the movie "That Thing You Do", where the drummer made the band's piece a hit by simply speeding it up. It was still mostly the same song, but had more energy at a faster tempo.)
There are other time signatures, such as 2/4 (think of polkas) and less-common meters like 5/4 and 7/4. You'll also see meters like 7/8, where there are seven eighth notes in a measure. Time signature can change within a piece, although this isn't too common.

Related: Is there any real-world difference between time signatures such as 4/4 and 8/8?
Comment: "One **two** three **four**" ([backbeat](http://en.wikipedia.org/wiki/Beat_(music)#Backbeat)) is a very American thing. It's the spine of jazz (and rock), but not of classical music. ["In music that progresses regularly in 4/4 time, the first down-beat is usually the strongest accent in the melody and the likeliest place for a chord change, the third is the next strongest: these are 'on' beats."](http://en.wikipedia.org/wiki/Beat_(music)#On-beat_and_off-beat) That's why it's so hard to teach, say, a German to clap on two, four, six, eight. Their musical tradition is very different.
Comment: I like the tone of your answer! Two thoughts: (1) Is it worth amending slightly to make it clear that although in 3/4 (for example) there are three quarter-note **beats** or toe-taps per measure, there aren't necessarily three quarter-**notes** in each measure as there may be more or fewer notes?  (2) Like @RegDwight, I am more familiar with 4/4 having the accented pattern strong-weak-lessStrong-weak (I'm from the UK). I find this pattern useful for recognising where each new bar begins (and also for following a conductor marking the downbeat of each bar).
Comment: Yes, I have a friend with that same blind spot, due mostly to the music she grew up hearing. However, to one who is familiar with music that has a backbeat, this is a very quick way to explain it. Even if it doesn't help the question author (in which case he's free to vote this down), it may help others.
Answer: The best way to learn time signatures is to actually read good documentation on them. MusicTheory.net has some great lessons and visual examples to show you how notes are divided in measures.
Link: http://www.musictheory.net/lessons
More specifically, you should look at lesson 12, 15 and 16 that talk about Simple, Compound and Odd meters:
General Time Signature: http://www.musictheory.net/lessons/12
Simple and Compound Meter: http://www.musictheory.net/lessons/15
Odd Meter Lesson: http://www.musictheory.net/lessons/16
Since your question is a pretty basic one, you should look around that website on note values as they are helpful in reading measures.
Answer: 3/4 means there are three/quarter notes to a measure.
The tempo mark will usually say how many quarter notes to a second since you are saying how many quarter notes to a measure in the time signature.
If you changed the time signature to 4/8 time (four/eighth notes to a measure), it is typical then to say how many eighth notes to a second in the tempo mark.
So, no, it will not change your tempo going from 3/4 to 4/4, however, 3/4 to 3/8 would change things.
But, what 3/4 and 4/4 will change is the beat. 3/4 you would count 1,2,3,1,2,3 (with an accent on the 1 in most cases). But in 4/4, the way the beats are counted changes to 1,2,3,4,1,2,3,4 because now you have 4 beats to a measure. edit: Also, the measure bar lines should always be right before the 1, so if you change from 4/4 to 3/4 then you would have more bar lines and they would mostly all have to move.
Comment: Beware! you cannot change a time signature from 3/4 to 4/4 or 4/8 or 3/8 without changing either some of the notes' duration everywhere or all the bar lines or both! The only (theoretical changes) you can do without changing bar lines or note duration are conservative of the time signature's fraction: 3/4 to 6/8 for instance.
Comment: @ogerard: The asker did not ask if it would be written differently, he asked if it would sound differently. All the sheet music software I have seen changes the bar lines automatically. And I would be highly surprised if the asker was hand-writing his music. The down vote was not reasonable in my opinion. Edited anyway.
Answer:
I have a hunch they affect the tempo, but I'm not sure if they affect
the way the piece would sound.
In music notation, I've always been looking for a simple explanation
of those numbers that appear on the far left of musical piece, such as
3 over 4 or 4 over 4.

Erroneous. The tempo is the metronomic pulse of music. The tempo by the "clacking" of the drummers sticks together as he emphatically shouts "1! 2!34!!!"
This is the best explanation I can find. http://www.dolmetsch.com/musictheory4.htm#common
3/4 = 3 beats of 4 quarters where 4*1/4=1 Of course you're aware that 4 quarters make 1 whole, so naturally 4/4 time means four beats of four quarter notes (= 1 measure). Therefore, similarly, you know that three beats of four quarters then, should equal 1 whole.
Manifested in notation you'll find nothing more than the time/space musical sub divisions allow.

The first measure is "Common Time" which is what 4/4 is referred to in our modern era. This is also what the big ol C stands for.
Cut time is second, also called double time, also called half time, rather confusingly. Thus, the C is cut vertically to represent such.

And finally here you can see the juxtaposition of a handful of common measures interrelating to one another intimately so as to demonstrate their nature, and to illustrate how they can maintain confluence while being seemingly inherently contradictory.

What do the 3/4 and 4/4 numbers mean?


Include the content of a jsp in a servlet

Question: I have this servlet:
public class SaveImage extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = null;
        try {
            out = response.getWriter();
            out.println("");
            ...

            // I want to include here the content of this jsp:
            // /WEB-INF/mybox.jsp
            // (also, with the full context of the servlet)

            ...
            out.println("");
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Is there a problem doing it (response already committed?), how can I do this?
Answer: request.getRequestDispatcher("/WEB-INF/my.jsp").include(request, response);

But you should not a servlet for outputting html like that. Just use a jsp, with either <jsp:include /> or <%@ include file=".." %>
Comment: Hi Bozho, are we able to use request.getRequestDispatcher().include() with parameter set (not attribute)? Something like when we are using  we can set the parameter. Is it possible? Thanks for help.
Answer: THANKS ozho , YOU HAVE HELPED ME TO give final shape to 2 year old pending project. Thanks.
Actually to redirect the request of tomcat from sun web server 7 to application server, since the jsps are not shown in tomcat directly, technique is to use a passthrough in app.config and let the tomcat handle the requests.
            import java.io.IOException;

            import javax.servlet.RequestDispatcher;
            import javax.servlet.ServletContext;
            import javax.servlet.ServletException;
            import javax.servlet.http.HttpServlet;
            import javax.servlet.http.HttpServletRequest;
            import javax.servlet.http.HttpServletResponse;

            /**
             * Servlet implementation class MY... Parvez Ahmad Hakim
             */
            public class MY extends HttpServlet {
                private static final long serialVersionUID = 1L;

                /**
                 * @see HttpServlet#HttpServlet()
                 */
                public MY() {
                super();
                // TODO Auto-generated constructor stub
                }

                /**
                 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
                 */
                protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                    String pageName =request.getParameter("req");
                    if(pageName==null){
                        pageName="IC_LIC_Login.jsp";// default page
                    }
                    request.getRequestDispatcher(pageName).include(request, response);

                }

                /**
                 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
                 */

                protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                    String pageName =request.getParameter("req");

                    request.getRequestDispatcher(pageName).include(request, response);
                }

            }


Infinite tetration of $-2.5$

Question: Let $a_n$ be the sequence $z, z^z, z^{z^z} ...$ for $z \in \mathbb{C}$.  This is sometimes called the iterated exponential with base $z$.  I am investigating the above sequence for $z = -2.5$.  After 6 terms it is on the order of $10^{26649}$.  My question is whether the sequence is eventually sent very close to $0$ or if the entire sequence diverges to $\infty$.
I have tried manipulating the sequence $a_n$ in various ways, most of which involve the natural log.  These include computing $\ln a_{n+1} = a_n \ln z$
as well as the sequence $b_n = \ln a_n$ using $b_0 = \ln z$ and $b_{n+1} = e^{b_n}\ln z$.  For other values of $z$ I am able to conclude that some term $a_n \sim 0$  because $b_n$ has a negative real part.  But this is not the case for $z = -2.5$.  I have also found it is extremely awkward to evaluate more than a few terms in these situations; the numbers involved tend to get much too large to manipulate directly, even with a system that supports arbitrary precision arithmetic.
Edit: What I have tried so far is essentially asymptotic analysis.  To $10$ digits $a_6 = 1.048867589\cdot10^{26649}-5.4257156893\cdot10^{26648}i$.  If this, or some later term, were of the form $-\infty+\infty i$ I could stop there since we would have $a_n \sim 0\cdot0 =0$.  Otherwise, I need to explicitly compute at least $1$ more term, because we would have $a_n \sim \infty\cdot\infty = \infty$ or $a_n \sim 0\cdot\infty$.  Alternatively, I have tried computing $b_n = \ln(a_n)$ until $\Re(b_n) < 0$.  I have also thought about using other iterative formulas, such as for $ c_n = \ln(\ln(a_n)), d_n = \ln(\ln(\ln(a_n)))$, etc, but I have not had much luck with this.
Comment: And how am I to know what you have or haven't seen, when there's no indication in the body of your question of what you've already done? Look around the site – you'll see hundreds of questions that could have been answered by a simple visit to Google, a visit the person posting the problem didn't take. How can anyone know that you're not one of those people, when you don't give anything away?
Comment: @cpiegore, it is rather sad that we have to ask; as Gerry notes, there are actually too many people who can't be arsed to search, and if you don't give any indication that you've done due diligence, it is too easy to get lumped with the lazy.
Comment: Nothing useful at https://en.wikipedia.org/wiki/Tetration ?
Comment: @GerryMyerson Not to be rude or offensive, but if I could find an answer on Wikipedia I would not have asked here.
Answer: The following is not trying to give an answer how to overcome the numerical problem, but is thought to help the intuition.
From the wikipedia-entry for tetration the remark about the Shell-Thron region implies, that the base $b=-2.5$ should give a divergent orbit for $z_{k+1}=b^{z_k}$, but unfortunately, the orbit beginning at $0,1,b,...$ runs early in numerically such extreme values that we cannot continue looking heuristically for more than a couple of steps (as the OP has put it already).
I've tried to give an intuition for the general shape of the iteration using an interpolation based on log-polar values of the (conjugate) iteration of $y_{k+1} = t^{y_k}-1$ where $t = \exp(-W(-\log(b)))$ (or expressed differently: $b = t^{1/t} $). Here $t$ is also the attracting fixpoint for the inverse operation $z_k = \log_b(z_{k+1})$ - so we can start at a point, say $z_{-120}$ in the near in the fixpoint and iterate a couple of times more to make the tendency better visible.
Moreover, there is a "poor-man's" approximation of the Schröder-mechanism for the interpolation to a continuous flow, using the log-polar representation of the values $y_k$ and interpolating linearly, quadratic or by some higher polynomial. (The orbit $y_k$ are the values of the conjugate iteration $y_{k+1}=t^{y_k}-1$ where $y_k = z_k/t-1$ or vice versa $ z_k = (y_k+1)\cdot t$ .)
It gives for some (random) initial value $y_{-120} $ near zero the following contour, which spirals out (showing the basic divergence of the orbit), arriving at the near of $y_0 $ near $-1$ from where then the numerical problems explode after few more iterations.

The big orange points are the integer-iterates (the orbit of $y_k$) where the problems begins after the $y_k$ arrive in the near of $-1$ (which means $z_k=(y_k+1)t$ is near zero)  The operation $y_{k+1} = t^{y_k}-1$ means to move from the inside to the outside, showing the expected divergence. The small seagreen dots are computed using the interpolation of the log-polar coordinates of the $y_k$ based on 6 values $y_{-120} \ldots y_{-115}$ with a 5-order polynomial in 1/50 steps for one unit. (using simply the standard polinterpolate procedure in Pari/GP). The thin dotted line is the additional cubic spline interpolation provided by Excel.
One would now guess, that besides some extremal values, that curve of the orbit/of the flow would continue to expand - although with some exotic/erratic shape.
The following picture gives the orbit of the $z_k$ and its interpolated flow just by setting $z_k = (y_k +1) \cdot t$:

Of course, the analysis must be continued to really answer the original question.

Infinite tetration of $-2.5$


Deployment blocked

Question: I am in local and set up a gitlab pipepline to deploy my feature in our web site.
When I push my files in ftp client (FilleZilla) I can see the same folder and files and the  modication date.
But I when refresh our distant site I can't see any modifcations thant I have done in local.
Have someone met this issue or give me the solution?
Answer: Did you try to remove the cache in your server if you have any ?
or delete ur client cache

Deployment blocked


fail2ban : read whitelist from a database

Question: Now I don't know if this is the right place to ask, but I try it.
I have a fail2ban running on my server.
And I have a whitelist called ignoreip in /etc/fail2ban/jail.conf(I is a list of IPs and masks)
I have one nice questions:

is there a way or a plugin for fail2ban to use a database table instead of the ignoreip list?
Answer: Sure, there is a way.
Fail2ban has an ignorecommand parameter, that you could use to check against SQL database.
Here is an example using sqlite.
Note: there is parameter ignorecache, which makes it fast and minimizes load (overhead to check on every failure), but it is relative "fresh" - it was released firstly in 0.10.4 and 0.11.1.


How can I fit distribution for data which "almost fits"?

Question: I have a sample for events occurring at certain continuous distances (kilometers), let's suppose emergency calls to hospitals. I have 200k observations, coming from 500 hospitals for an entire month. So, when I plot a histogram for my  distances vector, it  looks to me like a Beta distribution with determined parameters, but actually it's not. Below we have these histograms with respectively 50 and 20k bins:

Yes, the second histograms shows some spikes and pits, and this is maybe my biggest problem to fit, because every goodness-of-fit test gives me extremely low p-values, (and I have already tried to use smaller samples with the same shape).
When I use Probability Plot my results seems to be "kinda good", but not perfect.

I've been reading about method of moments and kernel density estimation, in order to understand if I can use them to fit my data to a pdf (even if not from the theoretical ones), but first I would like to know some things:

Is there anything I could or I should do about my data before estimation? Is window smoothing a valid alternative?
Should I give up trying to fit it into beta? Is there a way to tell something like "this is beta, but with error margins"? What could I say in the paper to support my decision?
If my answer isn't in any of the alternatives above, what should I be reading right now to advance?

I need to fit it to make some conclusions about fuel and maintenance of the cars.
Answer: The overwhelming majority of datasets do not perfectly fit any parameterised class of distributions used in probability theory.$^\dagger$  Those classes of distributions represent an infinitesimally small sliver of the set of all distributions and so it is rare that a dataset comes from one of these classes.  As a result, you often get situations like this one where a dataset is close to a known parameterised distribution, but does not quite fit it.  As a secondary matter, it is well known that if you do a classical hypothesis test, even a tiny deviation from the null hypothesis (of a perfect distribution fit) will manifest in the p-value going to zero as the sample size grows to infinity.  Consequently, when you test a large dataset against a parameterised class of distributions, you will almost always get a rejection of the null hypothesis if you have sufficient data.
Now, most likely your dataset follows an almost-beta distribution that is not equivalent to any standard parameterised class used in probability theory.  You can get a reasonable estimate of the true distribution using a KDE (e.g., with a beta kernel) or some other non-parametric estimator.  Alternatively, since your observations involve multiple variables, you might get a better fit to a parameterised class of distributions for the conditional distribution arising from regression analysis (looking at the distribution of one variable conditional on one or more others).  Answers to your specific questions are below.

Is there anything I could or I should do about my data before estimation?  Is window smoothing a valid alternative?

Don't change your data to try to get a desired conformity with a hypothesised class of distributions --- instead, change your inference to conform to the evidence in your data.

Should I give up trying to fit it into beta?  Is there a way to tell something like "this is beta, but with error margins"?  What could I say in the paper to support my decision?

What do you mean by "give up"?  You tested this hypothesis and it was rejected with strong evidence --- end of test.  If you don't "give up" the null hypothesis after testing and strongly rejecting it, what was the test for?
As to what you can say here, you can say that this distribution is close to a beta distribution, but with some deviation in the upper tails.  If you want to quantify this you could use a measure of distance between distributions (e.g., between your empirical distribution and the closest "fitted" beta distribution) (see e.g., Chung et al 1989).  If you do this then I think you will find that there is a fairly small distance between your distribution and the class of beta distributions.

If my anwer isn't in any of the alternatives above, what should I be reading right now to advance?

I recommend you read about non-parametric inference, and bear in mind the general rule that parametric models for continuous random variables are approximations to true datasets at best.

$^\dagger$ There is an exception to this when dealing with discrete data with finite support.  For data with finite support, the categorical distribution actually does cover every possible distribution.  However, for continuous variables, parameterised classes are much smaller relative to the space of all possible distributions.
Comment: Thank you so much Ben, your answer gave me a clear path ahead and I finally can take a direction!
Answer: The answer by @Ben, which you've already accepted, is great.
I'll just add that a Beta distribution has bounded support (assumes an upper maximum), whereas you're dealing with distances, which don't naturally lend themselves to such an assumption. Moreover, the QQ plot indicates a potential uncertainty in the tail of the fitted distribution.
Therefore, I recommend to also try to fit to your datasets:

a Gamma distribution (perhaps constrained with shape parameter $k = \alpha = 2$),
a Weibull distribution (perhaps constrained with shape parameter $k = 2$, a case which is equivalent to a Rayleigh distribution).

https://en.wikipedia.org/wiki/Gamma_distribution
https://en.wikipedia.org/wiki/Weibull_distribution
https://en.wikipedia.org/wiki/Rayleigh_distribution (equivalent to Weibull with shape parameter $k = 2$)
Comment: This. In my experience a beta distribution is sometimes attractive and appropriate when there are clear bounds at both ends, but rarely otherwise.


Ill-conditioned matrices and their singular values

Question: For ill-conditioned matrices, must it be that the smallest singular value is arbitrarily close to $0$? I know that $K_2(A) = \frac{\sigma_{max}}{\sigma_{min}}$ where $\sigma$ is a singular value of A. Can their be a case of $\sigma_{max}$ being extremely large and $\sigma_{min}$ being arbitrarily close to 1.
Answer: Of course. Think of the matrix $A$ defined as
$$
A = \mathrm{diag}(1, 2, \ldots, N),
$$
where $\mathrm{diag}$ is the diagonal matrix. For any value $N$, the condition number of the matrix will be $K_2(A) = N$ and the smallest singular value $\sigma_{\min} = 1$. The matrix can also be small, for example
$$
A = \begin{pmatrix} 1 & 0 \\ 0 & N \end{pmatrix},
$$
has the same spectral properties as the matrix above.


Banach–Tarski paradox fails to iterate over all points

Question: The Banach–Tarski Paradox explanation goes along these lines
(1) Take a point on a sphere
(2) Use 2pi/3 rotations to construct a subset of points
(3) After infinite number of rotations you've selected [an infinite] countable set of points on the sphere
(4) For each point not on the set repeat step (2)
(5) Repeat step (4) while there are unprocessed points
Done. [This paradox uses an axiom of choice]
Here is my concern. I am fine with an axiom of choice in the form "for any non-empty set you can always select a member of a set". However, Banach–Tarski Paradox seems to try to do something very different.
It tries to keep selecting points from a continuum set until no more points remain. This is NOT possible. Infinite while loop can only select Countable number of points, while continuum must be selected to iterate over all points on a line or a sphere.
If this selection is possible then we can enumerate all points on (0,1) interval. Is there something in the proof that I am missing?
Comment: Your statement "for any non-empty set you can always select a member of a set" has nothing to do with the axiom of choice. However, the statement that you so heavily reject has everything to do with the axiom of choice. So it seems your problem is indeed accepting the axiom of choice. Note that this axiom does not claim anything about "computability" of the choice set, so we do not have to make one choice after the other in an "infinite while loop", but we can make *all choices at once*.
Comment: Are you familiar with transfinite induction/recursion? *(My terminology pet peeve: when you build something it's "recursion," when you verify a property it's "induction.")* Roughly, we can in many circumstances "iterate" a process uncountably many times - or rather, along any *well ordering* (and this is where the axiom of choice comes in: [by well-ordering whatever set we care about](https://en.wikipedia.org/wiki/Well-ordering_principle), we get a well-ordering along which we can perform the desired transfinite recursion).
Answer: There are indeed transfinite sequences — more precisely, sequences indexed by ordinal numbers — that enumerate the entire interval $(0,1)$.
Such a sequence can be 'constructed' via transfinite recursion by the method of transfinitely iterating the operation of "pick an element that hasn't been chosen yet, or stop if there are none".
This applies to any set at all; this fact is basically the content of the well-ordering theorem.
(Note: I'm responding to your final paragraphs. Your description of B-T is somewhat incoherent as well, so I'm not entirely sure you understand what it's doing or that your final questions actually pertain to B-T)
Answer: Axiom of choice is the following proposition:

Given any collection of disjoint non-empty sets, there exists a set containing exactly one element of each of these sets.

Note that the axiom says nothing about how to obtain this set; it only says that this set exists. Your proposition is the weaker axiom of countable choice (axiom of choice for countably infinite collections).
[Edit:] I have been corrected that the proposition from the original question is the axiom of dependent choice, which is stronger than the axiom of countable choice, but weaker than the full axiom of choice.
I am going to give you a theorem which is easier to understand (but is ultimately based on the same kind of construction): Vitali's proof of existence of non-measurable set of reals.

Let $\sim$ be the following relation on reals: $x{\sim}y$, if $x-y$ is a rational number.
This relation splits an interval from $0$ to $1$ to uncountably many equivalence classes, each class being a countable set.
Assuming axiom of choice, there exists a set containing one element of these sets. This set $V$ is uncountable.
Create countably many copies of this set, each shifted by some rational number from $-1$ to $+1$. It can be shown that a union of these sets is a superset of an interval from $0$ to $1$, but a subset of an interval from $-1$ to $2$. In addition, the sets are disjoint.
Lebesgue measure is translation-independent (shifting a set by a constant does not change its measure). In addition (assuming axiom of choice), it is countably additive; given a countably infinite collection of disjoint measurable sets, the measure of the union is equal to the infinite sum of the measures of the individual sets.
Now what is the measure of the set $V$? If the measure is zero, then the measure of the union is also zero (the series $0+0+0+\ldots$ has sum $0$ - note that a sum is a limit of the sequence of partial sums); and if the measure is not zero, then the measure of the union is infinite.
This is not possible - as I have said, the union is a subset of an interval of measure $3$ and a superset of an interval of measure $1$. Therefore, the set $V$ is not measurable.

Now Banach-Tarski paradox is based on the similar splitting of the surface of the sphere into uncountably many countable equivalence classes. The equivalence relation is: "Point $X$ can be reached from point $Y$ using a finite sequence of rotations." Each step is a rotation by a specific angle which is not a rational fraction of the whole circle, in the four directions: "Up", "Down", "Left", or "Right". It can be proven that no two sequences of rotations without backtracking will yield the same rotation; the only way to return to the origin (null rotation) is to backtrack the whole sequence. Therefore given a starting point - except for some pathological points, namely points on the axis of rotation or points reachable from them (of these there are countably many), no two sequences of rotation will yield the same point.
Now use the axiom of choice: there exists a set containing one element of each equivalence class. (For now disregard the pathological points.) Apply all the countably many finite sequences of rotations to this set. Any point on the surface which is neither a pathological point nor in the starting set can be reached from the set by exactly one sequence of rotation. Split the destination points into four subsets:

Points which can be reached by taking a rotation ending with the step "Up".
Points which can be reached by taking a rotation ending with the step "Down".
Points which can be reached by taking a rotation ending with the step "Left".
Points which can be reached by taking a rotation ending with the step "Right".

Now what happens when you take the first set, and rotate it "Down" (backtracking the last step)? Okay, what was the step before that - any of "Up", or "Left", or "Right" (but not "Down" because that would be backtracking). Therefore by backtracking the last step, we turned the first set into copy of the first set, plus the third set, plus the fourth set (plus an extra copy of the starting points). Similarly, when we backtrack the third set, you get the first + second + third set (plus extra starting points).
And now we are basically done - the rotated first set plus the second set yields one copy of the sphere, and the rotated third set plus the fourth set yields the other. (There are some technical details left. First, we have so far handled only the surface of the sphere; but of course we can divide the whole solid ball - except the center - in the same way depending under which point on the surface it is. Second, we have an extra copy of the starting points; we started with one, and got three. Third, we need to handle the pathological points and the center of the sphere.)
For more details on the Banach-Tarski paradox with layman's explanation, I can direct you to the following sites:

Irregular Webcomic (Make sure to enable the annotations.)
Vsauce YouTube video on Banach-Tarski paradox
Comment: A couple more details: 1) Axiom of countable choice indeed does not imply the existence of non-measurable sets. 2) On the other hand, the entirety of axiom of choice is not necessary to prove the existence of non-measurable sets. There are many weaker propositions which imply the same, e.g. the existence of well-ordering of real numbers. (In absence of axiom of choice, it can't be proven that real numbers can be well-ordered.) And that's still an overkill - it's consistent that real numbers can't be well-ordered, but non-measurable sets exist and Banach-Tarski paradox is true.
Comment: Your answer is actually wrong. The statement that the OP has in mind is not countable choice, but rather dependent choice, which is stronger.
Comment: And dependent choice does not imply the existence of non-measurable sets, either. More precisely: "ZF + dependent choice + all sets of reals are measurable" is consistent, if and only if "ZFC + there exists an inaccessible cardinal" is consistent.


WIF 4.5 BootstrapContext security token null

Question: I am using the new 4.5 WIF stuff to authenticate users of the website and to secure the communication between my MVC website and WCF services.
I have the website configured to save the bootstrap context so that I can re-use the same security token for all requests to the service layer.
Under normal conditions all is working fine with each website request authenticated and the SecurityToken made available via the context to secure the WCF calls.
If however the websites app domain is reset (e.g. building the app while developing) any requests to the website will still be authenticated but the SecurityToken is no longer available in the context to pass on to the WCF calls.
Debugging the BootstrapContext it has 4 useful properties:
SecurityToken
SecutiryTokenHandler
Token
TokenBytes

Pre-app domain reset SecurityToken and SecurityTokenHandler have values, and post reset Token has a value.
Eyeballing the value for Token after the reset it looks like this is the raw SAML XML so I can presumably rehydrate a full SecutiryToken from it but this seems strange behavior that I cannot find any documentation about.
Any ideas what I could do to ensure the SecurityToken is always available to save me messing around with the token XML?
Update
Using dotPeek to look at what is going on in the framework source code I could see the execution path that casues this behaviour but I couldn't determine any reason why it needed to be this way and how it could be avioded.
In the end I gave up trying to work it out and now use the following piece of code to ensure I have a token
if (context.SecurityToken != null)
{
    token = context.SecurityToken;
}
else if (context.Token.IsNotEmpty())
{
    var handlers = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers;
    token = handlers.ReadToken(new XmlTextReader(new StringReader(context.Token)));
}

What I am now concerned about is I have missed some reasoning behind this behaiour and my fix above is going to blow up at some point.
Comment: OWIN not same WIF ?
Answer: I have stumbled upon the same issue.
I see the Token to have the xml representation of the token and the SecurityToken being null.
I also noticed that this is really easy to reproduce by killing w3wp.exe.
Answer: I have solved the problem by deleting the browser cookie including the Fedauth cookie. Once debugging again I was able to get all needed values
Answer: I had the same issue when I implemented the ClaimsAwareWebFarm sample from microsoft. The problem arises when you add this section to the web.config:
  <caches>
    <sessionSecurityTokenCache type="CacheLibrary.SharedSessionSecurityTokenCache, CacheLibrary">

      <cacheServiceAddress url="http://localhost/SecurityTokenCacheService/SessionSecurityTokenCacheService.svc" />
    </sessionSecurityTokenCache>
  </caches>

Thank you Matt for this workaround!


Python - ImportError: No module named

Question: I have following directory structure:
img_search
   --- server
       --- __init__.py
       --- server_flask.py
   --- tests
       --- __init__.py
       --- test_kdtree.py
       --- test_distance_matrix.py
   --- __init__.py
   --- kdtree.py
   --- distance_matrix.py

__init__.py in server and tests are empty and __init__.py in img_search contains following code:
from img_search import distance_matrix, kdtree

I use class from kdtree in server_flask.py using following import:
from img_search import kdtree

When I run server_flask.py in PyCharm it works without any problems, however when I run it in terminal, I get an error.

Traceback (most recent call last):
  File "server_flask.py", line 2, in <module>
from img_search import kdtree
ImportError: No module named img_search

How can I fix this?
Thank you in advance
Answer: I suppose you have some meaningful reason to do it that way but it doesn't need to look like this.
In general, modules should provide some functionalities and be consistent as one package or library that is providing some API.
In other words this should be avoided:
python server_flask.py

or
python img_search/server/server_flask.py

But this one is totally fine:
python main.py

With main.py having some kind of:
from img_search.server import server_flask
# Do something if needed

Have a good one!
Answer: If you really need this, another option will be to mess with path. In your server_flask.py add following lines:
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))

sys.path.append will add to a path a module location which will be found by joining dirname of server_flask.py __file__ and its ../.. directory. Here we are.

Python - ImportError: No module named


Making sense of importance measures offered in Ranger

Question: I have trained a regression forest using the R package ranger. Now I would like to discuss the variable importance measures of the included features. However, I am having difficulties understanding the exact definition of the different importance measures offered by ranger.
The documentation of the ranger function states the following about the argument 'importance':

Variable importance mode, one of 'none', 'impurity', 'impurity_corrected', 'permutation'.
The 'impurity' measure is the Gini index for classification, the variance
of the responses for regression and the sum of test statistics (see splitrule)
for survival.

In my case, I trained a regression forest. Here is a reproducible example including all feature importance measures offered by ranger:
library(ranger)

## Estimate the same model with the three different importance measures offered by ranger
set.seed(1)
rg.iris_1 <- ranger(Sepal.Width ~ ., data = iris, importance = 'impurity')
set.seed(1)
rg.iris_2 <- ranger(Sepal.Width ~ ., data = iris, importance = 'impurity_corrected')
set.seed(1)
rg.iris_3 <- ranger(Sepal.Width ~ ., data = iris, importance = 'permutation')

## Store the importance measures in a table
varimp_table <- data.frame(impurity = rg.iris_1$variable.importance,
                               impurity_corrected = rg.iris_2$variable.importance,
                               perumtation = rg.iris_3$variable.importance)

This gives the following table:

And here are my questions:

How can I interpret the three columns of this table?
Are there any papers explaining what is meant by the different approaches?
What are the pro's and con's of each measure?

Edit:
After trying to make sense of the code on github, this seems to be the part where the variable importance is calculated in the case of the given example:
double decrease = sum_left * sum_left / (double) n_left + sum_right * sum_right / (double) n_right;

and for example, sum_right seems to be defined here:
for (size_t pos = start_pos[nodeID]; pos < end_pos[nodeID]; ++pos) {
      size_t sampleID = sampleIDs[pos];
      double response = data->get_y(sampleID, 0);
      double value = data->get_x(sampleID, varID);
      size_t factorID = floor(value) - 1;

      // If in right child, count
      // In right child, if bitwise splitID at position factorID is 1
      if ((splitID & (1ULL << factorID))) {
        ++n_right;
        sum_right += response;
      }
    }

I never learned C++, but this seems as if the squared response is averaged and not the response variance, as it is stated in the description of the package. This wouldn't really make sense, though... would it?
Please help!
Answer: Here are at least some links that might help:

Nembrini et al. 2018 explains "impurity_corrected" (and more)
More on permutation importance, including additional links: https://github.com/imbs-hl/ranger/issues/237
Something on impurity importance: https://github.com/imbs-hl/ranger/issues/489
Something on units of importance measures: https://github.com/imbs-hl/ranger/issues/308

On your additional question, squared response and variance is actually equivalent in optimization since the mean's cancel out.


How can I correlate pageviews with memory spikes?

Question: I'm having some memory problems with an application, but it's a bit difficult to figure out exactly where it is.  I have two sets of data:
Pageviews

The page that was requested
The time said page was requested

Memory use

The amount of memory being used
The time this memory use was recorded

I'd like to see exactly which pageviews are correlated with high memory usage.  My guess is that I'll be doing a T-test of some kind to determine which pageviews are correlated with increased memory usage.  However, I'm a bit uncertain as to what kind of T-test to go with.  Can someone at least point me in the right direction?
Answer: Jason,
You ask good statistical questions.  Think about the amount of memory being used as a random variable.  The first step is to look at the distribution of this r.v.  It may not fit any known distribution, but don't let that stop us. One simple approach would be to take the highest memory usage (top 5-10%) and see if those pageviews (or the times when they were requested) are any different than the pageviews for the rest.  I think you'll need some non-parametric test that compares the proportion of pageviews of the low memory sample to the proportion of pageviews in the high memory sample.  Hope this helps.
Answer: I would suggest constructing a dataset with two columns. The first would be the proportion of each page appearances in the highest memory usage times of the distribution, and the second the proportion of those (same) pages for the rest of the values of the memory distribution.
Then you would have to perform a paired test to check if the median of the differences (high - rest) is less or equal to zero (H0), against the alternative hypothesis that the median of difference is greater than zero (H1). I would suggest using the non parametric test Wilcoxon Signed Ranks Test which is a variation of Mann - Whitney Test for paired samples. It also takes into account the magnitude of the differences in each pair, something that other tests ignore (e.g. sign test).
Keep in mind that ties (zero differences) present numerous problems in derivations of nonparametric methods and should be avoided. The preferable way to deal with ties is to add a slight bit of "noise" to the data. That is, complete the test after modifying tied values by adding a small enough random variable that will not affect the ranking of the differences
I hope that test's results and plotting the differences distribution will give you insight into where the problem is.
This is an implementation of Wilcoxon Signed Ranks Test in R language
Comment: Thanks gd - this is a fine elaboration on my response.  Does it matter that the sample sizes are very different?  The high memory counts are going to have only 10-20% of the observations of the others, right?
Comment: That's why I suggested to use proportions. Also avoid zero percentages using the rule of succession - or calculating posterior probability estimates (binomial/beta model), in the bayesian way.
Answer: Here is another idea:
If you are able to join Pageviews and Memory use by the timestamp values, you could form a table like this
Page A | Page B | Page C | Page D | Page E |....| Memory_use
The value for each of the page columns might be a bit [0,1], showing that the page was requested or not, or a count of pages, depending on your data. In Memory_use column you could have the relevant memory load proportions, or counts in MB. In this way, Memory_use can be thought of a dependent variable and the pages as explanatory ones. So you could fit an appropriate (depending on the form of the dependent variable) generalized linear model to this dataset. The results of this analysis will give you insight on the following
-Which pages significantly affect the value of memory use
-The extent to which each page contributes to the load (by its coefficient in the model)
-The possibility that other factors, not measured, play a significant role in memory load (overdispersion), with the worst case that all the predictor variables may turn out to be unimportant.
Answer: What you pose is certainly an interesting statistical problem, but might I suggest a graphical approach with a good ol' spreadsheet instead?
Assign each of your pages a unique number, and make a scatter plot of page # vs memory usage. You should get a bunch of vertical lines of markers. Hopefully the culprit will be obvious.
If there are so many data points that the lines turn solid, then you can add a small amount of noise to the page numbers to broaden the lines. If the requests are overlapping then you may have to try tricks like dividing the memory by the number of concurrent requests, but your eyes should be able to pick out the offender even with a lot of noise.


When introducing the Optimizer variables under variable_scope get recreated twice, why?

Question: As the title suggests, when looking at the graph inside tensorboard - the variables I've created inside a variable_scope get recreated twice.  Why is that? what am I doing wrong?
def weights_biases(weights_shape, biases_shape):
    weights = tf.get_variable("weights", weights_shape, initializer = tf.random_normal_initializer())
    biases = tf.get_variable("biases", biases_shape, initializer = tf.random_normal_initializer())

    return weights, biases

def hl_relu(input_tensor, weights_shape, biases_shape):
    weights, biases = weights_biases(weights_shape, biases_shape)
    regression = tf.matmul(input_tensor, weights) + biases
    return tf.nn.relu(regression)

def neural_network_model(x):
    # W = tf.Variable(
    #    tf.truncated_normal([vocab_size, embedding_size], stddev=1 / math.sqrt(vocab_size)),
    #    name="W")

    # embedded = tf.nn.embedding_lookup(W, x)
    # embedding_aggregated = tf.reduce_sum(embedded, [1])

    with tf.variable_scope("hidden_layer_1"):
        relu1 = hl_relu(x, [max_words_len, n_nodes_hl1], [n_nodes_hl1])

    with tf.variable_scope("hidden_layer_2"):
        relu2 = hl_relu(relu1, [n_nodes_hl1,n_nodes_hl2], [n_nodes_hl2])

    with tf.variable_scope("hidden_layer_3"):
        relu3 = hl_relu(relu2, [n_nodes_hl2,n_nodes_hl3], [n_nodes_hl3])

    with tf.variable_scope("output_layer"):
        weights, biases = weights_biases([n_nodes_hl3, n_classes], [n_classes])
        output_regression = tf.matmul(relu3, weights) + biases

    return output_regression

def train_neural_network(test_x, test_y):
    with tf.device("/cpu:0"):
        custom_runner = CustomRunner()
        x_batch, y_batch = custom_runner.get_inputs()

        with tf.variable_scope("test"):
            testX = tf.constant(test_x, name="testX")
            testX = tf.cast(testX, tf.float32)
            testY = tf.constant(test_y, name="testY")
            testY = tf.cast(testY, tf.float32)

        with tf.variable_scope("nn") as scope:
            global_step = tf.Variable(0, trainable=False, name='global_step')

            logits = neural_network_model(x_batch)
            scope.reuse_variables()
            test_logits = neural_network_model(testX)

            cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits, y_batch), name="cost")
            tf.scalar_summary('cost', cost)
            optimizer = tf.train.AdagradOptimizer(0.01).minimize(cost, global_step = global_step)

Produces the following abnormality:

You can see that the 'nn' scope was created twice with my hidden layers which are not connected to any inputs, but affect the Adagrad optimizer by providing their initialized random weight constantly.  I suspect this is also slowing down training.
What have i done wrong in my code??
Answer: I believe this is what is causing them to be created twice.
logits = neural_network_model(x_batch)
scope.reuse_variables()
test_logits = neural_network_model(testX)

Can you change that to this:
logits = neural_network_model(x_batch)

without the test_logits and see if you still get the same issue?
Comment: Unfortunately they do.  Those lines do seem out of context, my apologies for that, thats because further down the method (that I didn't copy) there's an accuracy calculation and such.  But anyways, even if I remark these two lines you mentioned this problem still occurs.  I am completely lost as to why this happens.... it's only when I use scopes tho.  Without scopes it wouldn't happen.  The problem is, that I must use scopes if I want to use the QueueRunner feed... that's also why i have the above two lines.
Comment: Also note that adam and adadelta do create an extra set of variables for themselves.  If you look at the model files that get created you'd notice that they are twice as big while using those methods.  They need to do this because that's the way their methods work.
Comment: I'll totally buy that, it's just that when I don't use scopes i don't see those extra variables that i've referenced in the screenshot above.  I only see the extra ones prefixed with update_.  Those are not the ones above.
Comment: So tensorboard organizes the graph differently depending on scoping (it isn't really clear to me how, usually tries to put the scopes in boxes within the other scopes).  It could just be on the side when you don't use variable scopes.  Also when you don't use naming tensorflow will still create those variables but use the previous scope instead.
Comment: Exactly.  And I use scoping because instead of feeding my data through placeholders directly from memory, I have tried feeding the data through OPs that read the data from tfrecord example proto(s).  The whole thing is excessively slow, and I mean orders of magnitude slower and also seems to barely get better with time in terms of cost and accuracy.  That in turn prompted me to look closer at the graph and i've noticed that utilizing these scopes which is the only thing that allowed me to feed my test batches, created an extra set of hidden layer variables which are initialized...
Comment: ... but don't get fed any inputs.  Tho their outputs are being considered and changed by the Adagrad optimizer.  But sure, let's say that this is all fine and by design... is there anything in the code above that seems like it would make everything run so slow or for the model to not train properly?
Comment: There would be a couple of things to check for. 1) make sure you aren't recreating tf.Variables 2) your custom runner, 3) gpu >> cpu (usually but not always) 4) check the timing of just the cost step versus other parts.  Otherwise there isn't really anything wrong with your code I'd say.
Comment: 4) is what I should have addressed before.  It seems that if I just calculate cost but comment out the accuracy part and skip feeding it the test data, it runs faster.  Still comparatively slower than when using placeholders.
Comment: so actually there's a blog post on this, tf placeholders are in general at the moment faster than using queues. Here's the blog post  https://indico.io/blog/tensorflow-data-inputs-part1-placeholders-protobufs-queues/ you have to work at it to get it to be faster than or as fast as placeholders.
Comment: This blog post is why I'm confused and started looking at the graph more closely. You'll notice that in the beginning of train_neural_network() I use that same CustomRunner class they point to in part 2 of that linked blog article.  And I preload everything into memory.  And still I don't see an improvement not to mention that my model doesn't train as well as it would if it was purely from memory, fed with placeholders directly via feed_dict.  Thats what prompted taking a closer look at the graph and finding this extra NN layer hidden inside the NN scope. Problem is feed_dict doesn't scale.
Comment: One more thing worth mentioning is that I don't see any open issue about this apparently known problem.
Answer: Are you sure the variables are re-created? I suspect what you see is just Adagrad variables created by the optimizer so that is can save what it needs for its computation. Can you try the simplest GradientDescentOptimizer and see if it still happens?
Comment: You're right that with the GradientDescentOptimizer I don't see the same thing happening.  However, with the AdamOptimizer and the AdagradOptimizer I definitely see more than just the update variables.  You can even see in the example picture above that I get a new scope with the same name, that has its own weights and biases and NO inputs only outputs which ultimately affect the optimizer.  That's in ADDITION to the other layers outputting to the optimizer.  So I basically have double the outputs for every layer going into the optimizer. (excuse the caps, just wanted to highlight)
Comment: I don't know how to post any more images, but i'd gladly do so.
Comment: The whole thing started because I compared utilizing a QueueRunner and feeding the data with placeholders and my model crawled, very noticeably.  And then I started looking into the graph and found this... I'm suspecting it has something to do with my model crawling and also having some suspicious results.
Comment: Have you tried finalizing the graph before your first session.run


Unzip a zip file in google storage on google cloud shell

Question: Here I need help at 2 points: How could I achieve my bucket directory on google cloud shell and how to unzip a zip file in my bucket in google storage again on google cloud shell?
When I try:
unzip gs://bucket-name/zip-file-name.zip

google cloud shell says: -bash: gs://bucket-name/: No such file or directory
but when I write: gsutil ls gs://bucket-name/, it lists files in the bucket. So, I decided to first achieve my bucket directory than unzip. At this point, if I write: gsutil gs://bucket-name/ it says: CommandException: Invalid command "gs://bucket-name/"
What should I do to unzip a zip file in google storage on google cloud shell?
Comment: 1) Copy the file from Cloud Storage to the Cloud Shell file system using **gsutil**. 2) Unzip the downloaded file. 3) The program **unzip** does not contain drivers to support the Cloud Storage **gs:** namespace.
Comment: There is a "gsutil cp" command but I guess it is for copy the file from Cloud Storage to the local. How could I copy it to Cloud Shell file system? Do you have any idea?
Comment: Using **gsutil cp gs://bucket/objectname local-filename**.
Comment: It works, thank you. Could you please write it as answer instead of comment? I would like to check it as the answer of this question. In addition to, do you have any idea about unzip a zip file directly in a bucket where a zip file exists instead of in Cloud Shell file system?
Answer: There is no mechanism to do it in place. What you can do is open a cloud shell (from the >_ button to the right of the search bar) and in the shell that spawns at the bottom you can type:
gsutil cp gs://bucket/objectname local-filename
to move the file to the cloud shell machine.
Then you can unzip it:
gunzip local-file name
and then you copy it back with:
gsutil cp local-filename gs://bucket/objectname


How can i sort for every word in a string for every string in a list?

Question: For starters i did this
text = "Hello I want to make this code better"
x = text.split()
sorted_characters = sorted(x[5])
sortedword = "".join(sorted_characters)
print(sortedword)
I want the code to do this but i couldn't figure out how to seperate words and every string in list:
example=['I like python', 'I like reading books']
Output should be ['I eikl hnopty', 'I eikl adeginp bkoos']
Answer: A one liner:
[' '.join([''.join(sorted(z)) for z in i.split()]) for i in example]
This just does what you did, with the list comprehension feature of python, and sort every element in the list
Comment: how can i make it output 'ouy acn go aefrst ahnt 015', 'adiikklt ckllouuy' without it being a list and comma not being a string ?
Comment: I'm not sure I understood your question, but if you mean how to convert it to a string you could just ', '.join() the comprehended list
Answer: You can use split to get the words out of the sentence and sort each of them and add them to a new string, like this...
text = "Hello I want to make this code better"
res = ""

for i in text.split():
    temp = ""

    for j in sorted(i):
        temp += j

    res += f"{temp} "

print(res)

Comment: for j in sorted(i):
        temp += j

    res += f"{temp} " what did you do here can you explain i haven't learnt these things :D and are there any alternatives i can do ?
Comment: @PitonGamer - For example, `i += 1` is the same as `i = i + 1`. (It's a carry-over from C). In Python the same logic can apply to strings.  It's adding a new string to the existing string.


Salvar número em agenda telefonica?

Question: tenho uma mobile app acessando via browser, nesta tem um botão com número telefônico. Gostaria que quando o usuário clica se neste botão o número fosse salvo na agenda telefônica.
Obrigado
Comment: Sergio e uma mobile app, acessando pelo browser. Existe um botão com o numero telefônico, quando o usuário clicar neste número ele salva na agenda telefonica.
Comment: Podes ser mais claro? estás a fazer ou fizeste uma APP que tem funcionalidade de browser e quando clicar num numero de telefone ele guardar nos contactos?
Answer: Isto não é possível, até por questão de segurança. Suponha que fosse possível - neste caso, uma página poderia sobrescrever os contatos do usuário.
Por outro lado, você pode transformar um número de telefone em um link. Neste caso, o usuário poderá clicar no link que o telefone aparecerá no aplicativo de ligações. Basta usar algo como:
Número de telefone

Teste aqui: https://jsfiddle.net/ycmyu86b/
Com o número no aplicativo de telefone, o usuário pode então adicioná-lo aos contatos, ou ligar para o número. Mas a decisão do que fazer sempre ficará com o usuário.
EDITADO: @Sergio fez um comentário interessante, sugerindo utilizar vCards. Embora o contato não vá ser adicionado automaticamente, o vCard realmente tem muitas vantagens: dá para sugerir o nome do contato, adicionar mais informações etc. E é possível fazê-lo sem sequer precisar de servidor! Considere o vCard abaixo:
BEGIN:VCARD
VERSION:2.1
N: brandizzi
FN: brandizzi
TEL;WORK;VOICE: +55 (66) 7788 9910
END:VCARD

Podemos codificá-lo para pô-lo em uma URL (por exemplo, com encodeURI()):
"BEGIN:VCARD%0AVERSION:2.1%0AN:%20brandizzi%0AFN:%20brandizzi%0ATEL;WORK;VOICE:%20+55%20(66)%207788%209910%0AEND:VCARD"

Agora, basta usar essa versão codificada em uma URL de dados

    Link para contato

Pessoalmente, gosto da URL para o telefone porque eu, como usuário, quase nunca quero adicionar um contato à minha agenda, quero só ligar. Agora, suspeito que o vCard funciona melhor para o que o OP quer.
Comment: Mas não seria possivel fazer a webapp retornar um download de um `vcf` ? http://stackoverflow.com/q/1773876/2256325
Comment: @Sergio é possível, mas novamente o usuário terá de escolher se vai ou não adicionar o contato. Não é possível fazê-lo automaticamente via script. Por outro lado, o vCard realmente tem uma vantagem: é possível passar mais informações através dele, além do número. Nem é necessário gerar no servidor, dá para fazer via JavaScript. Ao menos eu consegui fazer, num teste aqui. Vou complementar a minha resposta.
Comment: @brandizzi se tiveres tempo para um exemplo com vCard seria excelente. Entretanto parece que a tua ajuda já resolveu o problema :)
Comment: Obrigado @brandizzi o `` ajuda.

Salvar número em agenda telefonica?


Versions of Package with YUM

Question: I want to know which versions of the same package were previously installed with YUM. For example if I have a package that it version is 4.0, I should need to know the previously versions installed
Answer: Have you tried looking at yum history?
That's what I use to find out what have been updated on Red Hat box.
Here is an article on redhat.com homepage.
For example:
<code>yum history package-list foo\*
</code>
Comment: Yes I tried it. But doesn't show the previous versions ,,,
Comment: If the package was installed previously by yum then AFAIK it *should* show the version...
Comment: Parse your YUM logs for the relevant history.
Comment: Seriously though, `yum history package-list` does just what Jorge is asking for;
     `to trace the history of subscription-manager and related packages, type the following at a shell prompt: "yum history package-list subscription-manager\*"` see link I posted in answer: https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Yum-Transaction_History.html

Versions of Package with YUM


Formatos de table?

Question: Gostaria de saber se é possível fazer uma table contendo um "texto" no meio das linhas dela!
Segue um exemplo:
Answer: Seria isso que você procura? http://jsfiddle.net/MeeW2/
O HTML ficará assim:

Div title

E o CSS, assim:
div{
    border: 1px solid #000;
    width: 200px;
    height: 200px;
}

div h1{
    text-align: center;
    margin-top: -10px;
    height: 20px;
    line-height: 20px;
    font-size: 15px;
}

div h1 span{
    background-color: white;
}

Originalmente postado aqui: https://stackoverflow.com/questions/19868267/div-title-on-div-border-how-to
Comment: Seria isso mesmo @FredDutra!
Comment: Funciona, e é interessante a forma como se resolveu. Porém observei que se, por exemplo, o tamanho da fonte for um pouquinho maior, ele poderá sobrepor outros elementos da página isso pelo uso do `margin` a negativo, dando ao texto uma espécie de posição absoluta. Acredito que depois o OP irá aprimorar neh... :)
Comment: Have my +1 good sir.
Comment: Sim, o OP deverá alterar para as necessidades dele. Quanto a essa questão da fonte, podemos fazer tanto alteração no próprio CSS como também podemos usar `media_query`, *JQuery*, ou um *Compass* para fazer versões diferentes ;)
Answer: Usa um fieldset. A tag fieldset tem que ter necessariamente uma tag filha legend, que é o texto dele. Fica exatamente como você quer, essa tag foi criada pra isso.
<fieldset>
    <legend>Texto</legend>
    foo
</fieldset>

Exemplo no JsFiddle. Editei o exemplo pra legenda ficar mais pro centro.
Agora é só deixar a borda como você quiser e ser feliz. Você também pode reposicionar o legend usando margens e padding.
Comment: não creio que dessa forma ficará tal como a imagem descreve. Talvez adicionado um estilo(`css`) poderia chegar lá.
Comment: @Cold errei a tag com o texto. Acabo de corrigir.
Comment: Mas ainda assim, não sei se a legenda ficaria no centro, tal como na imagem. Era esta a minha questão.
Comment: @Cold olha meu fiddle ;)
Comment: @Renan desconheço dessa tag. Qual seria a compatibilidade dela com os browsers mais antigos, sei que no HTML5 ela rodaria tranquilamente, mas me pergunto quanto ao IE (antigo) e as versões MOBILE dos respectivos.
Comment: Sim, era mesmo aquela porção `CSS` que estava reclamando @Renan :P. Agora, será que 50% no `margin-left` coloca o texto no centro?Tentei escrever um texto maior e fica meio estranho. Recomendo o `text-align`.
Comment: @FredDutra É compatível com IE9. Acredito que com IE8. Todos os demais navegadores suportam, inclusive mobile (até onde sei). Esse campo era uma recomendação no HTML 4, e já faz parte do HTML 5. Olha a MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/fieldset#Browser_compatibility
Comment: @FredDutra, quanto a compatibilidade veja:
http://www.w3schools.com/tags/tag_fieldset.asp. Quanto a antiguidade e versões mobile, hum, terei de pesquisar mais.
Comment: @Cold vou deixar o CSS a cargo do OP, mas você tem razão. Margin 50% não centraliza.
Comment: Na paz @Renan. Pergunto porque no mundo web de hoje nós temos que nos preocupar com coisas mínimas. Só uma correção, se você souber o tamanho da sua div/texto, você poderá centralizar fazendo `left: 50%; margin:-valor da div`. Agora não me lembro se é margin-left ou margin-right :/
Comment: Acho que é margin: auto ou coisa do tipo. Se alguém souber, fique a vontade pra editar o Fiddle.

Formatos de table?


Pulling Zabbix Data into csv file

Question: Can't seem to find the correct syntax to get the request I need.
At this point I am able to connect to my Zabbix server via an API. I'm able to see all the data that I need which is confirmed by a simple print() function.
However, I am blanking at the way to get the data from the variable into a csv file.
from pyzabbix import ZabbiXAPI

        zapi = ZabbixAPI("example")
        zapi.login("example", "example")

    for hostInventory in zapi.host.get():
        print(hostInventory)

This then spits out about 500 lines of this approx - obviously redacted sensitive information:
{'hostid': 'xxx', 'proxy_hostid': 'xxx', 'host': 'xxx', 'status': 'x', 'lastaccess': 'x', 'ipmi_authtype': 'x', 'ipmi_privilege': 'x', 'ipmi_username': 'x', 'ipmi_password': 'x', 'maintenanceid': 'x',
'maintenance_status': 'x', 'maintenance_type': 'x', 'maintenance_from': 'x', 'name': 'x', 'flags': 'x', 'templateid': 'x', 'description': 'x', 'tls_connect': 'x', 'tls_accept': 'x', 'tls_issuer': 'x', 'tls_subject': 'x', 'proxy_address': 'x', 'auto_compress': 'x', 'custom_interfaces': 'x', 'uuid': 'x', 'inventory_mode': 'x'}

If I need to provide any further information please let me know. First time poster.
Comment: you have to learn standard module [csv](https://docs.python.org/3/library/csv.html) or popular `pandas` - and this problem has nothing to do directly with Zabbix.
Comment: @furas I understand its not a problem with zabbix itself, however i'm more looking for the solution or the missing code that will allow me to write the data once i have it. Everything that I seem to have tried doesnt seem to be working.
Comment: if you found something and it doesn't work then you should show it in question - so we wouldn't have to waste time for methods which don't work for you. OR maybe we could fix these methods - if we know what error they gives.
Comment: I do apologise, i can only give a rundown of what I have tried as I have scrubbed it everytime the outcome either resulted in syntax errors or doesn't get me what I needed. I can edit the main post with this information if you think that would be helpful
Answer: You have to learn standard module csv or popular pandas
(and this problem has nothing to do directly with Zabbix).
With pandas it should be much simpler.
import pandas as pd

data = list( zapi.host.get() )
df = pd.DataFrame(data)

df.to_csv('output.csv')

Eventually you may have to use own code to create dictionaries
data = []

for hostInventory in zapi.host.get():
    item = {"hostid": hostInventory.hostid, ...}
    data.append(item)

Comment: Thanks for that Furas, seem to have run into an issue where it tells me that the object of type set is not JSON serializable.

I have tried using JSONpickle to encode and decode this however the end result always ends in the same output.
Comment: so you may have to create own code to convert it to normal dictionary with strings: `{"hostid": hostInventory.hostid, ...}` and this will need to use `for`-loop to create list with all dictionares.

Pulling Zabbix Data into csv file