Making functions non override-able

Question: I know python functions are virtual by default. Let's say I have this:
class Foo:
    def __init__(self, args):
        do some stuff
    def goo():
        print "You can overload me"
    def roo():
        print "You cannot overload me"

I don't want them to be able to do this:
class Aoo(Foo):
    def roo():
        print "I don't want you to be able to do this"

Is there a way to prevent users from overloading roo()?
Comment: @pupeno Clean coding may require invariants that should not be broken by unintended overrides. In addition, your argument is only true in cases you have no access to the superclass code (such as in a 3rd party library).

More lengthy: Think of a complex Python project with more than one developer and you being the designer/code owner of a class that lives from certain invariants that your function implementations ensure. You want to avoid breaks of the invariants in lazy subclass implementations. If someone needs a change, he can do it in the superclass code or initiate a design discussion.
Comment: Why would you want such a thing? Are you afraid someone will override it and it won't work for them? it's their problem. But sometimes, they know what they are doing and they just need to do it. I've spent three days workaround this kind of limitation in Java, in Python it was 20 seconds.
Answer: Python 3.8 (released Oct/2019) adds final qualifier to typing.
A final qualifier was added to the typing module---in the form of a final decorator and a Final type annotation---to serve three related purposes:

Declaring that a method should not be overridden
Declaring that a class should not be subclassed
Declaring that a variable or attribute should not be reassigned

from typing import final

class Base:
    @final
    def foo(self) -> None:
        ...

class Derived(Base):
    def foo(self) -> None:  # Error: Cannot override final attribute "foo"
                            # (previously declared in base class "Base")
        ...

It is in line with what your were asking and is supported by core Python now.
Have a look at PEP-591 for more details.
Comment: Note that it is not enforced at runtime, it requires a static type checker: 'It would be possible to have the `@final` decorator on classes dynamically prevent subclassing at runtime. Nothing else in `typing` does any runtime enforcement, though, so `final` will not either.'
Comment: A shame there is no way to have two accepted answers :)
Comment: As a long-time JVM developer lately venturing into Python territory, it's quite amusing reading these old questions on SO, where the oldest comments are strongly against the need of such a feature. Fast-forward five years and it has been added to the language. I guess it's just another case of programming languages converging in every aspect...
Answer: You can use a metaclass:
class NonOverridable(type):
    def __new__(self, name, bases, dct):
        if bases and "roo" in dct:
            raise SyntaxError, "Overriding roo is not allowed"
        return type.__new__(self, name, bases, dct)

class foo:
    __metaclass__=NonOverridable
    ...

The metatype's new is called whenever a subclass is created; this will cause an error in the case you present. It will accept a definition of roo only if there are no base classes.
You can make the approach more fancy by using annotations to declare which methods are final; you then need to inspect all bases and compute all final methods, to see whether any of them is overridden.
This still doesn't prevent somebody monkey-patching a method into a class after it is defined; you can try to catch these by using a custom dictionary as the classes' dictionary (which might not work in all Python versions, as classes might require the class dictionary to be of the exact dict type).
Comment: i would hate you, if i had to use your class
Comment: Couldn't you provide your method as a descriptor that prevented itself from being removed or overriden? Presumably descriptors are only triggered on attribute lookup and not if it they are looked up directly in the class dictionary.
Comment: It requires new-style classes, i.e. Python 2.2 or later.
Comment: How can we make `NonOverridable` class generic enough that it can be used by different classes ? Currently It seems tightly coupled to class `foo` only.
Comment: It's not coupled to `foo` (though it does have a  hard-coded list of methods that can't be redefined) at all; `NonOverridable` can be used as the metaclass for any class (up to the usual caveats about metaclasses not composing).
Answer: Since Python has monkey patching, not only can you not make anything "private".  Even if you could, someone could still monkeypatch in a new version of the method function.
You can use this kind of name as a "don't go near" warning.
class Foo( object ):
    def _roo( self ):
       """Change this at your own risk."""

That's the usual approach.  Everyone can read your source.  They were warned.  If they boldly go where they were warned not to go, they get what they deserve.  It doesn't work and you can't help them.
You can try to make this intentionally obcure with inner classes and "hidden" implementation modules that are called by the "private" methods.  But... everyone has your source.  You can't prevent anything.  You can only advise people of the consequences of their actions.
Answer: def non_overridable(f):
    f.non_overridable = True
    return f

class ToughMeta(type):
    def __new__(cls, name, bases, dct):
        non_overridables = get_non_overridables(bases)
        for name in dct:
            if name in non_overridables:
                raise Exception ("You can not override %s, it is non-overridable" % name)
        return type.__new__(cls, name, bases, dct)

def get_non_overridables(bases):
    ret = []
    for source in bases:
        for name, attr in source.__dict__.items():
            if getattr(attr, "non_overridable", False):
                ret.append(name)
        ret.extend(get_non_overridables(source.__bases__))
    return ret

class ToughObject(object):
    __metaclass__ = ToughMeta
    @non_overridable
    def test1():
        pass

# Tests ---------------
class Derived(ToughObject):
    @non_overridable
    def test2(self):
        print "hello"

class Derived2(Derived):
    def test1(self):
        print "derived2"

# --------------------

Comment: Could you explain your Solution a Bit Further?
Answer: Late to the party but not all python methods are "virtual" by default - consider:
class B(object):
    def __priv(self): print '__priv:', repr(self)

    def call_private(self):
        print self.__class__.__name__
        self.__priv()

class E(B):
    def __priv(self): super(E, self).__priv()

    def call_my_private(self):
        print self.__class__.__name__
        self.__priv()

B().call_private()
E().call_private()
E().call_my_private()

Blows due to name mangling:
B
__priv: <__main__.B object at 0x02050670>
E
__priv: <__main__.E object at 0x02050670>
E
Traceback (most recent call last):
  File "C:/Users/MrD/.PyCharm2016.3/config/scratches/test_double__underscore", line 35, in <module>
    E().call_my_private()
  File "C:/Users/MrD/.PyCharm2016.3/config/scratches/test_double__underscore", line 31, in call_my_private
    self.__priv()
  File "C:/Users/MrD/.PyCharm2016.3/config/scratches/test_double__underscore", line 27, in __priv
    def __priv(self): super(E, self).__priv()
AttributeError: 'super' object has no attribute '_E__priv'

So if you want to get some help from the language to prohibit people from overriding a bit of functionality that you need inside your class this is the way to go. If the method you want to make final is part of your class API however you are stuck with the comments approach (or metaclass hacks). My personal opinion is that a final keyword is very useful for inheritance - as you can avoid the class breaking in insidious ways when overridden (consider using the "final" method in super implementation for instance and then someone overrides - boom, super broken) - and for documentation purposes (no docs are better than a compile time syntax error) - but Python's dynamic nature would not allow it and hacks are fragile - so add a docstring:
"""DON'T OVERRIDE THIS METHOD"""

Comment: Seems I wasn't the only to want a final keyword actually - https://stackoverflow.com/a/58939735/281545 :)
Answer: If you'd like to enforce this at runtime but avoid messing with metaclasses, you can use __init_subclass__ (added in Python 3.6):
class Base:
    def __init_subclass__(cls) -> None:
        if cls.roo is not Base.roo:
            raise Exception('Oh, noes!  Cannot override Base.roo!')

This is a very handy class method which gets called for each subclass of Base (i.e., not for Base itself) at class creation time.

Making functions non override-able


Error when extracting data from firebase into flutter app

Question: I want to ask for some help or advice.
I have a simple form which stores data in Firebase.
I created a new page where I want to display that information. I am using StreamBuilder to display the data for the logged user.
return Scaffold(
  appBar: AppBar(
    title: const Text("Your upcoming appointments"),
  ),
  body: SafeArea(
    child: Column(
      children: [
        StreamBuilder(
          stream: FirebaseFirestore.instance.collection('client_bookings_doc').where('email', isEqualTo: currentUser.currentUser!.email).snapshots(),
          builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
            if (snapshot.hasData) {
              return ListView.builder(
                itemCount: snapshot.data!.docs.length,
                shrinkWrap: true,
                itemBuilder: (context, i) {
                  var data = snapshot.data!.docs[i];
                  print(data['email']);
                  return Text(data['email']);
                },
              );
            } else {
              return const Text("error");
            }
          },
        ),
      ],
    ),
  ),
);

I don't understand why I am getting that error:

W/GooglePlayServicesUtil( 3777): .................. requires the Google Play Store, but it is missing.
E/GooglePlayServicesUtil( 3777): GooglePlayServices not available due to error 9
W/Firestore( 3777): (24.4.2) [GrpcCallProvider]: Failed to update ssl context: com.google.android.gms.common.GooglePlayServicesNotAvailableException

I was following a few tutorials online and they both work fine.
Any help will be appreciated.

Update: I changed the device to google pixel 2 and now the error is

W/ProviderInstaller( 5334): Failed to report request stats: com.google.android.gms.common.security.ProviderInstallerImpl.reportRequestStats [class android.content.Context, long, long]
Comment: Would you please share the firestore document picture with us?
Comment: comment is updated now
Answer: This query doesn't match the document structure in your screenshot:
FirebaseFirestore.instance
  .collection('client_bookings_doc')
  .where('email', isEqualTo: currentUser.currentUser!.email)
  .snapshots()

There is no collection client_bookings_doc in your screenshot. Instead there is a root collection client_bookings with a document client_bookings_doc and then a subcollection again named client_bookings.
If you want to query across all client_bookings collection, you can use a collection group query:
FirebaseFirestore.instance
  .collectionGroup('client_bookings') //
  .where('email', isEqualTo: currentUser.currentUser!.email)
  .snapshots()

Comment: Thank you! I fixed my query now, however i still got that eorro: W/DynamiteModule(12066): Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found.
I/DynamiteModule(12066): Considering local module com.google.android.gms.providerinstaller.dynamite:0 and remote module com.google.android.gms.providerinstaller.dynamite:0
W/ProviderInstaller(12066): Failed to load providerinstaller module: No acceptable module com.google.android.gms.providerinstaller.dynamite found. Local version is 0 and remote version is 0.


how to set command line for electron

Question: I need a the electron start with transparent window in linux, the documents say I need put --enable-transparent-visuals --disable-gpu in the command line. Is there a way to pass the command line args in the program not in the  terminal command line.
like this:
electron . --enable-transparent-visuals --disable-gpu

I need when I run
electron .

the args have set in the program.It means I just double click the bin file and the args are OK. Don't need to pass them manually.
Answer: You can put them in the main script of the application (main.js), before the 'ready' event of the app module is emitted, like so:
const electron = require('electron')
// Module to control application life.
const app = electron.app
app.commandLine.appendSwitch('enable-transparent-visuals');
app.commandLine.appendSwitch('disable-gpu');

app.on('ready', () => {
  // Your code here
});

For a list of other command line switches, you can go here
Comment: It not works very well. Nothing display. My distribution is Linuxmint 18
Comment: I couldn't find any indication that this would behave differently in Linuxmint. Make sure you add the arguments at root level of the main script, just like the `app` constant, and not inside a function or something, and make sure it's before the `ready` event. Also, in case you do some sort of platform check like `if (process.platform !== 'linux') `, please make sure your code is correct. I edited my code to be more like the [electron quick-start example](https://github.com/electron/electron-quick-start/blob/master/main.js). For more information, please post your code.
Comment: Also, check the css
Comment: This is my code, change from the electron-quick-start.
[electron example](https://github.com/zephyrzoom/test/tree/master/electron)
Comment: On my side it does display 'Hello world!' in black text with transparent background (click the taskbar icon to check). I don't see any css in your code. Keep in mind that if you don't set a background color, the window will be invisible. Have you tried playing around with your css? Maybe something like: `body{
    background-color: rgba(0, 0, 0, .5);
}`
Comment: I just want the transparent background. It displays nothing in my linux. :(
Comment: It may be my OS problem. Thank you all the same.
Comment: Ok, but I seriously doubt this is an OS issue. The text itself is *very* easy to miss, and thus it would seem like it displays nothing. You didn't really answer my previous question: *Did you or did you not try to add a background-color via a .css stylesheet like I suggested*?
Comment: I tried what you told me, and it works. Interesting. I don't know why?
Comment: This is fine. but the alwaysOnTop is not work. while I add `mainWindow.setAlwaysOnTop(true)` it works.
Comment: Like I said, if no background is set, the window will be completely transparent => 'show nothing'. As for the AlwaysOnTop, that's a separate question and it may be an internal issue, as related issues have been reported before (eg. [here](https://github.com/electron/electron/issues/2097) ). Since what I suggested worked, don't forget to mark the answer as 'accepted'. Thank you!

how to set command line for electron


How to filter a dataframe and update selective rows for a particular cell

Question: I want to update a particular column in DF when certain condition on another column passes . this is what I am trying but it gives error
train[train['Rain]'==1]['Price']=100

So for all rows when Rain column is 1 , for that Row the price column should be set to 100 , could you give an example of using it via where and without where fucntion as well.
Answer: You could use below three options
train.loc[train['Rain'] == 1, ['Price']] = 100

OR
import numpy as np
train['Price'] = np.where(train['Rain'] == 1, 100,train['Price'])

OR use the 'at' operator
train.at[train['Rain'] == 1, ['Price']] = 100

Hope that helps
Answer: Use Dataframe.loc
train.loc[train['Rain'] == 1, ['Price']] = 100


Create a json file from other json files

Question: I have 2 json files:
User.json:
<code>    {
         "users": [
           {
              "username": "User1",
              "app": "Git",
              "role": "Manager"
           },
           {
              "username": "user2",
              "app": "Git",
              "role": "Developer"
           }
          ]
 }
</code>
App.js:
<code>{
     "apps": [
       {
          "appName": "Git",
          "repo": "http://repo1..."
       },
       {
          "appName": "Jenkins",
          "repo": "htpp://repo2..."
       }
      ]
    }
</code>
I'm working on an Angular-CLI apllication for the first time and I want to generate a new json file called infos.json containing the content of the 2 files (User.json + App.json) without redundancy.
Expected file:
Infos.json:
<code>{
         "infos": [
           {
              "username": "User1",
              "appName": "GIT",
              "role": "Manager",
              "repo": "http://repo1..."
           },
           {
             "username": "User2",
             "appName": "Jenkins",
             "role": "Developer",
             "repo": "htpp://repo2..."
           }
          ]
        }
</code>
How can I do it in my Angular-CLI app ?
Comment: angular cli dont do that kind of task ...you need to code for it
Comment: you have this web pack plugin check this merge-jsons-webpack-plugin https://github.com/tettusud/merge-jsons-webpack-plugin
Answer: You can do this by creating task in task runner. Some of the task runner are Grunt, gulp etc.
Grunt and gulp have different inbuilt packages.
Grunt:  npm i grunt-merge-json
Gulp: npm i gulp-merge-json
If you are using web-pack so there is a inbuilt package called merge-webpack-plugin
Comment: Thank you, I did it with gulp-merge-json :)
Comment: @Develo55 That's great. Happy coding !


Find a polynomial with roots from another

Question: I apologize if the title is not complete enough.
Let $f(x) = x^3 - 7x - 3$ and $g(x) = x^3 - 4x -5$ be polynomials with complex coefficients.
I need to find a polynomial of degree $3$ with roots $g(x_1)$, $g(x_2)$, and $g(x_3)$, where $x_1$, $x_2$ and $x_3$ are roots of $f$. The coefficient in front of $x^3$ must be $1$.
I can't find roots of $f$.  Any suggestions?
Comment: Are you familiar with (elementary) symmetric polynomials? If not, then this exercise is a bit cruel IMHO.
Comment: A rather similar question: (http://math.stackexchange.com/q/1415302)
Answer: Suppose $\;a\;$ is a root of $\;f\;$ , so
$$0=f(a)=a^3-7a-3\implies a^3=7a+3\,,\,\,\text{so}\;$$
$$\; g(a)=a^3-4a+5=7a+3-4a+5=3a+8$$
Thus, if the roots of $\;f\;$ are $\;a,b,c\;$ , then the wanted polynomial is
$$h(x)=(x-3a-8)(x-3b-8)(x-3c-8)=$$
$$=x^3-(3a+8+3b+8+3c+8)x^2+(9ab-24(a+b)....$$
Now, if you know the relations between coefficients of a polynomial and its roots, then for example:
$$a+b+c=0\implies3a+8+3b+8+3c+8=24$$
and also
$$ab+ac+bc=-7\;,\;\;abc=3$$
You may want to google "Vieta's Formulas"
Comment: I somehow missed that $a\mapsto 3a+8$ relation, and it became hairy. Good job, DonAntonio!


Content Type vs. Taxonomy | Example TV Series

Question: As this is my first post here I don't know if I do everything right. Please forgive me.
So, my plan is to build a website with many categories and these than contain posts. To explain the stuff in the easiest way I decided to use Series and Episodes.

Serie A:

Episode 1
Episode 2
Episode 3

Serie B:

Episode 1

For my use I also want to be able to decide what exactly an episode is. For example is it an normal one or just a 20 minute special and should be displayed like this:

Serie A:

Author:
Year:
(more stuff here)
Episodes: (Headline)

E1 (Link to this Episode)
E2 (Link to this Episode)

Special Episodes: (Headline)

E1 (Link again)
E2 (Link again)

The problem here is that I don't know if I should create this with Content Types or Taxonomy.
A) So one Content Type for Serie and another one for Episodes. Both with the needed fields. But the problem is here I don't know how to join/connect them properly.
B) Creating a Taxonomy called "Series" and adding all Series into it. Than a Content Type "Episodes" with setting a Tag to connect the Episode to the right Series. The problem I could get here is for example when adding something like genre. A Taxonomy would get a list of Genres like Action, Comedy and so on.
Another point would be accessibility. It should be possible to search for Series include/exclude genres and also searching for fields like year, episode-count of a series.
At last is it possible to create Custom Types where for example a javascript is loaded in the background that parses text from a input text area?
I hope you understand my goal with this example and can tell me the proper way. Thanks for everything.
Answer: I would do it the A) way and use Entity reference module to "link" episodes to series. That way you can use watever fields you want in your content types (including taxonomy for genre for example).

The Entity Reference Module is used to relate entities (nodes, terms,
  users, etc...) to one another.

After that, you can display content types with Views showing Series with list of episodes.
Answer: I'm assuming that the series and episode are going to have fields and you need to link series and episodes together. Both A and B are technically correct approaches to your problem, but I'd lean more towards approach A(creating a content type for both series and episodes). I'll explain why in a moment.
The series and episode can be linked using the entity reference module as mentioned in an earlier answer. To add more detailx, you would add a multivalue entity reference field to series content type and add all your episodes there.
If you want to store more metadata for the series-episodes link(in Drupalspeak, make that relationship fieldable), you can create a series-episode relation and add fields to that using the relation module.
You can as well make episodes as a taxonomy term and add an entity reference field pointing to episodes(approach B), but series are a separate entity in itself and wouldn't exactly map to a taxonomy term in the grand scheme of things. They are better off as nodes(approach A).

At last is it possible to create Custom Types where for example a
  javascript is loaded in the background that parses text from a input
  text area?

Not sure I understand this right. You want to parse some semi-structured text and create series and episode nodes out of that?
Comment: Thanks for your answer and help.

Example:
I want to add an episode with the fields duration, summary and some links (wikipedia)
And this should work like this:
A textarea input field: I paste all my information I have structured with a self definied scheme (description:foobar link1:wikipedia.org duration: 50)
This area will be parsed with JS and below the textarea are the input fields for description, links, duration. These input fields should than be automatically filled with the parsed text.

Maybe I should create my own module to insert episodes? Also looking into views should help me.
Comment: Maybe a little easier to understand:
A semi automatic input page where someone only has to select the series and can add/edit an episode. But I think a modul is the best go to create that.
Answer: Have a look at field_collection module. By default a collection (contenttype episode) is part of an entity (series) and can be managed as one bundle.
Answer: There many ways to implement this as other guys gave you a few solutions. Selecting the right choice deponds on how good you are at Drupal, which fields do you want to filter on, ... .
Searching and filtring on field collection is an almost complex process. The group views by fueld collection is an example of it. But it has the advantage of easily inserting the content. By this moduleva package of fields come together as a one unique field. It is nice.
Using entity module is very good, by this module you will need to create two content types, and link them using an entity field. Searching and filtering is easier than field collection solution.
You can also use Entity View Attachement module which assigns a view to a node. In this case nodes are Series and you assign a View of episoded to them
Anyway I recommend you to use entity module because of it's flexibility in filtering, searching, new requirements in the future and ....


Drupal::config to access Site default timezone

Question: Like the title says, I want to access the sites default timezone.
Guess
Drupal::config('system.date')->get('timezone')['default']

is the right function.
I really would love to know how to use the config-function. Is there a list with all the configs, settings or variables that can be called?
Whats the logic behind the keywords "system.date"? Is there a way to discover keywords by looking at the yml config structure? Can all values of them be returned?
Answer: Inspect the system.date configuration
You can navigate to the /admin/config/development/configuration/single/export path and inspect the configuration types and values. The default timezone is of type simple configuration and system.date is the cofiguration name.
Inspect all the configuration values
Go to /admin/config/development/configuration/full/export, here you can export all the active configuration, you can download and extract the bundle and then inspect the individual files. If you have the drush command line tool, you could use the command drush config:export.
Official Documentation
You should read the official documentation to better understand the logic behind the Configuration API. These are some links:
Simple Configuration API | Drupal 8 guide on Drupal.org
Configuration API | Drupal 8 guide on Drupal.org
Configuration API overview | Drupal 8 guide on Drupal.org


H2 in memory Database doesnt create table when starting application

Question: i have an issue where my sql-statements, doesnt get created when i start my application.
My yaml-file looks like that:
Spring:
  datasource:
    url: jdbc:h2:mem:testdb;MODE=h2;LOCK_MODE=0;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'createTable-0.sql';
    username: sa
    password: sa
    driverClassName: org.h2.Driver
  h2:
    console.enabled: true
    console.path: /h2
  jpa:
    properties:
      hibernate:
        dialect: org.hibernate.dialect.H2Dialect

However when i start my application, no table is created:
H2
My Projectstructure looks like that:
Project
I tried to change the path of the createTable sql or changed some configurations on the yaml file, however it didnt worked and still no table was created when starting up the app.
I know that the sql is correct, since manually pasting it in the h2 browser , the tables are created correctly.
Answer: You seem to be missing the following:
spring.jpa.hibernate.ddl-auto=update`

Try this and do let know if it works
Comment: Done it, but the table didnt get created still.


UINavigationController to UITabBarController

Question: The first part of my app is a Sign in section with built in Navigation controller. When the sign up section is completed and a new user is created I would like to proceed into a UITabBarController and will add seperate navigation controllers for each tab. Right now when sign up is complete and my UITabBarController is presented it still shows the UINavigationController from the first section of my app. How do I exit the UINavigationController once I enter the new UITabBarController?

And here is the code
import UIKit

class SignUpSecondViewController: UIViewController, BEMCheckBoxDelegate {

@IBAction func completeButtonAction(_ sender: Any) {

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewController(withIdentifier: "NewTabBarViewController") as! UIViewController
    // Alternative way to present the new view controller
    self.navigationController?.show(vc, sender: nil)
}

Answer: You should better use
self.navigationController?.present(vc, animated: true, completion: nil)

Generally there is no need for signup once main tabbar controller is up. In this case you can do this which will remove signup from memory.
let appDelegate = UIApplication.shared.delegate as! AppDelegate)
appDelegate.window?.rootViewController = vc


Como pesquisar qualquer parte da string com mysql

Question: Olá, eu uso esta forma para pesquisar no MySQL string%, porém em uma frase "teste um dois três" se eu usar ste% ele nao vai retornar a frase, como eu poderia pesquisar se contém dentro da frase?
Comment: Tente utilizar  `%ste%`
Comment: Qual a intenção de por o % no final da string de busca, se o que varia no seu exemplo é o começo? O % é o coringa, se quer achar coisas que mudam dos dois lados, tem que por % dos dois lados, como disse o @Maurivan. No seu caso, se procurar "test%" vai encontrar, pois começa com "tes". Se procurar por  "%rês" também, pois termina com "rês" a frase. Note a diferença de posição do %
Comment: @Bacco Mas por exemplo, em uma string "Wolverine", quero que ao pesquisar `veri` já resulte em Wolverine, como posso fazer isso ??
Comment: LucasCarezia exatamente o que o @Maurivan já disse,  `campo LIKE "%veri%"` pondo um % antes e um % depois
Answer: Já que o que você quer não começa com ste não adianta você realizar um select assim ste% pois ele irá te retornar tudo que começar com ste seguido de qualquer coisa.
Para poder pegar tudo que contenha apenas ste o seu select terá que ter %ste%
select coluna from tabela where coluna like %ste%


How to edit the content page fields column in the admin section?

Question: In the admin section --> Content menu displays all the contents of the site.

I want to have options (or atleast to know where I have to change) for adding and removing the columns in the content section.
Answer: You can use hook_form_FORM_ID_alter() and do your changes inside that.
Example:
<code>function YOUR_MODULE_form_node_admin_content_alter(&$form, &$form_state, $form_id) {
 // YOUR CUSTOM CODE GOES HERE
}
</code>
Comment: Thanks I am new to drupal 7, I try it and update my comments.
Answer: I would say the easiest way is to install the admin views module (and its dependencies).
That module will replace Drupal core's implementation of that listing (and the taxonomy, comment, user and book listings) with a views based one.
You can then edit the 'Administration: Nodes' view and change the columns ('Fields' in the Views UI) as you see fit.
Alternatively, you could create own custom view that uses the admin/content path, to override the core listing. That would have the same effect but would be a little extra effort in setting up the view.
Comment: This is the solution, which is suggested to me from my colleagues. Thank you.


$T:x\to\phi_x$ is a linear isometry from $X$ into $C(\Omega)$.

Question: Let $X$ be a normed linear space and $\Omega := \{f \in X':||f||=1\}$. For each $x\in X$, let $\phi_x: \Omega \to \Bbb K$ be defined by $\phi_x(f)=f(x), f\in \Omega$.  Show that $\phi_x \in C(\Omega)$ for every $x\in X$ and the map $T:x\to\phi_x$ is a linear isometry from $X$ into $C(\Omega)$.
Need some hints for the problem.
Answer: From Hahn-Banach Theorem we have that $$||x||=\sup\{|f(x)|:f \in X^*,||f|| \leq 1\}$$ for an arbitrary $x$ in a normed space $X$

Thus $$||x||=\sup\{|f(x)|:f \in X^*,||f|| \leq 1\}=$$ $$\sup\{|\phi_x(f)|:||f|| \leqslant 1\}=||\phi_x||=\sup\{|\phi_x(f)|:||f||=1\}$$

I hope this helps.


Stochastic modelling, distribution and ergodicity of a particular time series with a given finite history

Question: Let $\Omega$ be a sample space. A stochastic process $\{Y_t\}$ is a function of both time $t \in \{1, 2, 3, \ldots\}$ and outcome $\omega \in \Omega$.

For any time $t$, $Y_t$ is a random variable (i.e. a function from $\Omega$ to the space of real numbers $\mathcal{R}$).
For any outcome $\omega$ the series $y(\omega)$ is a time-series of real numbers: $\{y_1(\omega), y_2(\omega), y_3(\omega), \ldots \}$

We can model a particular time series with an observed history $(y_1,\dots,y_t)$ as a realization of a stochastic process.
It is quite common in practice* that

we are only interested in a particular observed series (corresponding to a particular $\omega_0\in\Omega$) and its future or historical development and
we do not care about the hypothetical other realizations of the same stochastic process (corresponding to $\omega\in\Omega\backslash\omega_0$).

I.e. we want to make inference and predictions about $\{y_t({\omega_0)}\}$ rather than $\{Y_t\}$ and/or $y_{t+1}({\omega_0)}$ rather than $Y_{t+1}$. But then it seems to me we cannot talk about the distribution of $\{y_t(\omega_0)\}$ (a realization of a random process) or $y_{t+1}(\omega_0)$ (a realization of a random variable) or any derived features such as moments. Yet time series analyses are full of expected values (conditional or unconditional), variances (cond. or uncond.) and the like. And then there are discussions of ergodicity which again seem irrelevant if we only have a single, fixed $\omega_0$. I am confused by this. How do I think about it?
*An example: the daily closing share price of Tesla. We can obtain the historical time series $(y_1,\dots,y_t)$ from a financial database. We may want to discover patterns in the series and extrapolate them into the future, perhaps with an aim of investing in Tesla's share and making money or (more modestly) assessing and managing risk. We do not care about any other realization from the data generating process (DGP) has generated Tesla's daily share price, as we do not believe there exists another company the share price of which is governed by the exact same laws.
A counterexample: second-by-second altitude of a helium atom in a closed container filled with pure helium. Roughly, every atom is the same, and the laws that govern atom A govern also atom B and all the other atoms in the container. If we built a model based on the historical time series of atom A, we could still be interested in generalizing across atoms and saying that the model applies to each of them. Ergodicity may then naturally be relevant.

A follow-up question: "Stationarity and ergodicity of a process conditional on a finite trajectory".
Answer: Your question misunderstands how conditioning works in measure-theoretic probability
I think you are letting the complexity of the notation for a stochastic process get in the way of intuitive understanding of the essence of your question (let alone its answer).  Remember that each outcome $\omega$ in the abstract probability space is essentially indexing a full stipulation of the process which gives the outcome of all the values in the infinite series.  So you are wrong to state that an observed vector $(y_1,...,y_n)$ for a finite number of time values corresponds to a particular outcome.  Because the observed vector is just a part of the infinite series, it must correspond to an infinite set of possible outcomes in the abstract sample space --- specifically, observation of that vector is the event:
$$\mathcal{E}_* \equiv \mathcal{E}_*(\mathbf{y}_n) \equiv \{ \omega \in \Omega | Y_1(\omega)=y_1, ..., Y_n(\omega)=y_n \}.$$
It appears that all you are trying to do here is to understand what happens when you condition on observing this vector of values (i.e., when you condition on this event).  You say that it is quite common practice to condition on a single outcome $\omega_0 \in \Omega$, but I see no evidence that this is practiced at all, let alone being common.  Conditioning on a single outcome would of course reduce the whole problem to a deterministic series (in principle a known series) and so it would remove probability from the matter entirely.  That is not how the conditioning is done.
Okay, so what is actually done here?  Rather than reducing things down to a single outcome, the observed vector of values reduces things down to the conditioning event $\mathcal{E}_*$ (which still contains an infinite number of outcomes), and we proceed using conditional probability based on this observed event.  This is no different to any other application of conditional probability --- by conditioning you reduce the sample space and you then get a new probability measure that gives the conditional probability of any event of interest.  Formally, if you start your analysis in the probability space $(\Omega, \mathscr{G}, \mathbb{P})$ the new conditional probability space is $(\mathcal{E}_*, \mathscr{G}_*, \mathbb{P}_*)$ where the conditional sigma-field and probability measure satisfy:
$$\mathscr{G}_* = \{ \mathcal{E} \in \mathscr{G} | \mathcal{E} \subseteq \mathcal{E}_* \}
\quad \quad \quad \quad \quad
\int_\mathcal{A} \mathbb{P}_* d \mathbb{P} = \mathbb{P}(\mathcal{A} \cap \mathcal{E}_*) \quad \text{for all } \mathcal{A} \in \mathcal{E}_*.$$
In regard to the basic mechanics of conditioning, it really doesn't matter whether you are dealing with an application that is "repeatable" in the frequentist sense or not.  If you are already at a point where you are applying probabilistic analysis to it then you have already made the decision that this framework is philosophically appropriate (and you are right to do so, since probability can be given an epistemic interpretation in any case).  So if you are looking at the price of Tesla shares over time (and noting that there is only one Tesla) then this is not mathematically any different to if you are looking at some hypothesised process where the experiment generating the data is "repeatable" in the classical frequentist sense.  (Of course, you are making conditional inferences about a single series, not an inference about some parallel "repeated" experiment, which would be different.)
Once you clear out the confusion relating to how conditioning works in measure-theoretic probability, you are in a good position to get to the essence of your questions about other properties such as ergodicity.  It appears that you want to know if ergodicity (and maybe other properties) still hold for the remainder of the series (the unobserved part) once we condition on observing a vector of values.  I won't get into the answer to that here, since I think the focus of your question is just to clear up the confusion around how conditioning works in measure-theoretic probability.
Answer: There can be more than one $\omega\in\Omega$ that may have generated the finite-length observed trajectory $(y_1,\dots,y_t)$. Let us collect all such $\omega$s into an $\Omega_0\subset\Omega$. By referring to the distribution of $\{Y_t\}$ or $Y_{t+1}$, are we implicitly considering its conditional distribution, i.e. the distribution over the subset $\Omega_0$. The distribution is proper if $\Omega_0$ contains more than a single element.
I am not sure how to think about ergodicity. Perhaps it is still relevant within $\Omega_0$ (as long as it contains more than a single element) even if we are not interested in $\Omega\backslash\Omega_0$.
Comment: @ChristophHanck, in case you might be interested: I have succeeded in soliciting answers from Ben both to this and to the follow-up question.
Comment: I am not sure if the answer is correct (or even approximately correct). I have been thinking about the topic for a little while and have decided to write my thoughts down (both the question and the answer) to get some feedback. Hopefully I will learn something from this.
Comment: My disorganized two cents: I think of (mean) ergodicity (well, that is not too deep, looking at definitions) as a kind of LLN for time series. I.e., can we infer moments from sample quantities of the single trajectory we have in practice? Clearly, if the mean changes over time (nonstationarity) this will be difficult. Had we drawn another $\omega$ (another "state of the world") the mean of the process would still be the same, though. For a given $\omega$, $Y_t$ still is a r.v. for a given $t$, so that forming expectations about future values still seems well-defined.
Comment: @ChristophHanck, my rough intuition about ergodicity seems to be in line with yours. However, my impression is that $\omega$ is the only source of randomness behind the stochastic process $\{Y_t\}$. Therefore, while $Y_t$ is a random variable based on an experiment producing diffent $\omega\in\Omega$, $y_t(\omega)$ is not a random variable anymore (just a realization) when $\omega$ is fixed. According to you, what makes $Y_t$ a random variable for a fixed $\omega$? What is the additional source of randomness?
Comment: Hm, I am indeed not sure whether there is an "additional" source of randomness - if a SP is a "family of random variables" (https://en.wikipedia.org/wiki/Stochastic_process), then, at a given $t$, we get a r.v. $\omega$ might then be thought of as entering through "where" the process was "born" - say, the initial condition of an AR process.


Sequence to Sequence models only returning the same response?

Question: I've tried out my code just to make sure it works on a dataset of 100 input and output sentences. Turns out that no matter what I insert, the trained model only responds with either 1 of 2 phrases.
I convert the sentences into one-hot vectors, and my matrix is very sparce, in other words, I have some very long sentences and some very short ones, and the short ones are padded with zero vectors. I also do not implement attention and beam search.
Is this because of the incredibly small dataset, or does that normally not occur?
Comment: It's impossible to answer this without seeing the data and running reproducible code.
Answer: Sounds like small and biased dataset to me, which assigns high biases to those 2 neurons on output layer. Take a look at the biases in the last layer.


Wilcoxon signed rank test (3 related samples) with or without bonferroni correction?

Question: I have ordinal data from 3 related samples. First i conducted a Friedman test to know if there were differences between at least two samples. Next I conducted a Wilcoxon signed rank test to know between which of the 3 samples there were differences and i generated 3 possibles pairs.
However i don't know if i need to apply Bonferroni correction and basically compare my Asymp Sig (2 tailed) with P=0.05/3 instead of 0.05, or if i should mantain a p=0.05 to know if i accept or reject my null hypotesys.
Could anyone help me to clarify this question?
Thank you very much.
Comment: You should probably clarify this in your question
Comment: One possibility is to consider the [Quade](https://stats.stackexchange.com/questions/211453/why-run-a-post-hoc-wilcoxon-signed-rank-test-after-friedman-test-why-not-just-s) test or the Friedman test (which is more akin to the sign test than the signed rank but is also suited to multiple related samples)
Comment: First I conducted a Friedman test, but that only tells me that differences exist at least between two samples. I need to conduct a Post-hoc to know between which samples there are differences, right?
Comment: Thanks for the input. Can you help me knowing what you know now about my analysis?
Comment: I think you'll get better answers on post-hoc testing from others.
Answer: It depends on what kind of false discovery probability you wish to control.
Keeping p=0.05 means you allow 5% probability of false discovery (e.g. rejecting null hypothesis while it shouldn't be rejected) in each comparison.
Taking Bonferroni correction means that you allow 5% probability for at least one false discovery.
If the latter is what you deserve, I'd recommend using some other correction (eg. Holm), because Bonferroni is very conservative. It actally dumps false discovery probability far below 5%. But, on the other hand, with 3 comparisons only this effect is not very big.
Holm correction:
First, order your p-values in incereasing order. Let $p_1$ be the smallest and $p_n$ the largest one.
Then compare each $p_i$ with $$\frac{\alpha}{n-i+1}$$
So, in your case ($n=3$):
the smallest p-value ($p_1$) is significant if it's lower than 0.05/3,
the middle one ($p_2$) is significant if it's lower than 0.05/2,
and the largest ($p_3$) is significant if it's lower than 0.05.
Plus, some people say that if you find $p_i$ significant you should also consider all lower p-values significant. So according to them, if, for example, $p_3$ is significant, while $p_2$ is not, you should also treat $p_2$ as significant.
Comment: Thank you for your answer. I've never heard about Holm correction. How i can easily apply it, could you please tell me?
Comment: See edited answer
Answer: There are some post-hoc tests devised for Quade and Friedman tests.  The best place I can refer you to is the documentation and vignette for the PMCMR package in R. The methods there are simply called "Friedman – post-hoc test after Nemenyi", "Friedman – post-hoc test after Conover", and "Quade – posthoc tests".  Having played with them a little bit and here, they seem to give reasonable results, but I can't speak to their statistical qualities.


Azure SDK 2.0 Upgrade button not available

Question: I installed the latest Azure SDK 2.0 on my development machine, but can't find the "Upgrade" button to upgrade my current project to the latest SDK. Googling how to upgrade show that previous upgrades had an "upgrade" button when going to the Cloud Project -> Properties -> Application Tab and the upgrade button will be next to the Windows Azure Tools Version: October 2012.
Why wouldn't I see the Upgrade button? If I want to manually upgrade my project, what would the process of doing so be?
The current version of the SDK used is SDK 1.8
Comment: I just tried it in VS 2012 (Premium edition) and I see an "Upgrade" button when going to the Cloud Project -> Properties -> Application Tab. What version of VS are you using? Also what's the .net version used by your cloud service projects?
Answer: It turns out when I opened the Web Platform Installer to install the latest SDK, the item that said "...SDK... - Latest" wasn't the latest, but the February 2013 (1.8.1) update instead of the 2.0 SDK. I ended up uninstalling all Azure SDK's, restarted the machine and tried again.
This solved the issue and I was presented with a new option to install the 2.0 SDK. The trick was to uninstall all (including any PowerShell cmd's) Azure related products I could find in Product and Features (Win 8).
Comment: Have you done anything else? I removed 1.9, reinstalled 2.0 SDK and restarted my machine, but still no luck. Did you also uninstall other Azure related products (e.g. Azure Storage Explorer, Azure Management Studio)?
Comment: I just removed all the Azure related components developed by Microsoft. Applications developed by other companies I left untouched.


How to set auto height in jquery colorbox?

Question: I am trying to open colorbox onclick. It is ok. But now i want to make the colorbox height set to auto (according to the height of the returned content height) and the scrollbar of the browser will be scrollable within the height of the colorbox content height. Here's my code
$('body').on('click', 'a.post', function(e) {
  e.preventDefault();
  $.colorbox({
    width: "850px",
    height: "600px",
    iframe: true,
    href:this.href
  });
});

Any help? (thanks in advance)
Comment: I have tried this part of code from colorbox site, but no solution
                            $('a.post').colorbox.resize();
Comment: If you want auto height, why is it set to 600px?
Comment: @andyb -- I have tried to do this without the height option, but then it gets about 30 to 40 px height. That is why....
Comment: What kind of content do you put there? Is the content already there when you initialize the control?
Comment: no. that content will come from another page
Comment: There is an `initialHeight` option that might help. Can you create a demo with [jsFiddle](http://jsfiddle.net) or [jsbin](http://jsbin.com/)?
Comment: Possible duplicate of http://stackoverflow.com/questions/10066938/jquery-and-colorbox-how-to-automatically-set-the-height-and-width-of-an-iframe
Comment: @andyb Sorry, As i am displaying data in the lightbox from another page, creating jsFiddle will be difficult.
Comment: i am trying to do the modal window just like pinterest.com. @anydb
Answer: You can try using Height via the height() method:
var objHeight=$(window).height()-100; // reduce 100, so that it will fit in the container

$.colorbox({
   width: "850px",
   height: objHeight,
   iframe: true,
   href: this.href
});

Comment: May be it will be helpful if i give any reference. actually i am trying to do the modal window just like pinterest.com. @anydb
Comment: your answer is helpful but not what i am trying to do.
Answer: Posting the answer for those who still might have this issue
For auto height, this worked for me beautifully,


Negative Binomial Distribution.

Question: What is the probability that a batsman get run from $15$ balls and no run from $25$ balls before being caught behind in the $40$th balls ? Assuming he has a half-half chance to get run from each ball .
My Attempt:
This is a case of negative binomial distribution
So the distributional form is :
$$P(X=k)=\binom {\alpha+k-1}{k}(1-p)^{\alpha}p^k$$
$\alpha$ is number of failures and $k$ is number of successes.
$$P(X=?)=\binom {40-1}{?}(0.5)^{40}(0.5)^?$$
Answer: Not sure about cricket rules, but if the 40th ball has to be no run...
k = number of sucesses = 15
$\alpha$ = number of failures = 25
p = (1 - p) = .5
$P(X=15)=\binom {25 + 15 - 1}{15}(1-p)^{25}p^{15}$
$P(X=15)=\binom {39}{15}(.5)^{40}$
Comment: [Law 32.5](http://www.lords.org/mcc/laws-of-cricket/laws/law-32-caught-1/) *If the striker is dismissed Caught, runs from that delivery completed by the batsmen before the completion of the catch shall not be scored ..."* and anyway if would be very unusual to complete a run before being caught "behind", i.e. by the wicketkeeper.  A bigger problem is the use of "before" in the question.

Negative Binomial Distribution.


Method to find $(x_1, x_2,...,x_n)$ s.t. polynom $p(x_1, x_2,...,x_n) \bmod m = 0$

Question: I have a natural number $m$, and a polynomial $p: \mathbb{Z}^n \rightarrow \mathbb{Z}$, and I need to find a set $(x_1, x_2,...,x_n)$ so that $p(x_1, x_2,...,x_n) \bmod m = 0$.
First: Does every non-constant polynomial have such a set? And more importantly: Does there exist an (efficient) procedure to determine it, in case a set exists?
Comment: They objects are usually called "polynomials" in English, and not "polynoms".
Comment: No, a solution does not always exist. Take $p(x) = 2x+1$, and $m=2$; or $p(x)=x^2+x+1$, again with $m=2$. For a two variable example, take $p(x,y) = x^2+y^2+x+y+1$ with $m=2$; since $(x^2+x)+(y^2+y)$ is always even, $p(x,y)$ is never even.
Comment: Thank you for that quick answer. That restricts the question for the procedure to the case that such set exists. (I edited the question accordingly)
Comment: A partial answer to the first question: If $m$ is prime and the number of variables $n$ is bigger than the degree of the polynomial $p$ then by [Chevalley's Theorem](http://mathworld.wolfram.com/ChevalleysTheorem.html) the number of zeros is divisible by $p$. This might be useful if you already know a solution as in the case when there is no constant term.
Answer: If I am not mistaken, this is not known.  When $m = 2$ this problem is equivalent to Boolean satisfiability (SAT for short), which is known to be NP-complete.  This is because one can represent logical operations as polynomial operations on the finite field $\mathbb{F}_2$ (with $0$ being false and $1$ being true) as follows:
$$\neg x = 1 - x, x \text{ and } y = xy, x \text{ or } y = x + y + xy.$$
It follows that any Boolean expression in $n$ Boolean variables $x_1, ... x_n$ can be written as a polynomial over $\mathbb{F}_2$, and finding solutions is equivalent to finding a non-satisfying assignment for the Boolean expression (so replacing the expression with its negation we get the usual form of SAT).  So the question of whether there exists a polynomial-time algorithm for solving this problem is equivalent to P vs. NP.
I was mistaken!  Well, in any case, this paper might be relevant.
Comment: The size of the polynom resulting from a formula in CNF is not bounded polynomially, therefore this reduction is not in $P$. (Add: The arithmetization of $x \vee y$ is $x + y - xy$)
Comment: @Mike: whoops.  Very good point.


Scraping data from multiple places on same HTML with Beautiful Soup (Python)

Question: I have problems with scraping data from certain URL with Beautiful Soup.
I've successfully made part where my code opens text file with list of URL's and goes through them.
First problem that I encounter is when I want to go through two separate places on HTML page.
With code that I wrote so far, it only goes through first "class" and just doesn't want to search and scrap another one that I defined.
Second issue is that I can get data only if I run my script in terminal with:
python mitel.py > mitel.txt

Output that I get is not the one that I want. I am just looking for two strings from it, but I cannot find a way to extract it.
Finally, there's no way I can get my results to write to CSV.
I only get last string of last URL from url-list into my CSV.
Can you assist TOTAL beginner in Python?
Here's my script:
import urllib2
from bs4 import BeautifulSoup
import csv
import os
import itertools

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

with open('urllist.txt') as inf:
urls = (line.strip() for line in inf)
for url in urls:
    site = urllib2.urlopen(url)
    soup = BeautifulSoup(site.read(), 'html.parser')
for target in soup.findAll(True, {"class":["tel-number", "tel-result     main"]}):
    finalt = target.text.strip()
    print finalt

with open('output_file.csv', 'wb') as f:
writer = csv.writer(f)
writer.writerows(finalt)

For some reason, I cannot paste succesfully targeted HTML code, so I'll just put a link here to one of the pages, and if it gets needed, I'll try to somehow paste it, although, its very big and complex.
Targeted URL for scraping
Thank you so much in advance!
Comment: you assign only last value in `finalt = target.text.strip()`. You have to use list to keep all values `finalt = []` and later `finalt.append( target.text.strip() )`
Comment: to get two separated places on HTML page you have to use two separated `findall()` .
Answer: maybe your selector is wrong, try this
for target in soup.findAll(True, {"class":["tel-number",'tel-result-main']}):

Answer: Well I managed to get some results with the help of @furas and google.
With this code, I can get all "a" from the page, and then in MS Excel I was able to get rid of everything that wasn't name and phone.
Sorting and rest of the stuff is also done in excel... I guess I am to big of a newbie to accomplish everything in one script.
import urllib2
from bs4 import BeautifulSoup
import csv
import os
import itertools
import requests

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

finalt = []
proxy = urllib2.ProxyHandler({'http': 'http://188.8.131.52:80'})
auth = urllib2.HTTPBasicAuthHandler()
opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
urllib2.install_opener(opener)
with open('mater.txt') as inf:
    urls = (line.strip() for line in inf)
    for url in urls:
        site = urllib2.urlopen(url)
        soup = BeautifulSoup(site.read(), 'html.parser')
    for target in soup.findAll('a'):
        finalt.append( target.text.strip() )
        print finalt

with open('imena1-50.csv', 'wb') as f:
     writer = csv.writer(f)
     for i in finalt:
         writer.writerow([i])

It also uses proxy.. sort off. Didn't get it to get proxies from .txt list.
Not bad for first python scraping, but far from efficient and the way I imagine it.


Choosing right computer cluster components

Question: Recently someone at university gave me a task to create a network for parallel computing. For now i've got two intel chassis, two quad-core processors each, but it will expand with time for sure. I don't have IT degree, I'm only computer enthusiast, and I'm standing in front of following problems:

What would be the best OS?
What is the best way to secure such network?
What would be the better - ldap or nfs - if data will be storaged in separate disk array?

That network will be used by employees of my division for science computations (speed is a very important factor :)).
The person who gave me the task advise me to look for CentOS, Beowulf, Kerberos and ldap but i want to know if a better solution exists (maybe more modern one - previous network was build on beowulf).
It needs to be simple and effective (no way?! ;)) and must be easy to expand.
So, should i stick to what was told or should i search for something better?
What do you think?
Answer: My apologies if this come across offensively; but if you ain't a cook, stay out of the kitchen. You admit, and prove by the technologies you've got confused, that you know nothing about what you're embarking on; you're destine for a World of Fail™.
First thing you need to do is figure out what you're trying to accomplish. People don't build a skyscraper just to see if they can, they build it for a particular purpose (office space or what have you). If you have some specific application you'll be running, or a development environment, or something (anything!), that can serve as your focal point. Figure out what your destination is, then work back from there to where you are now.
Recommending CentOS without a clue as to what you're trying to accomplish would be reprehensible at best. Similarly for recommending a virtualization platform, clustering software, MPI (et alii), infrastructure, application bases, etc.
Security is definitely not a simply topic, nor one where I can simply point you to a quick how-to. Each component of a complicated system has it's own individual necessities, vulnerabilities, and other considerations.
The one thing I can tell you, it's almost certainly not going to be simple. That is the nature of computing these days. To think otherwise is an insult to the professionals who dedicate their lives to understanding just a portion of the spectrum modern technology encompasses.


Animações não aparecem

Question: Boas pessoal, estou a tentar fazer umas animações em scroll, mas  não sei porquê mas não vejo animação nenhuma, as secções não fazem reveal À medida que vou fazendo scroll...
Html:
Adicionei a classe js--wp-1, js--wp-3, js--wp-4 nos elementos que queria animar.
CSS:
<code>/* ---------------------------------------------- */
/* ANIMATIONS */
/* ---------------------------------------------- */

.js--wp-1,
.js--wp-3,
.js--wp-4{
   opacity: 0;
   -webkit-animation-duration: 1s;
   animation-duration: 1s;
}

.js--wp-1.animated,
.js--wp-3.animated,
.js--wp-4.animated{
   opacity: 1;
}
</code>
JS:
<code> /*Animations on scroll*/
        /*Animation 1*/
        $('.js--wp-1').waypoint(function(direction) {  /* Waypoint*/
            $('.js--wp-1').addClass('animated fadeIn');  /*Select animationçao*/
        }, {
            offset: '40%'
         });

        /*Animation 3*/
        $('.js--wp-3').waypoint(function(direction) {
            $('.js--wp-3').addClass('animated fadeIn');
        }, {
            offset: '50%'
         });

        /*Animation 4*/
        $('.js--wp-4').waypoint(function(direction) {
            $('.js--wp-4').addClass('animated fadeIn');
        }, {
            offset: '50%'
         });
</code>
Obrigado pessoal!
PS: Estou a utilizar o animate.css para fazer estas animações.
Answer: Utilizando as informações postadas na sua pergunta, o animate.css sozinho não tem ligação com o scroll e não entendi muito bem a sua tentativa de adicionar a detecção de scroll.
Porém, tenho uma alternativa bacana (e bem fácil de implementar) para o que você está tentando fazer, utilizando o wow.js. Que, inclusive, utiliza o animate.css para fazer a animação.
Segue o link:
wow.js
Qualquer dúvida, pode comentar.
Espero ter ajudado! :)

Animações não aparecem


The PDF of $X^3$ where $ X \sim \text{Normal}(0, 1)$

Question: I have been stumped for a few days on this...It would be great if anyone can point me to enlightenment :)
Here's what I have tried. Let $Y = X^3$, where X is a standard normal distribution with mean 0 and variance 1. Then
$P(Y \leq y) = P(X^3 \leq y) = P(X \leq y^{1/3})$, for both $y$ positive or negative.
The above is the CDF of $X^3$; differentiating w.r.t. to $y$ should give me the PDF, which is
$f_X(y^{1/3})\frac{1}{3}y^{-2/3}$, where $f_X$ is the PDF of the standard normal.

But THAT cannot be the answer, because it would take on negative values for $y < 0$. Whereas a PDF should always be non-negative. I have seen a "correct" answer in a math paper, where it changes $y$ to $|y|$ and results in an integral that converges (in Mathematica).
But where can I introduce the absolute terms!? Much thanks :D
Comment: The derivative of $g:y\mapsto y^{1/3}$ is positive at every $y\ne0$, in particular, if $y<0$, $$g'(y)=\frac1{3|y|^{2/3}}$$
Answer: If $y \ne 0$, the $2$ in the index would make it positive,
$$f_X(y^{1/3})\frac{1}{3}y^{-2/3}=f_X(y^{1/3})\frac{1}{3}y^{-\color{red}2/3} $$
Comment: Thanks. That makes sense...which makes me even more confused. Can you explain why in this paper they introduced an absolute sign? Seems superfluous ...https://projecteuclid.org/download/pdf_1/euclid.aop/1176991795
Comment: The problem is that sometimes you might say $(-8)^{-2/3}$ is $-\frac14$ and sometimes $-\frac18 - \frac{\sqrt{3}}{8}i$.  [Wolfram Alpha gives the complex answer](https://www.wolframalpha.com/input/?i=(-8)%5E(-2%2F3))
Comment: thanks for the enlightenment. I interpreted it as always taking the real root previously.
Comment: Thank you Henry! That's exactly the problem with using Mathematica :)
Answer: Here's a way to find the $|y|$-based formula the first time, rather than saying, "Oh gee, it looks like that needs a little something" near the end. Since $X$'s pdf is even, $Y$'s should be even too. Let $\Phi,\,\phi$ denote the CDF and PDF of $X$. For $y\ge 0$, $$P(Y\le y)=\Phi(y^{1/3})\implies f_Y(y)=\frac{1}{3}y^{-2/3}\phi(y^{1/3}).$$Then, for arbitrary $y\in\mathbb{R}$,$$f_Y(y)=f_Y(|y|)=\frac{1}{3}|y|^{-2/3}\phi(|y|^{1/3}).$$
Comment: I can't believe I didn't see this ... Thank you J.G.!


Express $e^\pi$ in the form $x+iy$

Question: The hint for this problem says to reason carefully, so I did. However, whenever I see $e$ in a problem I'm never quite sure how to treat it.
My attempt:
$e^\pi$ is of the form $re^{i\theta}$, so
$$r= e^\pi$$
$$a=r\cos \theta$$
$$a=(e^\pi)\cos(\pi)$$
$$a=e^\pi$$
And,
$$b=r\sin\theta$$
$$b=0$$
Thus,
$$z=e^{\pi}$$
Comment: Are you sure you copied the problem correctly?
Comment: @Henry I don't think so....why?
Comment: @Henry ok....? I don't follow
Comment: @Did: Be like that then
Comment: @avid19 yup. Not much to it.
Comment: Can you say $e^{\pi} = \sqrt[i]{-1} = (-1)^{-i}$ ?
Comment: ... because $\left(e^{\pi}\right)^i = -1$ is the most interesting thing about $e^{\pi}$
Comment: @Henry How come? It is well known that $(e^\pi)^i=-e^{-2\pi}$, no?
Comment: @Did: Perhaps you are missing an $i$ in the exponent of $-e^{-2\pi}$
Comment: @Henry No. Perhaps you are missing the point. Oh, and by the way, it is also well known that $(e^\pi)^i=-e^{42\pi}$...
Answer: My pocket calculator gives $e^\pi\doteq23.14$. There is absolutely no reason that it could be something else in the complex world. Note that the "complex" function $z\mapsto e^z$ is the extension of the function $x\mapsto e^x$ defined for real $x$; hence $e^\pi$ remains $e^\pi$ even in the larger environment. Note that the formula
$$e^z:=\sum_{k=0}^\infty {1\over k!}\>z^k$$
is valid for all $z\in{\mathbb C}$, hence for all $z\in{\mathbb R}\subset{\mathbb C}$.
Answer: Your approach is incorrect - one way to see this is that it gives the wrong result for $e^{\pi/2} \approx 4.81$: It would give a pure imaginary number.

$e^{\pi}$ is just a real number, since the exponent is real. Any real number $x$ can be written as $x + 0i$.
Comment: Can the same thing be said vice versa? If I had $e^i\pi$, could I simply say that the real part is $0$? Or is it different for the imaginary side of things?
Comment: @whatwhatwhat: $e^{i\pi}=-1+0i$
Comment: $e^i$ is not a purely imaginary number, so no. (And neither is $e^{i\pi}$).
Comment: @T.Bongers wait so $2i$ is a purely imaginary number, but $e^i$ isn't??
Comment: Yes. ${}{}{}{}{}$
Answer: Notice that $\Im\left(e^{\pi}\right)=0$ so the imaginary part of $e^{\pi}$ is $0$, what gives us it in the form:
$$x+yi\to e^{\pi}+0i$$

Express $e^\pi$ in the form $x+iy$


Confusion on Extremes of Chernoff-Hoeffding Bound

Question: For $X$ a binomial random variable with probability of success $p$, the Chernoff-Hoeffding bound states
\begin{equation}
    \mathrm{Pr}[X \geq (p+t)n] \leq e^{-n\left((p+t)\log(\frac{p+t}{p})+(1-p-t)\log(\frac{1-p-t}{1-p})\right)}
    = e^{-nD(\{p+t,1-p-t\}||\{p,1-p\})}
\end{equation}
where $n$ is the number of trials, $D(p||q)$ is the Kullbeck-Leibner divergence, and $t$ is a free-parameter which is used to specify the bounded value.
Here's where my confusion begins: consider $\mathrm{Pr}[X\geq 0]$. In this case,
\begin{equation}
    (p+t)n=0 \iff t=-p
\end{equation}
so the Chernoff Bound states
\begin{equation}
    \mathrm{Pr}[X\geq 0] \leq e^{-nD(\{0,1\},\{p,1-p\})} = e^{-n\log(\frac{1}{1-p})} = (1-p)^n < 1
\end{equation}
which is not true, because $X\geq 0$ encompasses ALL possible values of $X$, so it must be equal to 1.
Where is my error? I've detailed my understanding of the derivation below:
Consider random, independent trials each with probability of success $p \in [0,1]$. If $X$ is the number of successes attained in $n$ trials, then $X$ follows a binomial distribution:
$$
    \mathrm{Pr}[{X = i}] = {n\choose i}p^i (1-p)^{n-i}
$$
The Chernoff bound allows us to bound the cumulative probability $\mathrm{Pr}[X\geq m]$. Note that $X = \sum_{i=1}^n X_i$ where $X_i=1$ iff trial $i$ succeeds and $X_i=0$ otherwise.
Then
\begin{equation}
    \mathrm{Pr}[X\geq m] = \mathrm{Pr}[e^{\lambda X} \geq e^{\lambda m}] \leq \frac{\mathbb{E}[e^{\lambda X}]}{e^{\lambda m}}
\end{equation}
where the inequality follows from Markov's inequality. Further, by the independence:
\begin{equation}
    \frac{\mathbb{E}[e^{\lambda X}]}{e^{\lambda m}} = \frac{\prod_i \mathbb{E}[e^{\lambda X_i}]}{e^{\lambda m}} = \frac{(pe^\lambda + (1-p))^n}{e^{\lambda m}}
\end{equation}
Using parameterization $m=(p+t)n$ and minimizing over all $\lambda > 0$ yields
\begin{equation}
    \mathrm{Pr}[X \geq (p+t)n] \leq e^{-n\left((p+t)\log(\frac{p+t}{p})+(1-p-t)\log(\frac{1-p-t}{1-p})\right)}
    = e^{-nD(\{p+t,1-p-t\}||\{p,1-p\})}
\end{equation}
where $D(p||q)$ is the Kullbeck-Leibner divergence.
It seems like the only room for error in the derivation would be Markov's inequality:
$$
    \mathrm{Pr}[X \geq a] \leq \frac{\mathbb{E}[X]}{a}
$$
But Markov's inequality holds for all $a>0$, and in this case my value $e^{\lambda m} >0$ for all values of $m,\lambda>0$.
Answer: You are choosing $m = 0$. Thus, in the first step you are stating that for any
$$
P[X \geq 0] = P[\lambda X \geq 0] = P[e^{\lambda X} \geq 1] \le E[e^{\lambda X}] = (pe^{\lambda} + (1 - p))^n,
$$
for any $\lambda > 0$. But then $e^{\lambda} > 1$ implies that
$$
pe^{\lambda} + (1 - p) > 1,
$$
and the bound is useless.
Comment: I am not very familiar with Kullback Leibler divergence, but probably the error is in that computation.
Answer: This is a nice question, and you got me confused at first.
Th problem is that your first inequality only holds for $t \ge 0$.
The correct Chernoff Entropy bound is the following:
\begin{align}
    \mathrm{Pr}[X \geq (p+t)n] \leq e^{-nD(\{p+t,1-p-t\}|\{p,1-p\})}&\quad\text{if }t\ge 0\\
\mathrm{Pr}[X \leq (p+t)n] \leq e^{-nD(\{p+t,1-p-t\}|\{p,1-p\})}&\quad\text{if }t\le 0
\end{align}
So you see, that for $t=-p$ we get
\begin{align}
\mathrm{Pr}[X \leq 0] \leq (1-p)^n,
\end{align}
which is in fact an equality in our case.
The reason for the two bounds is that when you optimize $\lambda$ you set it equal to $\log\left(\frac{m(1-p)}{(n-m)p}\right)$ which is equal to $0$ at $m=pn$ and less than zero for $m<pn$.


Upload progress bar in DWR?

Question: In my project i want to show the progress bar while uploading files. I am using DWR to get send the data to server, javascript and Java is the server side language. I have done some searches to learn it. But i couldn't able to find one.
Any link to learn or suggestions would be appreciative!!!
Thanks!!
Answer: There is no Progress bar support in DWR right now. Hope, it will be added in their Official DWR 3 release.

Upload progress bar in DWR?


Get Facebook access token using PHP

Question: I'm developing application which need access to user's facebook account. It is working, but I need to get user's facebook token and save it to MySQL database. How can I get facebook token using PHP (with permissions defined by me) ?
Answer: There's a good official guide/tutorial about just that in the facebook developers documentation.
What you're looking for is the Server-Side authentication flow, since it results with a long lived access token (60 days) which you can persist in your db and reuse when needed.
There's also the Client-Side flow but that grants you short lived tokens (a few hours long) which are no good for persistancy.
If however you do decide to go with the client side flow then you can extend the expiration time of a valid token using the new endpoint which was introcuded due to the deprecation of the offline_access permissions.
Comment: Thanks for answer. I've used example code from your link (server side), but how can I get extended permissions ?
Comment: In that same guide, the first section "1. Redirect the user to the OAuth Dialog" has this *scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES* in the redirect url, add the needed permissions there.

Get Facebook access token using PHP


Implementing Area 51 with Acquia Commons?

Question: I'm probably going to use Acquia Commons to put together a site for communities, and I understand that it's set up as installed to have administrators create the groups and subgroups. However, I'd like users to be able to petition for new groups (and subgroups?) to be created in a process something like Stack Exchange's own Area 51, though perhaps without the following phase.
How would I go about implementing that sort of thing on the current release of Commons? It's based on Drupal 6 until more modules are ported to D7.
Answer: Here's a simple solution:

Create a content type, say 'proposal', that any user can add for the petition group (with title as group name and body for reason).
Users can comment on nodes of that type so they can discuss the proposal.
Create a view to show nodes of type 'propsal' and enable filtering, sorting etc.
Use the Votingapi module and one of the voting widgets (like vote up/down) to allow people to vote on the node.

For the creation of the groups, you can either:

Do it manually, monitoring when a proposal gets a specified number of votes.
Use the Rules module to do it automatically.


Comparing one property of an instance against an array of other instances

Question: I'm trying to write an instance method for a Card class that compares a single card against an array. The class has some properties like: shape and color. The otherCards array is filled with other instances of this class, that also have their shapes and colors.
Now, I want to write a method that can check all of these attributes separately. How can I pass in a particular attribute, as in: [allAttributesIsEqual:otherCards compareWith: self.shape]? So I can pass in self.shape or self.color when actually comparing?
- (BOOL)allAttributesIsEqual: (NSArray *)otherCards
{
    //self.shape is equal to othercards.shape
}

Comment: And you only want to compare one property of that one instance against that same property in the whole array, and you only want a single function name?  Is there anything wrong with doing something like `-(BOOL) shapeEqual:(NSArray*) otherCards`?
Comment: Yes! I want to compare one instance of Card with all the Cards in the array. But the key is that the Cards got different properties like color and shape, and I want 1 method to check them all
Comment: I thought I had it after Dan's comment, but now I'm confused again. If you have a `Card` whose shape is square and color is blue, you want to see if a whole array of other cards are also both blue _and_ square? Or you just want to check if they're all blue?
Comment: Each card has different properties?  Or do all cards have different values in each property?
Comment: Josh: I want to ask: isAttributeEqual: self.shape: otherCards and/ or isAttributeEqual: self.color: otherCards, then compare to the correct thing in the method: color or shape... Sorry for the bad explanation I am sorta confused myself...
Comment: Tom, I've edited the title to reflect what I understand you're asking. _Please_ feel free to change it or roll it back if I've got it wrong!
Answer: You can't just pass in self.shape, because that will give you the value of the property. Thanks to some of Cocoa/ObjC's dynamite, however, you can pass in the name of a property (or method) and get the results later.
The clever (dare I say, perhaps even "Pythonic") way:
// The name of the property we're interested in.
NSString * key = @"color";
// Get the values of that property for all the Cards in the array, then
// collapse duplicates, because they'll give the same results when comparing
// with the single card.
NSSet * vals = [NSSet setWithArray:[arrayOfCards valueForKey:key]];
// Now, if the set has only one member, and this member is the same
// as the appropriate value of the card we already have, all objects
// in the array have the same value for the property we're looking at.
BOOL colorIsEqual = ([vals count] == 1 && [vals containsObject:[myCard valueForKey:key]]);

Then your method can look like this:
- (BOOL)allOtherCards: (NSArray *)otherCards haveEqualAttribute: (NSString *)key;

Dan F's suggestion to implement - (BOOL)<#property#>Equal: (NSArray *)otherCards; for each property you're interested in is not at all a bad idea, however. Of course, each of these could call through to the base "clever" version.
Comment: Eh, I guess it's not that Pythonic. It's hard to be Pythonic without list comprehensions.
Comment: That is pretty cool! will take me some time to get used to this way of doing things.
Answer: The idea is that you (as the Card class) know what it means for two instances to be "equal". It sounds like in your case, two Cards are equivalent if their color and shape properties match. Start by implementing -isEqual: (along with -hash) on your custom Card class. This is the standard way of having an object expose a notion of whether it is the same as some other object. You can implement this however you need. Within this isEqual method, you can check all of the relevant properties:
- (BOOL)isEqual:(id)otherObject
{
    if (![otherObject isKindOfClass:[self class]) {
        return NO;
    }
    Card * otherCard = (Card *)otherObject;
    // now compare the attributes that contribute to "equality"
    return ([self.shape isEqual:otherCard.shape] && [self.color isEqual:otherCard.color]);
}

Now, once your custom object supports this -isEqual:, you can check all the cards in the array to see if any are equal to the candidate card. You could do the loop yourself and use the -isEqual:, but the nice thing about doing this in the system standard way is that you can also use system provided convenience methods to check for collection membership, like:
if ([myCardList containsObject:candidateCard]) {
    // one of the cards compared as "equal"
}

If you would prefer to do this as you request in a method on your class, you could then structure it like so:
- (BOOL)isRepresentedInArray:(NSArray *)arr
{
    return [arr containsObject:self];
}

Comment: Based on the comments and the [repost](http://stackoverflow.com/questions/14903322/objective-c-writing-a-smart-reusable-compare-function?lq=1), Tom wants to compare only a single attribute of the cards, not check for full equality.


Least degree of positive part in degree zero divisor class on compact Riemann surfaces

Question: Consider a compact Riemann surface $M$ of genus $g>1$ and a divisor $D$ of degree zero. Any such divisor can be expressed as difference of two effective divisors: $D=E_1-E_2$, we can think of $E_1$ as positive part of $D$. In each linear equivalence class (i.e. divisor class), there ought to be a 'simplest' form, by which I mean a divisor $D_0=E_1^0-E_2^0\in [D]$ with deg$(E_1^0)=$deg$(E_2^0)$ being smallest in the whole class $[D]$.
For example if $D=(f)$ for some meromorphic function $f$ on $M$, then this number is zero, because $D\sim 0-0$. Furthermore, if $g>1$, any divisor of the form $D=x-y$ with $x\neq y$ cannot be further 'reduced' by linear equivalence, so the least degree of positive part for it is 1.
My question is: is there any general theory that characterizes the least degree of positive part of a divisor of degree zero?
For example, since the set of divisor class of degree zero is identified with set of line bundles of degree zero, that is the Jacobian $Jac(M)$, there should be a disjoint union $Jac(M)=Jac(M)_0\coprod Jac(M)_1\coprod \ldots$ where $Jac(M)_n$ consists of divisor class with least degree of positive part being $n$. Is any of these dense in the torus $Jac(M)$ with its usual topology? What is this partition of a complex torus look like geometrically?
Answer: This is the topic of the Riemann--Roch theorem, Clifford's theorem, and
Brill--Noether theory.
For example, Riemann--Roch shows that if deg $D \geq g$, then there is an effective divisor linearly equivalent to $D$.  This implies that if $D$ has degree zero, then we can write it as a difference of degree $g$ divisors.  This gives an upper bound for your question.
In general, the morphism $\operatorname{Sym}^d C \times \operatorname{Sym}^d C \to \operatorname{Pic}^0 C$ sending $(D_1,D_2) \to D_1  - D_2$ has Zariski closed image (its source and target are projective), and so the partition you ask about is a partition of the Jacobian into Zariski locally closed subsets.  Since the source of this morphism has dimension $2d$, while its target has dimension $g$, this shows directly that this morphism is not surjective if $d < g/2$.    One can say much more than this, but maybe this is enough to start with.

Added:
As one more example, I'll show that if $g \geq 2$, then this map is surjective
when $d = g-1$ (so any degree zero divisor can be written as a difference
of effective divisors of dgree $g-1$).
We begin with a preliminary result.
Namely, let $K$ denote the canonical divisor (which has degree $2g-2$),
and for any effective degree $g-1$ divisor $D$,
consider the linear series $|K-D|$.
Riemann-Roch shows that this has positive dimension (here we use the fact that $D$ is effective), and so we may write $K \equiv D + D'$,
where $D'$ is also of degree $g-1$.
Now suppose given $D$ of degree zero, and consider $D + K$.  This has
degree $2g-2$, which is $\geq g$ (b/c $g \geq 2$), and so we may
find an effective divisor $E$ so that $D + K \equiv E$.  Now write
$E = E_1 +E_2$, where each of $E_1,E_2$ is effective of degree $g-1$,
and then write $K \equiv E_1 + E_1'$ as in the preceding paragraph.
Putting this all together, we get that $D + E_1' \equiv E_2,$ i.e.
that $D\equiv E_2 - E_1'$, which shows that $D$ is linearly equivalent to
the difference of effective divisors of degree $g-1$.


Finding a future co-linear midpoint of two moving objects

Question: I have three objects in a 2d space: S, E1, and E2.
E1 and E2 are at some location ((E1x, E1y) & (E2x, E2y)) and moving at constant velocities VE1 and VE2. They will be set initially and not change.
S starts at some location and needs to pick a direction. It has a speed and can only move at this speed.
How does one select the exact direction that will result in S being both equidistant from and co-linear to E1 and E2 in the minimum amount of time.
Comment: Just to clarify, all these objects move in a straight line? Also, are you assuming that the initial configuration is such that this is even possible? For example, if $E_1$ starts at $(-1,1)$ and $E_2$ starts at $(1,1)$, both moving due North at speed $v_0$, and $S$ starts at $(0,0)$ and has speed $v_0$, then the three objects can never be co-linear.
Comment: Yes. Everything moves in a straight line. The project will require them to collide with walls later but I will take whatever implementation I have and make it piece-wise to deal with that. Your concern is more than valid and I need to specify that S will have a much higher speed than the other two objects. But I can't specify what "much higher" means since the project constraints aren't specified yet. I would be fine with a solution (or point in the direction of a solution) that finds a solution if one exists and simply breaks if one doesn't
Answer: Without loss of generality, assume $S$ starts at the origin. If $S$ has constant speed $s$ and chooses a constant heading $\vec h_S$ where $|\vec h_S|=1$ then its position at time $t$ is
$\vec S(t) = (st) \vec h_S$
Let's call the midpoint of $E_1$ and $E_2$ $F$, so at time $t$
$\vec F(t) = \frac 1 2 \left( \vec E_1(t) + \vec E_2(t) \right)$
Then $F$ starts at position
$\vec F(0) = \frac 1 2 \left( \vec E_1(0) + \vec E_2(0) \right)$
and has constant velocity
$\vec v_F = \frac 1 2 \left( \vec v_{E_1} + \vec v_{E_2} \right)$
and so its position at time $t$ is
$\vec F(t) = \vec F(0) + t\vec v_F$
Then $S$ intercepts $F$ at time $t$ if
$(st) \vec h_S = \vec F(0) + t\vec v_F \\ \Rightarrow t(s \vec h_S - \vec v_F) = \vec F(0)$
So $S$ has to choose its heading $\vec h_S$ so that $s \vec h_S - \vec v_F$ is parallel to $\vec F(0)$. As pointed out in a comment, if $s$ is too small this may not be possible.
Comment: Perfect. Thank you. I was worried this might be a Calculus of Variations problem. But simple kinematics does the trick.


Why does phase randomizing the Fourier transform of a data set render it Gaussian?

Question: Let's say I have a data set $s_n$.  I take the Fourier transform of this data set to obtain $\tilde{s}_n$. I randomize the complex phases of $\tilde{s}_n$ and I take an inverse transform to obtain $s'_n$. This way $s_n$ and $s'_n$ have the same power spectrum.  On the other hand, the PDF of $s'_n$ is Gaussian (at least asymptotically) irrespective of the PDF of $s_n$.  Why is this so?
Answer: This is a hand-waving answer that might provide some intuition.
Given a data set $(x_0, x_1, \ldots x_{N-1})$ which is a set of $N$ (independent) samples from an unknown distribution (which we assume
has zero mean and finite varince), we take its
Discrete Fourier Transform (DFT) to obtain a complex vector
$(X_0, X_1, \ldots, X_{N-1})$ where
\begin{align}
\Re(X_k) &= \frac{1}{\sqrt{N}}\sum_{m=0}^{N-1} x_m \cos(2\pi km/N)\\
\Im(X_k) &= -\frac{1}{\sqrt{N}}\sum_{m=0}^{N-1} x_m \sin(2\pi km/N)
\end{align}
Vigorous hand-waving and the murmuring of shibboleths that sound
a lot like "Sea Elle Tea" allow us to suggest that maybe, just
maybe, $\Re(X_k)$ and $\Im(X_k)$ can be treated as (independent)
zero-mean normal random variables (approximately). Thus, $|X_k|$ is
Rayleigh distributed (approximately) and when you replace
$\angle X_k$ in $X_k = |X_k|\exp({i\angle X_k})$ by $\Theta_k \sim U[0,2\pi)$, the alleged resemblance of $\Re(\hat{X}_k)$ and
$\Im(\hat{X}_k)$ to zero-mean normal random variables only
increases. (For best results, choose $\Theta_{N-k} = 2\pi-\Theta_k$
in order to maintain the necessary conjugate symmetry of the DFT
result.)  Finally, apply the inverse DFT transformation (giving you
linear combinations of normal random variables) and
shout "See Elle Tea" in a more strident voice as you insist
to all and sundry that $(\hat{x}_0, \hat{x}_1, \ldots, \hat{x}_{N-1})$
sure looks like $N$ samples from a normal distribution


Typescript cannot assign typed FormGroup

Question: I have a typed FormGroup and a generic component that takes a FormGroup as Input and handles the errors.
Here is what my FormGroup looks like:
  filterForm = new FormGroup({
    name: new FormControl<string>('', { validators: [Validators.required] }),
    authority: new FormControl<string>('')
  });

The error handler component declares a regular input, which evaluates as FormGroup<any>:
@Input({ required: true }) form!: FormGroup;

Now when I try to set filterForm as my error handler's form input I get the error:
Type FormGroup<{ name: FormControl<string>; authority: FormControl<string>; }> is not assignable to type FormGroup<any>.
Types of property 'controls' are incompatible. [...]
Property 'name' is incompatible with index signature.
Type FormControl<string> is not assignable to type AbstractControl<any, any>.
Types have separate declarations of a private property '_parent'.

While I understand the error, I don't know how to solve this and how to type my @Input so that I can use any typed FormGroup as a parameter. What I really use is the form's global invalid status and the indexable controls object to go over individual field errors, so I don't care about the form's type within my component.
Comment: It doesn't make sense that it doesn't work; `FormControl` _is_ assignable to `AbstractControl`.
It works for me in this stackblitz: https://stackblitz-starters-hs2kgr.stackblitz.io.
Could you try updating your dependencies? Or comparing your config with the stackblitz?
Answer: I'm not sure if this is what you have going on, but this can happen when there is more than one version/copy of @angular in your workspace.
In my case, I am developing and referencing my own library project (my-lib) in an application (my-app) and my library is using its own @angular packages and the app is using its own @angular packages.
Because they live in two different locations, even though they can be exactly the same version, the compiler views them as different libraries.
The solution is to tell your app to ONLY use one version/copy of @angular by redirecting ALL @angular references to a single spot by adding the entry below in your tsconfig.json file of your application.
"compilerOptions": {
  "paths": {
    "@angular/*": [
      "./node_modules/@angular/*"
     ]
  }
}

I'm not sure if this is what you have going on, but thought I'd share in case it helps you out.
Comment: I won't be able to try your solution as my component no longer exists, but I believe this is what was going on. I am also working with my own lib and didn't think this info actually mattered since both Angular versions were exactly the same. I'll keep your answer in mind next time I have some typing magic going on with a lib!


Obtain one single growth curve from various replicates in a growth experiment

Question: I am performing a yeast growth experiment measuring areas of growth across a time interval, therefore having area (%) as my dependent variable and time (min) as my independent variable. I have three experimental conditions: Control, Treatment 1, and Treatment 2, and 3 replicates for each condition.
As my initial area percentage (t=0) is slightly different for each replicate of my conditions (e.g. replicate1-control: 5%, replicate2-control: 6.5%, replicate3-control: 10%), I would like to perform some kind of standardization so there is a unique growth curve for each condition before fitting them to one of the models (logistic, Gompertz, Richards, etc.), and calculating the growth rate and duplication time. Given this, I have the following questions:

Is there any method to reliably perform this standardization?
Which method could be the most reliable?

I have read some articles and documentation of R packages about this topic, but most of them only offer examples of the data fitting of different conditions. They don't offer details or they are unclear about whether there is a previous standardization step before fitting the data. I am not sure if the functions fitting the models perform some kind of standardization before the fitting, and if so, I couldn't find which is the method or formula through which it is performed.
Example data could be find in this repository: Preliminar data
Comment: That orange line can't be modelled with a simple growth model. The model would need to take into account whatever caused the drop to zero at time 500 and the later regrowth (possibly of a different micro-organism?).
Comment: You may try applying a nonlinear mixed effects model. If you share at least a portion of your data I may give it a try.
Comment: @utobi Thanks for your answer, and sorry for the late reply. That sounds like a very interesting approach to solve my problem, but I am not sure about how to do it. Of course you can have a portion of my data, you can find it in the edited question, at the end of it. Let me know if you can access and download it.
Comment: @Roland Thanks for your answer. In the case of the published image, it is just an example of the data I want to model. In fact, what I want to do after obtaining one single curve is to separate it in three "growth intervals" and each interval would be modelled or fitted to different yeast growth models. That drop you are mentioning is mainly caused by the growth conditions that we are studying and we will address them in our analysis.
Answer: See Chapter 7 of Frank Harrell's Regression Modeling Strategies for extensive explanation of how to model longitudinal data like growth curves. Instead of first reducing the replicates for each treatment to a single growth curve, you model the association of outcome with time flexibly as a function of treatment condition while taking into account the correlations among the values found within each replicate. In that case, including the initial value as a predictor in the model is a way to handle the differences among starting conditions. How well that will work depends on the details of your data. If all area values are greater than 0, you might consider working with log-transformed areas.
From what you show in the figure, I'd recommend against a simple parametric growth curve model (e.g., logistic). That's particularly the case if growth conditions can change during the experiment, as you imply in a comment to explain the dip in the orange curve at about a time of 500. Flexible fitting of time as a predictor without imposing a particular parametric form, as with a regression spline, would seem to be preferable. That would still allow you to discern differences among treatments and might also make it easier to handle the 3 "growth intervals" that you mention in a comment (depending on how those intervals are defined).
Comment: Hello, @EdM. Thanks for your answer. I am not clear what do you refer about when suggesting to model the association of outcome with time flexibly as a function of treatment condition. If you could please explain me this a bit more, that would be amazing.
As all my area values are greater than 0, I have other question, and it is: working with log-transformed areas will not shape differently my data?
Comment: @PaoloVallejoJaneta a regression spline can give flexible modeling of time, as explained in Chapter 2 of the Harrell reference linked above. You include an interaction between the spline and the treatments to allow the trajectory over time to differ depending on treatment. The choice between using raw areas and log-transformed values depends in part on how measurement errors are related to observed values. If errors are fairly constant over the range of measurements, then raw values are OK. If they are approximately proportional to measured values, log transformation can be better.
Answer: Imo, you don't need to standardize or normalize your data.
The preliminary data matrix can be reshaped to better enable growth curve models.
For example, stack up the three conditions into a matrix with single fields for TIME, AREA and CELL. Then add a CELL TYPE field coded 1, 2, 3 or add three dummy variables, one for each cell type. Build the growth models on that data.

And so on...
Comment: Thanks @Mike Hunter for your answer. In my data there are no different cell types, what I have are multiple replicates for different treatment conditions (e. different chemical concentrations). Still, I could include 2 variables: one for number of replicate and another for the treatment condition.
What makes me doubt about this approach is the fact that when working with R libraries to fit a data frame like this, most of them takes the average value (for each timepoint) of all the replicates from the same condition, so I'm not sure if taking the average without previous analysis is accurate.
Comment: I don't know R, so I can't suggest an appropriate module. Given the above data matrix ways to think about this analysis include, first, as an ANOVA and then as a pooled time series or panel data model.


Concrete Mathematics Section 3.5: Floor / Ceiling sum manipulation

Question: Problem: To find the closed form of $\sum_{0 \le k \lt n}\lfloor \sqrt{k} \rfloor$
The text goes on solving as follows
$$
\begin{align}
\sum_{0 \le k \lt n}\lfloor \sqrt{k} \rfloor
&= \sum_{k,m \ge 0}m[k < n][m = \lfloor \sqrt{k} \rfloor]\\
&= \sum_{k,m \ge 0}m[k < n][m \le \sqrt{k} < m + 1]\\
&= \sum_{k,m \ge 0}m[k < n][m^2 \le k < (m + 1)^2]\\
&= \sum_{k,m \ge 0}m[m^2 \le k < (m + 1)^2 \le n] + \sum_{k,m \ge 0}m[m^2 \le k < n < (m + 1)^2]
\end{align}
$$
Let's assume that $n = a^2$ is a perfect square. Then the second sum is zsero and the first can be evaluated as
$$
\newcommand{\fallingfactorial}[1]{%
  ^{\underline{#1}}%
}
\begin{align}
\sum_{k,m \ge 0}m[m^2 \le k < (m + 1)^2 \le a^2]
&= \sum_{m \ge 0}m((m + 1)^2 - m^2)[m + 1 \le a]\\
&= \sum_{m \ge 0}m(2m + 1)[m < a]\\
&= \sum_{m \ge 0}(2m\fallingfactorial{2} + 3m\fallingfactorial{1})[m < a]\\
&= \sum_0^a (2m\fallingfactorial{2} + 3m\fallingfactorial{1}) \delta m\\
&= \frac{1}{6}(4a + 1)a(a - 1)
\end{align}
$$
The next part I don't understand
It says: In general we can let a = $\lfloor \sqrt{n} \rfloor$; then we merely need to add the term $a^2 \le k < n$, which are all equal to a, so they sum to $(n - a^2)a$. This gives the desired closed form,
$$
\sum_{0 \le k < n} \lfloor \sqrt{k} \rfloor = na - \frac{1}{3}a^3 - \frac{1}{2}a^2 - \frac{1}{6}a, \text{where } a = \lfloor \sqrt{n} \rfloor
$$
Why we are considering $a^2 \le k \lt n$, shouldn't we consider $a \le k \lt n$ as we have already calculated for $0 \le k \lt a$ before ?
Answer: We consider the second sum  in somewhat more detail which might help to clarify the situation.

We obtain
  \begin{align*}
\color{blue}{\sum_{k,m\geq 0}}&\color{blue}{m[m^2\leq k<n<(m+1)^2]}\tag{1}\\
&=\sum_{k\geq 0}a[a^2\leq   k<n<(a+1)^2]\tag{2}\\
&=\sum_{{k\geq 0}\atop{a^2\leq  k <n}}a\tag{3}\\
&=\sum_{a^2\leq  k <n}a=\sum_{k=a^2}^{n-1}a\tag{4}\\
&\color{blue}{=(n-a^2)a}
\end{align*}
Comment:

In (1) we observe that if $n$ is fixed there is precisely one integer $m$ which fulfills the condition
$$[m^2\leq k<n<(m+1)^2]$$
So, we sum in fact only over $k$.
In (2) we sum over $k$ only and denote the single value $m$ with $a$. We have
$$m=a=\lfloor \sqrt n\rfloor$$
The condition $[\color{blue}{a^2\leq   k<n}<(a+1)^2]$ tells us that we have a non-zero contribution only if $a^2\leq k<n$.
In (3) we rewrite the condition from (2) as index range.
In (4) we do a small simplification.


MariaDb: JSON_ARRAY_APPEND to empty array

Question: I find it confusing (and not working) to use JSON_ARRAY_APPEND with empty JSON arrays according to the docs. I'm using newest version of MariaDb 10.2.6.
When I do:
SELECT JSON_ARRAY_APPEND('[1]', '$', JSON_EXTRACT('{"test":123}', '$'));

Result is as expected:
[1, {"test": 123}]

(the same with:
SELECT JSON_ARRAY_APPEND(JSON_EXTRACT('[1]', '$'), '$', JSON_EXTRACT('{"test":123}', '$'));

)
But, when I operate on empty array:
SELECT JSON_ARRAY_APPEND('[]', '$', JSON_EXTRACT('{"test":123}', '$'));

The result is:
(NULL)

Probably because of this I cannot update field with empty array. When I do:
UPDATE `test` SET `test`.`log` = JSON_ARRAY_APPEND(`test`.`log`, '$', JSON_EXTRACT('{"test":123}', '$'))

I get an error:
(4038) Syntax error in JSON text in argument 1 to function 'json_array_append' at position 2

Am I getting something wrong or is it some kind of bug or caveat?
Regards,
JK.
Answer:
MariaDB [test]> SELECT JSON_ARRAY_APPEND(JSON_ARRAY(''), '$', JSON_EXTRACT('{"test":123}', '$'))\G
*************************** 1. row ***************************
JSON_ARRAY_APPEND(JSON_ARRAY(''), '$', JSON_EXTRACT('{"test":123}', '$')): ["", {"test": 123}]
1 row in set (0.00 sec)

Comment: You are right. This is what docs are saying. But I'm not talking about NULL, I'm talking about empty array `[]`.
Comment: Hi. Thank you, but not really. I store it in field. Default value is `[]`. I need it to be working with this.
Comment: I think mariadb has different treat for `[]` and `JSON_ARRAY('')`, and they has different meaning.
Comment: It does treat in this case. But it should not. `JSON_EXTRACT('[]', '$')` should === `JSON_ARRAY('')`.
Comment: Yes, this looks like a bug.
Comment: this array thing is still a bug for me, even for 10.2.9
Comment: I stumbled upon this bug too, but let me tell you, `json_array() !== json_array('')`. Both represent different things. `json_array()` is `[]` (empty array) while `json_array('')` is `[""]` (array length one, with empty string)
Comment: crazy, I am on mariadb 10.2.17 and in the bug you linked they said it was fixed on mariadb 10.2.9 and closed it. But I still get the same bug
Comment: Probably this one: https://jira.mariadb.org/browse/MDEV-17121