Mysql crashing/restarting, InnoDB: Unable to lock ./ibdata1. Can't kill via 'stop';

Question: My server seems to crash/restart under a load that would not have previously made it crash.
How can I troubleshoot this?
VPS is running Centos 6.x, 8GB ram

Mysql is crashing/restarting itself under loads that would not have previously done it in.
This error: InnoDB: Unable to lock ./ibdata1, error: 11 pops up in the log after the crash. Could this simply be from mysql recovering from a crash and trying to restart while it hasn't fully died?

I'm not sure if any of this is related to the crashing, as it shows during the database trying to restart itself. Quite a few lines of:
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.

The log then proceeds with:
141207 18:58:06 [ERROR] Plugin 'InnoDB' init function returned error.
141207 18:58:06 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
141207 18:58:06 [ERROR] Failed to initialize plugins.
141207 18:58:06 [ERROR] Aborting

141207 18:58:06 [Note] /usr/libexec/mysqld: Shutdown complete

141207 18:58:06 mysqld_safe Number of processes running now: 1
141207 18:58:06 mysqld_safe mysqld process hanging, pid 15456 - killed
141207 18:58:06 mysqld_safe mysqld restarted
141207 18:58:06 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
141207 18:58:06  InnoDB: Initializing buffer pool, size = 6.0G
141207 18:58:06  InnoDB: Completed initialization of buffer pool
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
141207 18:58:06  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Last MySQL binlog file position 0 14626, file name /var/lib/mysql/mysql-bin.000892
141207 18:58:06  InnoDB: Started; log sequence number 3 2358701171
141207 18:58:06 [Note] Recovering after a crash using /var/lib/mysql/mysql-bin
141207 18:58:06 [Note] Starting crash recovery...
141207 18:58:06 [Note] Crash recovery finished.
141207 18:58:06 [Note] Event Scheduler: Loaded 0 events
141207 18:58:06 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.73-log'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution

There doesn't seem to be much information leading to a cause of why mysql is now so weak. Considering no my.cnf changes or otherwise have been made, I don't think it's a configuration issue.
Where should I be looking to get better data on this issue? Or is there a more 'hard' reset of sorts I can do to get things back to normal?
EDIT - Latest from the logs
Cleaned up my log files and restarted the server before running a load that it is currently crashing for (that it could previously handle just fine.)
Here is the latest output from the log file, everything from after the restart I performed before running the task. As far as I can tell, nothing that clues into the reason for the crash, correct?
141207 20:50:34 mysqld_safe Number of processes running now: 0
141207 20:50:34 mysqld_safe mysqld restarted
141207 20:50:35  InnoDB: Initializing buffer pool, size = 5.0G
141207 20:50:35  InnoDB: Error: cannot allocate 5368725504 bytes of
InnoDB: memory with malloc! Total allocated memory
InnoDB: by InnoDB 36878736 bytes. Operating system errno: 12
InnoDB: Check if you should increase the swap file or
InnoDB: ulimits of your operating system.
InnoDB: On FreeBSD check you have compiled the OS with
InnoDB: a big enough maximum process size.
InnoDB: Note that in most 32-bit computers the process
InnoDB: memory space is limited to 2 GB or 4 GB.
InnoDB: We keep retrying the allocation for 60 seconds...
141207 20:50:49  InnoDB: Completed initialization of buffer pool
InnoDB: Log scan progressed past the checkpoint lsn 3 2681111025
141207 20:50:49  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 3 2686353408
InnoDB: Doing recovery: scanned up to log sequence number 3 2691596288
InnoDB: Doing recovery: scanned up to log sequence number 3 2696839168
InnoDB: Doing recovery: scanned up to log sequence number 3 2702082048
InnoDB: Doing recovery: scanned up to log sequence number 3 2707324928
InnoDB: Doing recovery: scanned up to log sequence number 3 2712567808
InnoDB: Doing recovery: scanned up to log sequence number 3 2717810688
InnoDB: Doing recovery: scanned up to log sequence number 3 2723053568
InnoDB: Doing recovery: scanned up to log sequence number 3 2728296448
InnoDB: Doing recovery: scanned up to log sequence number 3 2733539328
InnoDB: Doing recovery: scanned up to log sequence number 3 2738782208
InnoDB: Doing recovery: scanned up to log sequence number 3 2739356250
InnoDB: 1 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 237115 row operations to undo
InnoDB: Trx id counter is 0 15792384
141207 20:50:50  InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
InnoDB: Last MySQL binlog file position 0 157660, file name /var/lib/mysql/mysql-bin.000902
InnoDB: Starting in background the rollback of uncommitted transactions
141207 20:51:07  InnoDB: Rolling back trx with id 0 15789484, 237115 rows to undo

InnoDB: Progress in percents: 1141207 20:51:07  InnoDB: Started; log sequence number 3 2739356250
141207 20:51:07 [Note] Recovering after a crash using /var/lib/mysql/mysql-bin
141207 20:51:07 [Note] Starting crash recovery...
141207 20:51:07 [Note] Crash recovery finished.
 2 3 4141207 20:51:07 [Note] Event Scheduler: Loaded 0 events
141207 20:51:07 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.73-log'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution
 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
InnoDB: Rolling back of trx id 0 15789484 completed
141207 20:51:11  InnoDB: Rollback of non-prepared transactions completed
141207 20:51:20 [ERROR] /usr/libexec/mysqld: Table './bck_wpdb/bck_statpress' is marked as crashed and should be repaired
141207 20:51:20 [Warning] Checking table:   './bck_wpdb/bck_statpress'
141207 20:52:19 [ERROR] /usr/libexec/mysqld: Table './mdi_db1/mdi_statpress' is marked as crashed and should be repaired
141207 20:52:19 [Warning] Checking table:   './mdi_db1/mdi_statpress'

Comment: You have provided no further information for us in this post than your last. Can you rule out that you aren't still trying to start mysql when it is already running? FYI you aren't even killing it properly. If the process is not responding to a sigterm, your syntax for trying to send a sigkill is incorrect. If you must use killall, it would be "killall -s SIGKILL mysqld".
Comment: "You have provided no further information for us in this post than your last."  I don't follow, my last post was an assertion error, that led to me dumping and restoring the DB. Different, and fixed, issue. This has been marked duplicate by a handful of people but the post referenced is not the same as this at all, I'm unsure as to what I'm missing. The last line is very helpful, although, as of this morning I don't seem to be having the issue.
Comment: You really should do a full dump and reload.
Comment: @MichaelHampton Surprisingly, this is actually just after doing a full dump and reload yesterday to resolve an assertion error.

With that said, the dump had to be done from recovery mode. Should I do a dump and reload now that I can access it without recovery mode? Would that make a difference?
Answer: This log entry is the key to the most likely issue:
141207 20:50:34 mysqld_safe Number of processes running now: 0

If there is not an extremely verbose block of log messages, including a stack trace, immediately before this line, then MySQL's not actually crashing... the kernel is killing it because another process (such as the web server) is making aggressive demands on the system for memory.  In a desperate attempt to relieve the pressure and avoid what is an impending system-wide crash or lock-up, the kernel goes scouting for a process to kill.
$ cat /var/log/messages | egrep -i 'mysql|oom|kernel'

Follow the trail from syslog.  You will most likely need to reign in your web server.
Everything after the log entry above is just MySQL trying to restart itself and recover from being killed.  In a case of severe memory shortage, it will fail to restart right away, because there's simply not enough system memory available:
141207 20:50:35 InnoDB: Error: cannot allocate 5368725504 bytes of
InnoDB: memory with malloc! Total allocated memory
InnoDB: by InnoDB 36878736 bytes. Operating system errno: 12

In Linux, Error 12 is indeed "out of memory."  And, again, that's not MySQL saying it's out of memory, that's the kernel.

Also noteworthy, 5,368,725,504 bytes seems like a very large buffer pool for an 8GB server, unless the server is doing nothing other than running MySQL.  A subjective rule of thumb for shared workloads is to allocate not more than 50% of system memory for the buffer pool.
The amount of memory you allocate, here, is claimed and held by MySQL and unavailable for other processes.  Generally, with this particular parameter, bigger is better... but only within reason based on available resources.
Comment: Ah, I figured that the last part was just mysql trying to restart itself. It turns out that for a bit it was maxing memory causing the system to kill it (turned up in `messages`). Although, even after that was fixed it still would die without leaving a log anywhere. I really appreciated that added info in troubleshooting - that's what I'm really trying to learn more about, so I come to the good people of ServerFault with better intel. I did wind up knocking the buffer pool donw to 4Gb, just for good measure.


meu codigo nao funciona python

Question: for i in x:
    print("Jogador 1, selecione a linha para ataque: ")
    LinhaAtaque1 = int(input("Linha do ataque: "))
    print ("Jogador 1, selecione a coluna para ataque: ")
    ColunaAtaque1 = int(input("Coluna do ataque: ")

    if board2[LinhaAtaque1][ColunaAtaque1] != "0":
        print("Você atingiu um navio!!!!!!!!")
        from random import randint

Answer: O código que você enviou está sem formatação adequada... Formatando aqui, notei um erro de sintaxe no trecho ColunaAtaque1 = int(input("Coluna do ataque: ").
Está faltando um ')' ao final do comando.

meu codigo nao funciona python


showing different radio buttons when choosing specific button

Question: I  am trying to make radio buttons where person chose options and different options appear for him/her to chose from. my code is :

$(document).ready(function() {
  $('input[type="radio"]').click(function() {
      if($(this).attr('id') == 'wanted') {
        $('.sec-row').show();
      }

      else {
        $('.sec-row').hide();
      }
  });

});

<form role="form" id="add_property" method="post" action="#">

            Purpose

                    <input type="radio" name="options1" id="forSale" autocomplete="off"> For Sale

                    <input type="radio" name="options1" id="rent" autocomplete="off"> Rent

                    <input type="radio" name="options1" id="wanted" autocomplete="off"> Wanted

            Wanted For

                    <input type="radio" name="options2" id="wf-buy" autocomplete="off"> Buy

                    <input type="radio" name="options2" id="wf-rent" autocomplete="off"> Rent

            Property Type

                    <input type="radio" name="options3" id="homes" autocomplete="off">Homes

                    <input type="radio" name="options3" id="plots" autocomplete="off">Plots

                    <input type="radio" name="options3" id="commercial" autocomplete="off">commercial

</form>

but the issue is I am not able to get active value when selecting certain radio button if I use data-toggle="buttons" in divs it works but js doesn't work that way. I need to make 2 or more lines of different radio buttons where they appear when some specific button is selected.
Answer: Use common name in radio button and pass value attribute too.

    Purpose

            <input type="radio" name="purpose" value="forSale" id="forSale" autocomplete="off"> For Sale

            <input type="radio" name="purpose" value="rent" id="rent" autocomplete="off"> Rent

             <input type="radio" name="purpose" value="wanted" id="wanted" autocomplete="off"> Wanted

$(document).ready(function() {
  $('input[type="radio"]').click(function() {
      var value = $("input[name='purpose']:checked").val();
      if(value == 'wanted') {
        $('.sec-row').show();
      }
      else {
        $('.sec-row').hide();
      }
  });

});

Comment: it works for sec-row those two can be seen selected and show() and hide() working well but can it be checked for every radio button i click? so user know which options hes been clicking and going down? thanks btw
Comment: i am using this answer so i will upvote this i removed the btn-group-toggle then it worked. its not complete yet as something else need to add but its what i got close to answer.
Answer: Use this code
<!DOCTYPE html>

    <title></title>

<form role="form" id="add_property" method="post" action="#">

                            Purpose

                                    <input type="radio" name="options1" id="forSale" autocomplete="off"> For Sale

                                    <input type="radio" name="options1" id="rent" autocomplete="off"> Rent

                                    <input type="radio" name="options1" id="wanted" autocomplete="off"> Wanted

                            Wanted For

                                    <input type="radio" name="options4" id="wf-buy" autocomplete="off"> Buy

                                    <input type="radio" name="options5" id="wf-rent" autocomplete="off"> Rent

                            Property Type

                                    <input type="radio" name="options6" id="homes" autocomplete="off">Homes

                                    <input type="radio" name="options7" id="plots" autocomplete="off">Plots

                                    <input type="radio" name="options8" id="commercial" autocomplete="off">commercial

                </form>

Comment: Radio buttons are used for multiple questions. If clicked any radio button in second row or third row, the second row will hide.
Comment: its working same as what i was using before i need radio buttons to show active where i click and yes 2nd row hide when clicked on third.
Comment: you can add same name of all radio button like that  For Sale, Rent, Wanted
Comment: i was naming them separate that was mistake, thanks for telling. but its not making it selected the first row and 2nd row always disapear when i click 3rd one only way its staying active when i use data-toggle but that makes js not working if i use it.
Comment: its still not working as i said 2nd div goes hidden again when 3rd is selected
Comment: i tried that didn't work i had to remove the btn-group-toggle class to make it  for now.
Comment: You will remove btn-group-toggle in every div?
Comment: yes thats what i did. then it let all of the answers here worked. but it did made them look not good.


IdentityServer4 encodes # in LoginUrl

Question: I am building a frontend for IdentityServer4 using AngularJS with ui-router, but if I set UserInteraction.LoginUrl to /index.html#!/login the # gets urlencoded, breaking angular.
I have been trying to fix this, but I cannot find any relevant posts or documentation.
For Angular, the query string unfortunately has to come after # for $location to work, so removing #!/login from the url is not a valid solution.
Comment: Is having a function-specific entrypoint an option? E.g. `/auth/login` which loads the same angular app but has logic to kick off the sign in flow client-side? `identityserver4` will want to pass a returnUrl query string parameter to it too so you'll need to accommodate that too.
Comment: I want to make it as simple as possible and avoid having to use mvc views and whatnot. I am well aware of passing the returnUrl, that is what I am trying to get to work after all :) if I set LoginUrl to `index.html#!/login` the redirect becomes `index.html%23!/login?RedirectUrl=...` or something similar, which breaks routing in angular
Comment: If it was me I'd just have a host page (either static file or served via MVC) for the angular app that bootstraps it with the entry point you need.
Comment: I have considered it, but it feels like a bad solution. having the client needing to do an extra jump just to work around what seems to me like a bug in the frameworks just doesn't sit right with me. My hope is that there is some obscure method of telling identityserver4 to not urlencode that # - or that angularjs fixes the $location services search method to look before the #.
Comment: I wouldn't call it a bug given that this is a server-side framework that it must be able to append query parameters and these must be before the fragment. I'd imagine the cookie middleware will work similarly too.
Comment: Not being able to specify the url I want to use isn't a bug? :p
Comment: Frustrating it may be but the analogy would be trying to hitch a trailer to a car that already has a bike rack on the back. It's reasonable for the trailer manufacturer to assume you won't do this when writing the manual.
Comment: I must be expressing myself unclearly, because you clearly do not understand what I mean. I want the url to be `index.html#!/login?RedirectUrl=...` but it becomes `index.html%23!/login?RedirectUrl=...`
Comment: And I'm saying it's reasonable to for the framework (IdentityServer4 and ASP.Net Core cookie authentication middleware) to mandate that the URL you specify does not include a hash fragment or any other parameters. Combining a client side framework that relies on the hash with a server-side framework that assumes you won't do that is an edge case basically but one that's simple to work around.
Comment: And I'm saying it is reasonable to be able to control the behaviour of the framework to match whatever needs the consumer of said framework have.
Comment: You'll have to take that up with Microsoft and the IdentityServer4 guys ;)
Answer: As a somewhat hacky workaround, adding a minimalist login.html with this script works;

But this is obviously not the ideal solution, as the client then has to make an extranous round trip to the server just to get redirected twice.
Answer: in my solution i basically used the below for User interactions. The actual SPA application was loaded because i was using usefileserver which also internally serves the default file "/Account/index.html" - I created account folder inside of wwwroot
Once the index.html is loaded, the angular route takes care of the rest
 services.AddIdentityServer(setupAction =>
    {
        setupAction.UserInteraction.LoginUrl = "/Account#Login";
        setupAction.UserInteraction.LogoutUrl = "/Account#Logout";
        setupAction.UserInteraction.ErrorUrl = "/Account#Error";
    })

I did not get any encoding issues

IdentityServer4 encodes # in LoginUrl


Project war file does not occur in dist folder

Question: I run clean and build in netbeans web project.Past ,the war file was created in the dist folder. However I do same thing, but it was not created in dist folder. How can solve this problem?
Answer: Check the logs as it produces when you do clean and build using netbeans.It might show you the contexts and some paths it uses for creating a war.May be some of them might be missing.If it still does not help
try this

Stop the server.
Do clean and build and it will produce the war file now.
check the logs again.


Can K-fold cross validation cause overfitting?

Question: I am learning $k$-fold cross validation. Since each fold will be used to train the model (in $k$ iterations), won't that cause overfitting?
Comment: Please keep in mind that training restarts after every iteration, with the model "forgetting everything it knew about the data"
Comment: FYI: [How does cross-validation overcome the overfitting problem?](https://stats.stackexchange.com/questions/9053/how-does-cross-validation-overcome-the-overfitting-problem)
Comment: *"No. Each fold is used to train a new model from scratch, predict the accuracy, and then the model is discarded. You don't use any of the models trained during CV."* But when ı used k fold cv, ı see that accuracy increasing each fold, smallest one is initial fold, is it just a coincidicence?
Answer: K-fold cross validation is a standard technique to detect overfitting. It cannot "cause" overfitting in the sense of causality.
However, there is no guarantee that k-fold cross-validation removes overfitting. People are using it as a magic cure for overfitting, but it isn't. It may not be enough.
The proper way to apply cross-validation is as a method to detect overfitting. If you do CV, and if there is a big difference between the test and the training error then you know you are overfitting and need to get more diverse data or choose simpler models and stronger regularization. The contrary does not hold: no big difference between test and train error does not mean you haven't been overfitting.
It's not a magic cure, but the best method to detect overfitting we have (when used right).
Some examples when cross-validation can fail:

data is ordered, and not shuffled prior to splitting
unbalanced data (try stratified cross-validation)
duplicates in different folds
natural groups (e.g., data from the same user) shuffled into multiple folds

There are other cases where it cannot detect information leakage and overtitting even when used perfectly right. For example when analyzing time series, people like to standardize the data, split it into past and future data, then train a model to predict the future development of these stocks. The subtle information leakage was in the preprocessing: standardization prior to temporal splitting leaks information about the average of the remainder. Similar leaks can occur in other preprocessing. In outlier detection, if you scale the data to 0:1, a model can learn that values close to 0 and 1 are the most extreme values you can observe etc.
Back to your question:

Since each fold will be used to train the model (in  iterations), won't that cause overfitting?

No. Each fold is used to train a new model from scratch, predict the accuracy, and then the model is discarded. You don't use any of the models trained during CV.
You use validation (such as CV) for two purposes:

Estimate how good your model will (hopefully) work in practise when you deploy it, without risking a real A-B-test in production yet. You only want to go live with models that are expected to work better than you current approach, or this may cost your company millions.
Find the "best" parameters for train your final model (which you want to train on the entire training data). Tuning hyperparameters is when you have a high risk of overfitting if you are not careful.

CV is not a way of "training" a model by feeding 10 batches of data.
Answer: On the contrary, cross-validation is a good way to combat overfitting!

Why $k$-fold CV?
Suppose you have a model and you want an estimate of its out-of-sample performance...
You could assess the prediction error on the same data used to fit the model (i.e. the training error), but this is obviously not a good indicator of out-of-sample performance. If the model is indeed overfitting, it will perform poorly on new observations, but you will still observe a low training error.
Alternatively, you could split your data into two part (train/test) and only use the train set to fit the model. The rest of the data, never seen by the model in any way, is then used to get an estimate of the out-of-sample performance. Great! But what if we had used a different split? As it turns out the variance between results obtained from different splits can be quite large... so large in fact, that data splitting is only reliable for really large $n$.
This is what $k$-fold CV attempts to tackle, by doing the following repeatedly:

Fit your model with $n - \frac{n}{k}$ observations;
Observe its performance on the remaining $\frac{n}{k}$ observations, which were not used to fit your model.

You repeat this process $k$ times, each time leaving out the next $\frac{n}{k}$ observations for testing, until all observations have been used once as a test set. You then sum the errors on the test set of each fold (or compute a weighted average), and you have an estimate of out-of-sample performance that is less sensitive to the particular splits used, because there are now $k$ of them.$^\dagger$

Can this cause overfitting?
Now to answer your question:

Since each fold will be used to train the model (in $k$ iterations), won't that cause overfitting?

Each fold is indeed used to train the same model... from scratch. So while there is indeed overlap between training sets, and thus you are indeed fitting models on (partially) the same data multiple times, you are not reusing the data to update your estimates!
If your model would overfit in a particular fold, then the training error of that fold would be lower than the testing error of that fold. Hence, when summing/averaging the errors of all folds, a model that overfits would have low cross-validated performance.

$\dagger$: Even better, if you can afford it computationally, is to repeat $k$-fold CV multiple times.


Inteiro muito grande não funciona

Question: Meu código está assim:
#include <stdio.h>

int main()
{
    unsigned long int L, N;
    scanf("%lu%lu", &L, &N);

    printf("%lu\n", (L-(N-1))*(L-(N-1)) + (N-1));

    return 0;
}

Quando o caso de teste tem números baixos, o programa funciona. Porém, quando os números estão além da capacidade do unsigned long int, com entradas como 1.000.000 e 9 (a resposta correta seria 999984000072) o programa dá a resposta errada.
Como posso operar com inteiros maiores?
Answer: Se tiveres uma implementacao de C99, podes experimentar unsigned long long. Este tipo tem que existir, mas pode nao ser maior que unsigned long --- e, portanto, pode nao te resolver o problema.
Verifica com, por exemplo sizeof (unsigned long) == sizeof (unsigned long long)
Se poderes usar este tipo, lembra-te de usar "%llu" tanto nos printfs como nos scanfs.
Nesse caso, ou usas uma biblioteca para numeros grandes ou fazes a tua versao de multiplicacao de numeros como aprendeste na escola primaria (um projecto muito interessante).
Comment: ou ainda ... *faz batota: `sprintf(cmd, "echo 'n=%lu; l=%lu; print (l-(n-1))*(l-(n-1))+(n-1)' | python", n, l); system(cmd);`*
Comment: Oh! So mais uma coisa. As strings de conversao para `unsigned long long` usam `%llu` tanto no printf como no scanf.
Answer: Utilize o tipo unsigned long long e seja feliz.

Inteiro muito grande não funciona


Key / Value fields module where you can choose the type?

Question: Is there a module which creates a field where you can choose the field type of the key and also the value during content type creation?
Answer: You can use the Field Collection module to achieve that functionality:

Provides a field-collection field, to which any number of fields can be attached.
A field collection is internally represented as an entity, which is embedded in the host entity. Thus, if desired field collections may be viewed and edited separately too.

The idea is:

Create a Field Collection.
Add key/value fields to it with the field types of your choice.
Add a Field Collection field to the content type you want these key/value fields on.
Set the source of that Field Collection field to the new Field Collection you've just created.
Repeat for whatever other content types you need to.
Comment: Thanks, I've always tried to avoid the field collection because it creates an actual entity from the fields. It's a shame you can't group fields without doing this.
Comment: Yeah Field Collection is a weird one (I try to avoid it to wherever possible), but short of writing your own field type I think it's the simplest way to get what you're looking for
Comment: As an update to this - if you're looking to create nodes programmatically, I'd certainly recommend you avoid this module - use entity reference and views and a separate content type. (EVA allows you to embed views as a field) I just found out the hard way that field collection isn't the best solution to this problem!
Comment: And furthermore, if you want 0 instances of your field collection (that is, allow optional instances of your field collection to be specified), it seems you can't


How do I shown that $x_{n+1}=x_n/2 + 1$ converges to $2$?

Question: Let  $\{x_n\}$ be a converging sequence such that
$$x_{n+1}=\frac{x_n}{2}+1$$
Show that $\{x_n\}$ converges to $2$. I am lost I have no idea how to begin.
These are my questions so that I can better understand the problem.
What does $x_{n+1}$ tell me? What is $x_{n+1}$ significance in relation to $x_n$.
Comment: No problem mate, glad to see Arpan has you taken care of :D
Comment: I cannot seem to follow what this post is trying to say. What does "f x n g" mean? I can't quite tell how the sequence is defined, is the $x_n$ in the denominator? What about that $+1$?
Comment: f x n g thats an error. The sequence {xn} is not in the denominator. The plus one is not in the denominator either.   x(n+1)= (1*{xn})/2) +1
Comment: Sorry I don't know how to add math type. I'm gonna look that up.
Comment: Prove its is bounded above by 2 and increasing
Comment: Check, if you can apply Banach fixed-point theorem and solve $x=\frac{x}2+1$.
Answer: $x_{n+1} = \dfrac{x_n}{2} + 1 \to x_{n+1} - 2 = \dfrac{x_n-2}{2} = \dfrac{x_{n-1}-2}{4} = \cdots = \dfrac{x_1-2}{2^n} \to 0 \Rightarrow x_{n+1} \to 2$.
Comment: I do not understand how you determined  the x_{n-1} term  from      (xn-2)/2 =(x_{n-1}-2))/4.
Comment: It comes from the recursive formula and replacing $n$ by $n-1$ you get: $\dfrac{x_n-2}{2} = \dfrac{\dfrac{x_{n-1}-2}{2}}{2}$
Comment: Sure. Hope you find it useful....


Is there a way to use svnsync with a repository loaded from a dump file?

Question: I created a new repository A.
Ran svnsync init with repository B as the source.
Loaded a dump file from B (rev 0 to 1690 of 1801) to A.
Then tried to run svnsync. My thinking was that svnsync could pick up where the dump file left off.
This is the error:
svnsync: Destination HEAD (1690) is not the last merged revision (0); have you committed to the destination without using svnsync?

Is there a way to make svnsync think it has already synced up to the current rev?
Answer: After the loading the dump file, you can run this command:
svn propset --revprop -r0 svn:sync-last-merged-rev 1690 https://mysvn.com/svn

All SYNC properties are stored in [repository]\db\revprops\0\0. You can inspect and modify other properties there, but do it with caution. You can easily corrupt the settings. I recommend using the command line rather than manually editing the 0 file.


Why HTTP GET with Request body in swagger & node js NOT working?

Question: I'm trying to Send a GET request to my api to obtain some result. i'm using x-www-form-urlencoded. I successfully get the result using the following curl:
curl -k -X GET https://localhost:8443/parser -H 'accept: */*' -H "Content-Type: application/x-www-form-urlencoded" -d "mydata=1"

the '-k' is because I'm using https.
However, when I'm using the following swagger in Nodejs
 * @swagger
 * /parser:
 *   get:
 *     summary: Get scenario validation result.
 *     requestBody:
 *       content:
 *         application/x-www-form-urlencoded:
 *           schema:
 *             type: object
 *             properties:
 *               mydata:
 *                 type: string
 *
 *     responses:
 *       200:
 *         description: success
 */

it returns an error TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
and the curl appeard as the follwoing :
curl -X 'GET' \
  'https://localhost:8443/parser' \
  -H 'accept: */*' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'mydata=8.1'

any hint?
Answer: GET is not supposed to have a request body, and OpenAPI 3.0 Specification explicitly does not allow requestBody in GET, HEAD, and DELETE requests. (This restriction was later lifted in OAS 3.1 though.) When using GET, you can send data in the URL query string (http(s)://...?key1=value1&key2=value2&...) or request headers instead.
If you must use a request body (e.g. if the payload is huge or has a complex structure), use POST, PUT, or PATCH instead, depending on the request semantics.
Comment: Thanks for your answer! I'm sending in a Get Request a 4 kb text which is a language syntax to validate the lang and return the result so there is no need for post. My API is only configured with GET requests. What do you think should i do ?
Comment: Sounds like a typical use case for POST to me. Change your API to use POST instead of GET. Problem solved.


Exercise in Wiener processes

Question: Exercise is from the book "Wstęp do rachunku prawdopodobieństwa" Jakubowski, Sztencel
I need to show that family of random variables given by $$ Y_t = tW_{1/t},\,t>0 $$
And $Y_0=0$ where $W_t$ is a Wiener process is also a Wiener process.
I'm stuck with showing that the trajectory is continuous, i. e. that $$ \lim_{t\to 0^+} Y_t = 0 $$
How can I show that the trajectory is continuous? If possible, I'd like an advice rather than full answer.
My professor said something about the law of iterated logarithm (which is unkown to me).
Thank you
Comment: @tatan I've edited my question with the source
Comment: This looks like a problem you have collected from some source. According to recent discussions in Meta, we are looking forward to including sources for all applicable questions. Can you provide the source by editing the question?Refer-https://math.meta.stackexchange.com/questions/29290/is-it-a-good-idea-to-include-source-from-where-a-question-is-taken
Comment: Thanks! This would help future answerers and readers ;-)
Answer: The law of iterated logarithm for Brownian motion says
$$
\limsup_{t\to\infty}\frac{B_t}{\sqrt{2t\log\log t}}=+1 \text{ a.s.}
$$
(and symmetry about $0$ gives liminf is -1 a.s.).  You might have seen this for the sum of zero-mean unit-variance independent random variables, sitting between the law of large numbers $\mathbb{P}(S_n/n\to0)=1$ and the central limit theorem $S_n/\sqrt{n}\sim N(0,1)$.  Can you finish it off from here?
Comment: Well, look at page 121 onwards [here](https://www.stat.berkeley.edu/~peres/bmbook.pdf), for example.
Comment: Thank you. Do you know any reference to the law of iterated logarithm, including it's proof?

Exercise in Wiener processes


How to calculate joint distribution by integrating over all possible values of model parameters and observations

Question: I was wondering how to calculate the following joint distribution by assuming that $x_i$'s are continuous observations from normal distirbution $N(\mu, \sigma)$ with mean $\mu$ and variance $\sigma$ and $p(\mu, \sigma)$ is the joint distribution of $\mu$ and $\sigma$:
$$
p(x_1,x_2,..., x_n, x_{n+1}) = \iint {\displaystyle \prod_{j=1}^{n+1} N(\mu,\sigma)|_{x_j}} . p(\mu, \sigma) \,d\mu \, d\sigma
$$
I know that this can be accomplished by solving the intergration numerically (e.g. with rectangular integration), however, the thing that puzzles me is that the products of $N(\mu,\sigma)|_{x_j}$ would be always zero since the probability of the point $x_i$ in a continuous distribution  $N(\mu,\sigma)$ is zero (or I'm wrong?).
In addition, what is the best method to calculate (or estimate) this distribution in python?
Answer: Ok, this looks like deep learning related stuff, maybe an exercise.
$N(\mu,\sigma)|_{x_j}$ is not the probability of a point $x_j$, this is the density of point $x_j$ given the parameters $\mu, \sigma$. The total integral is not the probability either, it is the likelihood of sorts or a density function. The whole thing is in fact never a zero, because the density $N$ of normal distribution is never zero, it can be very small of course.
Comment: Thanks. Do you have any suggestion for the implementation in python? I've used `dblquad` for the integration but it takes a lot of time for evaluating a series of let's say 20 observations. I think the slowness of the integration is related to the fact that the p(μ,σ) is calculated using the product of two log-normal distribution but I simply use linear (not exponential) interval for the integrands.
Comment: I'm not sure someone intended to integrate this numerically. They may have written the equation to get across the concept. Multidimensional integration is very difficult beyond 2-3 dimensions, it's heavy computationally. You may want to integrate analytically or re-consider whether you need to integrate at all. If need help on integration though, it's better to post a separate question. There's a chance the question would be considered off-topic and moved to other SE or SO sites
Comment: But this formula comes from a paper in which the authors used numerical integration via a simple quadrature rule. Since the integrands are represented by log-normal distributions, they have used a rectangle rule in which the intervals between interpolation points vary exponentially.
But I don't know how to use the rectangular rule of integration with exponential intervals for the interpolations.
Comment: What was dimensionality?
Comment: The observations have only one dimension.


Dividir arquivo - como definir a parte que o arquivo se quebra

Question: Olá, eu estou utilizando um script que divide um arquivo em várias partes
Como eu faço para realizar essa divisão a partir de uma palavra já definida?
Ex: eu quero que ele divida em partes toda vez que a palavra ''id'' aparecer no arquivo
from math import ceil
from os import stat, mkdir
from os.path import exists, dirname, realpath

class Arquivo():
    def dividir (arquivo, partes):

        pasta_partes = dirname(realpath(__file__))+"\\partes\\"
        if not exists(pasta_partes):
            mkdir(pasta_partes)

        arquivo_primario = open(arquivo, "rb")
        parte = 0
        maximo = ceil(stat(arquivo).st_size / partes)

        while (parte < partes):
            parte += 1
            dados = arquivo_primario.read(maximo)
            arquivo_parte = open(pasta_partes + arquivo + ".parte" + str(parte), "wb")
            arquivo_parte.write(dados)

            arquivo_parte.close()
        arquivo_primario.close()

Arquivo.dividir ('results.json', 10)

Comment: Por favor, esclareça seu problema ou forneça detalhes adicionais a fim de destacar exatamente o que você precisa. Da forma como está escrito atualmente é difícil dizer com exatidão o que você está perguntando.
Answer: Bom, primeiro de tudo não tem muito sentido usar uma classe se a única função do seu algoritmo for particionar arquivos. Além do mais, o certo é class Arquivo:, sem os parênteses. Outra questão é que se o seu objetivo é separar o arquivo de acordo com alguma palavra-chave (como "id"), não faz sentido pedir o número de partes no qual o arquivo será dividido como argumento.
Se os arquivos que você se refere são de texto, então eis aqui uma solução bem simples.
def particionar(diretorio):
    with open(diretorio, 'r') as arquivo_alvo:
        conteudo = arquivo_alvo.read()
        lista_de_partes = conteudo.split('\n')
        for n, parte in enumerate(lista_de_partes):
            with open('parte' + str(n + 1) + '.parte', 'w') as arquivo_parte:
                arquivo_parte.write(parte)

particionar('texto.txt')

Nesse exemplo, criei um arquivo texto.txt com o seguinte conteúdo:
Minha terra tem palmeiras
Onde canta o sabiá
As aves, que aqui goerjeiam,
Não gorjeiam como lá

O código consiste em ler todo o arquivo e guardar seu conteúdo numa string usando arquivo_alvo.read(); em seguida separar esta string numa lista de strings usando conteudo.split() (que, no meu caso, especifiquei como separador a quebra de linha \n, o que na prática quer dizer que terei uma lista de linhas do texto); e finalmente escrevendo cada uma das partes em arquivos separados. O resultado, como esperado, foram quatro arquivos, cada um contendo uma linha do texto original.
Fazer deste jeito implica em carregar o arquivo inteiro na memória. Não sei se o Python tem algum truque na manga, mas como você vai dividir o arquivo e guardá-lo em partes numa lista, acredito que ele acaba entrando duas vezes na memória. Isso é um problema grave se estivermos falando de arquivos muito grandes ou caso queiramos uma solução muito otimizada para rodar em algum servidor ou algo assim.
Dividir o arquivo em um número definido de partes é menos custoso nesse sentido, porque daí não é preciso carregá-lo por inteiro na memória (é mais rápido também).
Comment: Cara isso resolveu muito o meu problema!
Mas saberia me dizer se tem como salvar isso em formato JSON? quando ele cria os novos arquivos?
tipo converter para JSON quando ele divide os arquivos
Comment: Sim, o Python tem um módulo da biblioteca padrão que se chama simplesmente `json`. Aí, geralmente você vai querer guardar os dados no formato de dicionário. Digamos que seja `d` o seu dicionário. `json.dumps(d)` vai retornar uma string com o formato JSON, que você pode simplesmente escrever no arquivo.


Given that $a>1$, show that the exponential function $a^x$ is increasing for $x\in\mathbb{Q}$

Question: The assumption one can make here is that it is increasing for $x\in\mathbb{Z}$. I have tried to make a proof but I'm not sure if it is valid. Here it goes.
Say $x,y\in\mathbb{Q}$. Then they can be written $x=\frac{p}{q},y=\frac{m}{n}$, with $q,n>0$. Because $$\frac{p}{q}=x<y=\frac{m}{n},$$
it must also hold that $pn<qm$. This implies that $a^{pn}<a^{qm}$. This would imply that $a^{\frac{p}{q}}<a^{\frac{m}{n}}$, QED.
It feels like the last step, namely "This would imply that $a^{\frac{p}{q}}<a^{\frac{m}{n}}$" in this proof depends on the fact we're trying to prove. Am I correct? If so, any suggestions as to what approach I should use to prove this theorem?
Comment: What you need is the monotonicity of $x \mapsto x^{1/k}$ for $x > 0$ (with $k = pq$). Can you deduce that from the monotonicity of $x\mapsto x^k$?
Comment: You don't even need continuity for that. (Well, you need it for the inverse to be defined everywhere.)
Comment: Wow, yeah, right! I can deduce it from the fact that the inverse of a monotone function is monotone, right?
Answer: You can just do a proof by contradiction... if $a^{p \over q} \geq a^{m \over n}$, then
use the monotonicity of $x \rightarrow x^{qn}$ to get that $a^{pn} \geq a^{mq}$, a contradiction. Don't even have to worry about inverses of monotone functions.


Apagar um determinado repositorio do github

Question: Como faço para apagar apenas um repositorio do github?
Answer: Vai no seu repositório, settings, delete repositório.
Quando vc clicar pra deletar, abrirá um pop-up em que você digitara o nome do repositório.
Comment: Vlw achei aqui tmj!!
Comment: Por nada parceiro. Tmj
Answer: Vá no repositório, settings e delete o repositório.
Veja o tutorial:
https://help.github.com/articles/deleting-a-repository/
Comment: Obrigado pela atenção!
Answer: Vá até o repositório que deseja excluir, em seguida clique na aba Settings

Em seguida role até o final na tela e encontre onde está demarcado em vermelho e escrito Danger Zone

Clique na ultima opção: Delete this repository
Será solicitado que você confirme que deseja remover o repositório digitando o nome do mesmo.


Grouping per column in mysql

Question: I have this data below
item    category    accounts
ITEM1   CATEGORY1   ACCOUNT1
ITEM2   CATEGORY1   ACCOUNT1
ITEM3   CATEGORY2   ACCOUNT2
ITEM4   CATEGORY2   ACCOUNT2
ITEM5   CATEGORY3   ACCOUNT3
ITEM6   CATEGORY3   ACCOUNT3

And was wondering what's the better way so I can get it to output like
item    category    accounts
ITEM1   CATEGORY1   ACCOUNT1
ITEM2   CATEGORY1
ITEM3   CATEGORY2   ACCOUNT2
ITEM4   CATEGORY2
ITEM5   CATEGORY3   ACCOUNT3
ITEM6   CATEGORY3

I have tried using UNION:
SELECT
item,
category,
account

FROM t1

UNION

SELECT NULL,NULL,account from t1

But the result I got was
item    category    accounts
ITEM1   CATEGORY1   ACCOUNT1
ITEM2   CATEGORY1   ACCOUNT1
ITEM3   CATEGORY2   ACCOUNT2
ITEM4   CATEGORY2   ACCOUNT2
ITEM5   CATEGORY3   ACCOUNT3
ITEM6   CATEGORY3   ACCOUNT3
NULL    NULL        ACCOUNT1
NULL    NULL        ACCOUNT2
NULL    NULL        ACCOUNT3

Any suggestion on how I can make it possible? Thank you
Answer: You could do this:
SELECT @acct := null;
SELECT item, category, (if(@acct = account, '', @acct := account)) account FROM items;

But I wouldn't really recommend doing that except as a way to more conveniently view the result from the mysql cli tool. (You'll probably also want to adjust the select query and specify an appropriate ORDER BY.)

Grouping per column in mysql


Java CardLayout events

Question: i have been doing some game programming recently and I am using a CardLayout to switch between different screens (Main Menu, Game Screen, Game Over, etc...)
My question is, every time I switch screens does the previous become "inactive", so lets say I switch from Canvas to Main Menu, are the methods such as pain(), painComponent(), and the game ticks still being called, or is the Canvas "inactive:="
In other words, when I switch would I have to manually stop the game, or does CardLayout do that already?
Answer: This is easy to test on your own.  Simply put a logging statement in your paintComponent method of the inactive panel and see if it prints when the card is not displayed.
This code shows that it's only calling paintComponent on the first panel:
<code>package com.sandbox;

import javax.swing.*;
import java.awt.*;

public class SwingSandbox {

    public static void main(String[] args) {

        JFrame frame = buildFrame();
        JPanel cards = new JPanel(new CardLayout());

        cards.add(new JPanelThatPrints("1"));
        cards.add(new JPanelThatPrints("2"));
        cards.add(new JPanelThatPrints("3"));

        frame.add(cards);
    }

    private static JFrame buildFrame() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(200, 200);
        frame.setVisible(true);
        return frame;
    }

    private static class JPanelThatPrints extends JPanel {

        private String message;

        public JPanelThatPrints(String message) {
            this.message = message;
        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            System.out.println(message);
        }
    }
}
</code>
Comment: thank you :) that answered my question,not sure why I didn't think of doing that before :)

Java CardLayout events


Adicionar vários telefones em um telephone_field no rails

Question: Estou fazendo um cadastro de clientes aqui para loja e acontece que alguns clientes tem mais de 2 números de telefones o sistema já funciona com dois campos de telefone um fixo e um celular :
<code><%= f.label :telcelular , "Tel. Celular" %>
<%= f.telephone_field :telcelular %>

<%= f.label :telfixo , "Tel. Fixo" %>
<%= f.telephone_field :telfixo %>
</code>
Não há como eu criar um campo para cada telefone, já que não sei a quantidade de números de telefone que cada cliente possui, há alguma possibilidade de salvar todos os telefones somente em um campo?
Comment: O mais correto seria criar uma tabela `telefones` que contém uma referência para cliente (`cliente_id`). Você pode por tudo em um formulário usando Nested Attributes ([1](http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html) [2](http://www.sitepoint.com/complex-rails-forms-with-nested-attributes/) [3](http://highaltitudehacking.wordpress.com/2009/11/10/getting-the-right-html-for-rails-nested-model-forms/)), mas eu nunca tentei usar isso. O mais fáicl é criar um formulário separado só para adicionar os telefones.
Comment: Usando Nested Attributes fica fácil de fazer. E tem como deixar no formulário um botão para ir adicionando campos para telefones caso seja necessário. Pode dar uma olhada nesse exemplo http://railscasts.com/episodes/196-nested-model-form-part-1
Answer: Uma sugestão que não iria afetar muito o que já existe seria serializar esses campos. O postgress por exemplo permite que você armazene nele um array, e o Rails possui funções para serializar esse array.
O único problema acredito seria serializar os objetos que já estão no banco. No mais assim você poderia ter quantos telefones quiser em um campo só. Bastaria uma mudanças no modelo, controlador e um Javascript para imprimir mais campos na view...


Why an InputStream obj cannot be nested into a BufferedReader obj directly?

Question: An OutputStream obj can be connected into a PrintWriter obj directly, e.g.,

//either is OK
new PrintWriter(socket.getOutputStream());
new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));

But in the case of an InputStream obj, it must be connected to a BufferedReader obj through an InputStreamReader obj, that is,

new BufferedReader(new InputStreamReader(socket.getInputStream())); //OK
new BufferedReader(socket.getInputStream()); //doesnt work

Is there any reason for this inconsistency of API design?
Answer: There isn't any inconsistency... you should be comparing BufferedReader and BufferedWriter. They exist to wrap other Readers and Writers respectively.
The basic reason for that is that different types of Readers and Writers may have different ways of being initialized and different ways of functioning, not necessarily wrapping an InputStream or OutputStream at all. In your example of a BufferedReader wrapping an InputStreamReader, InputStreamReader can (and generally should) be initialized with both an InputStream and a Charset. Should BufferedReader have an overload for that, when its only job is to provide buffering?
Comment: "InputStreamReader can (and generally should) be initialized with both an InputStream and a Charset"  That's true, but the same applies to `OutputStreamWriter` and `PrintWriter`.  You should specify a charset when creating an `OutputStreamWriter`, but `PrintWriter` doesn't have an overload for that.  And PrintWriter also exists partly to wrap `Writer` objects (of any type).
Comment: @Matthew Flaschen: Some classes in the IO package are handled rather poorly as far as charsets. `PrintWriter` and `FileReader` are examples. I think `PrintWriter` should probably only be allowed to wrap another `Writer` (rather than having all the other overloads) and `FileReader` just shouldn't be used... `FileInputStream` + `InputStreamReader` instead.
Comment: I agree.  And the fact that some classes rely solely on the default encoding, while others don't, is evidence that the package is partly inconsistent.
Answer: Java introduced Reader and Writer hierarchy (java 1.1 I think) when Input and output stream classes were already in use. Therefore using a bridge pattern they allow you to have stream classes passed into reader classes.
Further for writer also PritnerWriter is directly the bridge class which is equivalent to InputStreamReader. You will see the same thing for BufferedWriter too
For more info read up http://www.codeguru.com/java/tij/tij0114.shtml
Comment: Actually, `OutputStreamWriter` is the equivalent of `InputStreamReader`. `PrintWriter` is just an adapter that allows you to use the methods from `PrintStream` for writing to another `Writer`.
Answer: The BufferedReader is probably just decorating the InputReader being passed in.  It makes no sense for a BufferedReader to accept a class it can't decorate, like an InputStream.
Comment: So does it mean there are other choices when connecting an InputStream obj to a BufferedReader besides through an InputStreamReader ?
Comment: I believe the InputStreamReader is a 'bridge' between a Reader and an InputStream.  Read Fazal's answer below.


Panels problem with changing the width of columns or regions

Question: Some times when I try to change the width of columns or regions with Fluid Width the panels displays the NAN% and it doesn't change the width

Using Firebug I got the following error

What should I do?

UPDATE
It only displays this javascript error in console in flexible-admin.js file
splitter.parent.css('padding-right', (splitter.right_padding + moved) + 'px');

Comment: You might want to include the error as text so people can find it via search engines.
Comment: @ShawnConn I updated the question
Answer: I found it. when the current language of the site is rtl such error reported. it must be ltr


Keepalived: NAT VIP for internal network unused?

Question: I'm building a proof-of-concept loadbalancer with CentOS 7 and keepalived.
I took Red Hat's load balancer administration guide as a reference and implemented a NAT'ed loadbalancer with 2 nodes which carries traffic between a public and a private network.
To that effect, the loadbalancer has 2 VIPs: one for client traffic, on the public network; and one for ensuring failover for response traffic, on the private network.
The 2 loadbalancers (lb1 and lb2) are sending traffic to 2 hosts running apache (fe1 and fe2) on the internal network. lb1 is master, lb2 is backup.
Diagram is as follows:

The loadbalancer works, and fails over as expected when one of the directors goes down.
What is bugging me is that the incoming traffic on the real servers isn't coming from the internal VIP (10.10.33.254), but from the loadbalancer hosts' real addresses (10.10.33.2 and 10.10.33.3).
Ping from the real servers is also going through real IP addresses, and not the internal VIP, despite it being set as the default gateway for them.
Traceroute (lb1 as active):
[root@rsfe2 ~]# tracepath www.google.com
1:  rsfe2                                                 0.081ms pmtu 1500
1:  10.10.33.2                                            0.385ms
1:  10.10.33.2                                            0.385ms
2:  no reply
3:  192.168.1.1                                           1.552ms

(lb1 down, lb2 as active):
[root@rsfe2 ~]# tracepath www.google.com
1:  rsfe2                                                 0.065ms pmtu 1500
1:  10.10.33.3                                            0.463ms
1:  10.10.33.3                                            0.462ms
2:  no reply
3:  192.168.1.1                                           2.394ms

Routing table:
[root@rsfe2 ~]# ip route
default via 10.10.33.254 dev enp0s8  proto static  metric 1024
10.10.33.0/24 dev enp0s8  proto kernel  scope link  src 10.10.33.12

Despite this apparent anomaly, failover from one loadbalancer to the other works as expected from the clients' standpoint, seemingly due to the gratuitous ARPs from the surviving loadbalancer.
It seems that the internal VIP is not used for anything except ARP announcements, in the end (there is no traffic to or from it).
Should I be concerned about this, or is it working as expected?
My keepalived.conf contents:
global_defs {
    notification_email {
        firstname.lastname@example.com
        email@example.com
        email@example.com
    }
    notification_email_from firstname.lastname@example.com
    router_id LVS_DEVEL
}

vrrp_sync_group VG1 {
    group {
        RH_EXT
        RH_INT
    }
}

vrrp_script check_haproxy {
    script "/bin/pkill -0 -F /var/run/haproxy.pid"
    interval 1
    fall 1
    rise 5
}

vrrp_instance RH_EXT {
    state MASTER
    interface enp0s3
    virtual_router_id 50
    priority 101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass password123
    }
    virtual_ipaddress {
        192.168.10.80
    }

    track_script {
        check_haproxy
    }

    track_interface {
        enp0s3
    }
}

vrrp_instance RH_INT {
    state MASTER
    interface enp0s8
    virtual_router_id 2
    priority 101
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass password123
    }

    virtual_ipaddress {
        10.10.33.254
    }

    track_script {
        check_haproxy
    }

    track_interface {
        enp0s8
    }
}

virtual_server 192.168.10.80 80 {
    lb_algo rr
    lb_kind NAT

    real_server 10.10.33.11 80 {
        HTTP_GET {
                url {
            path /check.html
        }
        }
    }
    real_server 10.10.33.12 80 {
        HTTP_GET {
                url {
            path /check.html
        }
        }
    }
}

Comment: Would you please share any finding to this case?
Comment: I'm facing this problem and already solved by configure firewall rules. https://docs.oracle.com/cd/E52668_01/E54669/html/section_j4j_ll2_4r.html
Answer: I am fairly certain that you are actually using the VIP in this case. The reason you are seeing the native IP is simply due to the nature of traceroute. Each hop is designed in a way for the device to generate an ICMP error, which the system will always send using its adapters primary address.
Answer: I think you should try input from external network to VIPs to double-checks, I see the config is fine. The reason you see the IP in traceroute due to the nature of it.


Selenium C# The status of the exception was ReceiveFailure, and the message was: The underlying connection was closed

Question: "  Message=A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:49803/session. The status of the exception was ReceiveFailure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive."
So I have a handful of tests which work with Chrome. I am testing out on Edge (for now, the rest of the browsers later).
The method I am running which is failing is:
            public void Load(string Url, Browsers Browser)
        {
            this.Url = Url;
            this.Browser = Browser;
<code>        IWebDriver driver;

        switch (Browser)
        {
            case Browsers.Edge:
                driver = new EdgeDriver(driverLocation);
                driver.Manage().Window.Maximize();
                break;
            case Browsers.Chrome:
                ChromeOptions options = new ChromeOptions();
                options.AddArgument("--start-maximized");
                driver = new ChromeDriver(driverLocation, options);
                break;
            case Browsers.Firefox:
                driver = new FirefoxDriver(driverLocation);
                driver.Manage().Window.Maximize();
                break;
            default:
                driver = new ChromeDriver(driverLocation);
                break;

        }
        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
        Driver = driver;
        driver.Url = this.Url;
    }
</code>
Where the browser passed in is edge.
<code>                driver = new EdgeDriver(driverLocation);
                driver.Manage().Window.Maximize();
                break;
</code>
The browser loads, then I receive the error above.
I have checked my OS build (17763.437) and downloaded the latest WebDriver (Release 17134) cuz that is all there is. I see no info on Edge specific stuff I need. My search foo is pathetic however.
Help lease
Answer: The driver for Edge version 18, which shipped with Windows 10 build 17763, became a "feature on demand" for Windows, and is not generally downloadable as a separate download on the web. See the "Installation and Usage" section on the Microsoft WebDriver documentation page for information on how to install and use it.
Comment: @user2919960 The default constructor (`driver = new EdgeDriver();`) will suffice. The driver is installed to `%WindowsDirectory%\System32`, if memory serves, though I may be misremembering. Additionally, the driver can be copied from that to any destination directory, but would be subject to the same update issues.
Comment: Ok cool. You helped me understand the bit "Windows Feature on Demand which ensures that it's always up to date automatically and enables some new ways to get Microsoft WebDriver. To get started you will have to enable Developer Mode:
Go to Settings > Update and Security > For Developer and then select "Developer mode"." That I did not understand. So... having done that, how do I know WHERE the webdriver is or really, what is the correct driver constructor? (driver = new EdgeDriver(driverLocation);)


How do I reset all user passwords to 123 with drush or SQL?

Question: For testing purposes I like to reset all user passwords to 123.
Is this possible in Drush or SQL?
I guess the query will be someting like this but cannot find the exact yourhash:
UPDATE `<mydatabase>`.`users` SET `pass` = '<yourhash>' ;

Can I run the final query with drush?
Answer: Yes, you can do this using Drush, with following steps (e.g.):
1.Generate a password hash using following command:
$ cd [/var/www/html/drupal7]
$ php scripts/password-hash.sh '123'

2.Now run following drush command:
$ drush sql-cli
mysql > UPDATE users SET `pass` = 'pasted_big_hash_from_above' WHERE uid > 1;

Update pasted_big_hash_from_above with password hash generated using php command in step #1.
Answer: Solved.
Query can be done in Drush with:
drush sql-query UPDATE `users` SET `pass` = '$S$DM7xrCBIKOrShBhgb1eUkpPlnnAq36QKIlMfdkKhvaTS2iv0PuJ3'

Comment: This hash corresponds to 123 for the specific site only.


Locally Small Category construction confusion:

Question: Working through Categories for the Working Mathematician, there was a point that has confused me. Throughout chapter 2, section 2, Mac Lane describes a (family of) functors which map locally small categories to Set by $b \mapsto \hom(a, b)$ and $f \mapsto f_*$. At the top of page 35 he then describes a method for constructing a similar functor on categories that aren't locally small:

To include categories [that aren't locally small], we can proceed as follows: Given a category $C$, take a set $V$ large enough to include all subsets of the set of arrows of $C$...

I'm confused by this: how could $V$ possibly be a set and not a proper class? Indeed, how could all the arrows of $C$ not be a proper class? Since $C$ is not locally small, there is some $a, b$ such that $\hom(a, b)$ is a proper class. Then, $\hom(a, b)$ is a subset of all arrows of $C$, which in turn has an obvious bijection to $V$, by sending a given arrow to its singleton. Thus, $\hom(a, b) \subseteq V$, so $V$ must also be a proper class. What am I missing?
Answer: Mac Lane defines "small sets" in terms of universes.  In particular, on page 12 he says:

We shall assume that there is a big enough set $U$, the "universe", then describe a set $x$ as "small" if it is a member of the universe.

In section I.6, he elaborates that by "big enough set" he actually means a Grothendieck universe.  So for him, a "large" category is still a set, just one which is larger than the chosen universe.  For categories that are actually proper classes, he uses the term "metacategory" instead (and does not consider them to be "categories").
Comment: Very helpful thank you. I feel like this answer is a little unsatisfying though, because it doesn't answer the question: does such a construction exist for Mac Lane's metacategories?
Comment: That depends what you mean by "exist".  The hom operations will be definable, but they take values in proper classes, and there is no target (meta)category for them to be landing in.
Comment: The lack of a target metacategory is probably what would make me say that they don't exist. Thanks.


Data Safety in Cloud VPS Email Server?

Question: Is it safe to store email on a cloud based VPS host?
I know its not 100% like the unplugged server buried underground and that the Host has a big deal to do with it but, in the broader sense of avoiding snooping and data mining, how do people protect their data? I'm sure not everyone uses dedicated servers~
Is it even common to run email servers on a VPS? I DO want to be able to tell my clients that their data is relatively secure (assuming I take the proper precautions)~
I'm currently setting up email on a VPS with Ubuntu Server installed.
I'm thinking of encrypting the home folder of the email service user but, I'm wondering if accessing the encrypted data will make an imap/smtp email server slow~
Answer: The data is as safe as however much you trust the provider to keep it safe. Odds are that encrypting it on disk doesn't matter, because many common encryption schemes keep the encryption key in RAM. Anyone who gets a shell on your VM (such as a malicious IT person on your provider's side, or even a hacker) could simply log in  and extract email.
More importantly, if your provider doesn't make regular backups and your server goes down for whatever reason, you could be down for hours (bad) or lose all of your clients' email (career-stunting). You'd have to make your own backups and secure those elsewhere.
"Secure" may mean something different to your clients than it does to you. This sort of thing is generally detailed carefully in a service level agreement many pages long, so if your customers are holding you to an SLA, use that as your security guideline. As a rough guideline though, the setup you're describing is not PCI-compliant.
In short, your data will not be very secure, you could lose a lot of data, and your customers' email is apparently worth up to (but not exceeding) $49.95 a month to you. Buy your own box, keep it under lock and key. Caveats on backups and malicious physical access still apply.
Comment: Great, thanks! you provided some very good arguments and gave me some more things to think about. My gut was telling me its maybe not a great setup and that's why I double checked here. I will definitely rethink my email strategy.
Comment: I'm very glad to hear it. Please do speak directly to a colocation facility's sales team. They can tell you exactly how they do business and you can iron out a specific SLA. You do get what you pay for
Answer: For running my own personal vanity email domain, I find a VPS to be acceptable. Of course I am also sweeping every bit of mail off the server onto my home computer every minute via POP3.
If I were going to host other people's email, I would do so on my own physical server colocated in a data center with reasonable physical security measures in place, in addition to securing the server OS and system services.

Data Safety in Cloud VPS Email Server?


Correct implementation of Logistic Regression Model

Question: I am trying to follow the methodology shown here:
http://beyondmicrofoundations.blogspot.co.uk/2011/09/logisitic-regression-and-stock-returns.html
Q1.) Is this methodology correct?
Q.2) Have I implemented it correctly in Matlab?
<code> rtn=(Data1.Mid(2:end)-Data1.Mid(1:end-1))./(Data1.Mid(1:end-1));

 NStep=1;

Up=nan(length(rtn),1);
Down=nan(length(rtn),1);
Flat=nan(length(rtn),1);
RtnClass=nan(length(rtn),1);

for i=1:length(rtn)-NStep

   if(rtn(i+NStep)>0)
       Up(i)=2;
       Down(i)=1;
       Flat(i)=1;
    elseif(rtn(i+NStep)<0)
       Up(i)=1;
       Down(i)=2;
       Flat(i)=1;
    elseif(rtn(i+NStep)==0)
       Up(i)=1;
       Down(i)=1;
       Flat(i)=2;
    end

end

[BUp,dev,stats] = mnrfit(rtn,Up);
MatProbUp = mnrval(BUp,0);

[BDown,dev,stats] = mnrfit(rtn,Down);
MatProbDown = mnrval(BDown,0);
</code>
Answer: Not quite what you want to know, BUT, since your response is ordinal:  down < unchanged < up, you might be better off using ordinal logistic regression instead of multinomial logistic regression.  It can be run in R.


Is there a way to write this expression differently: $\arctan 1/(1+n+n^2)$?

Question: $$ \arctan\left(\frac{1}{1+n+n^2}\right)$$
My professor wrote this as
$$\arctan(n+1) - \arctan(n)$$
I don't understand how this expression is right?
Comment: Try taking tangent of both sides and using the tangent angle addition/subtraction formula.
Answer: Use the formula
$$\tan(\alpha-\beta)=\frac{\tan\alpha-\tan\beta}{1+\tan\alpha\tan\beta}$$
with $\alpha=\arctan(n+1)$ and $\beta=\arctan n$.
Answer: See this diagram (drawn for $n=3$, but the principle is general):

The red line has slope $\dfrac{1}{1+n+n^2}$ and makes an angle of $\tan^{-1}(n+1)-\tan^{-1}(n)$ with the horizontal axis.
Answer: $$
\arctan x + \arctan y = \arctan \frac{x+y}{1-xy}
$$
Applying this with $x=n+1$ and $y=-n$ we get
$$
\frac{x+y}{1-xy} = \frac{(n+1)-n}{1+(n+1)n} = \frac 1 {n^2+n+1}
$$
Answer: We have $$\tan^{-1}\left( \frac{1}{1+n+n^2}\right)$$ $$=\tan^{-1}\left( \frac{(n+1)-n}{1+n(n+1)}\right)$$ Now, let $\color{blue}{n+1=\tan\alpha}$ ($\implies \color{blue}{\alpha=\tan^{-1}(n+1)}$) & $\color{blue}{n=\tan\beta}$ ($\implies \color{blue}{\beta=\tan^{-1}(n)}$) $\forall \quad \alpha>\beta$
Thus by sustituitng the correspoding values in above expression, we get $$\tan^{-1}\left( \frac{\tan \alpha-\tan\beta}{1+\tan\alpha\tan \beta}\right)$$ $$=\tan^{-1}\left( \tan(\alpha-\beta)\right)$$$$=\alpha-\beta $$ $$=\color{green}{\tan^{-1}(n+1)-\tan^{-1}(n)}$$


Trying to import all google sheets files within a folder to a spreadsheet, all column headers are the same

Question: I need to be able to take all files from a a folder within drive and input the data into the spreadsheet. I am also creating a Menu Tab so I can just Run the script without going to editor. It would be great if I can create a way enter names of existing folder name without always going to the script in order to take out that extra step. This is the script I am using. I really need assistance with this.
function importTimesheets() {
 var spreadsheets = DriveApp.
   getFolderById("").
   getFilesByType(MimeType.GOOGLE_SHEETS);

 var data = [];
 while (spreadsheets.hasNext()) {
   var currentSpreadsheet = SpreadsheetApp.openById(spreadsheets.next().getId());
   data = data.concat(currentSpreadsheet
                        .getSheetByName('Timesheet')
                      .getRange("A3:L10")
                        .getValues()
                          );
 }

 SpreadsheetApp.
   getActiveSheet().
   getRange(1, 1, data.length, data[0].length).
   setValues(data);
}

function onOpen() {
 var ui = SpreadsheetApp.getUi();
 ui.createMenu('Generate Timesheets')
     .addItem('Generate', 'importTimesheets')

Comment: I have to apologize for my poor English skill. Unfortunately, I cannot understand the relationship between yout title of `Trying to import all google sheets files within a folder to a spreadsheet, all column headers are the same` and `It would be great if I can create a way enter names of existing folder name without always going to the script in order to take out that extra step.` in your question. Can I ask you about the detail of your question?
Comment: No apologize need. Every day timesheets are created and they all have different  file names but they all have the same format. I need to take all the data from all these files and input them into one weekly spreadsheet.
Comment: I will then use this method to generate weekly timesheets with ease. Due to covid the amount of data is small; but realistically, ill be dealing with well over 20 timesheets a day, well 2000 entries a week.
Answer: As far as I understand you are trying to find a solution for this line of code, whereby you currently have to enter the Id manually.
   DriveApp.getFolderById("")

My suggestions would be to prompt the user for the folder Id, because prompting for the folder name may cause errors if more than one folder has the same name. My suggestion is implemented as follows:
const folderId = SpreadsheetApp.getUi().prompt("Please enter the Folder Id").getResponseText()
const folder = DriveApp.getFolderById(folderId)

You could also use the Google File/Folder picker, as described here to search and select the folder.
Comment: oh no I just left that blank for confidential reasonings.. my problem was with .get range, it came up as an error. Although, I will most definitely try your code. Thank you!
Answer: Try this:
var level=0;
function getFnF(folder = DriveApp.getRootFolder()) {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getSheetByName('Sheet1')
  const files=folder.getFilesByType(MimeType.GOOGLE_SHEETS);
  while(files.hasNext()) {
    let file=files.next();
    let firg=sh.getRange(sh.getLastRow() + 1,level + 1);
    firg.setValue(Utilities.formatString('File: %s', file.getName()));//need editing
  }
  const subfolders=folder.getFolders()
  while(subfolders.hasNext()) {
    let subfolder=subfolders.next();
    let forg=sh.getRange(sh.getLastRow() + 1,level + 1);
    forg.setValue(Utilities.formatString('Fldr: %s', subfolder.getName()));//needs editing
    level++;
    getFnF(subfolder);
  }
  level--;
}

function runThisFirst() {
  let r = SpreadsheetApp.getUi().prompt('Folder id','Enter Folder Id',SpreadsheetApp.getUi().ButtonSet.OK);
  let folder = DriveApp.getFolderById(r.getResponseText())
  getFnF(folder);
}

Comment: Thank you @Cooper, I think this code will work  but I'm assuming that Line 9 will get the files with certain name. They all have different names and I need it to grab everything from the folder.
Comment: files is an iterator for files of MimeType.GOOGLE_SHEETS


Sorting and grouping objects by Date with the Django ORM

Question: I have an Article model which has a date field. I want to query against all Article objects, and have a datatype returned with each distinct year, and then each distinct month within that.
for instance

archives = {
   2009: {12, [, , ...], 11: [...]},
   2008: {12, [...], 11: [...]},
}

is this possible?
Comment: I have an idea to create a new field using raw MySQL query (smth like YYYY_MM) and after that use `map` for filling archives variable.
Answer: This sort of question seems to come up fairly often.  The easiest solution is to loop through the data and group the objects by year and month.  You can do this by hand in the view or using regroup in your template.  It really depends on what you want to do with the data.
If grouping Archives by year and month is a very common thing for you to do in your application, you might want to consider creating a year and month field that you populate on save().
By hand it could be something like this:
arch = {}
for a in Archive.objects.all():
    year = arch.get(a.pub_date.year, {})
    month = year.get(a.pub_date.month, [])
    month.append(a)
    year[a.pub_date.month] = month
    arch[a.pub_date.year] = year

Or pushing all the grouping logic into the template using regroup (untested):
{% regroup archives by pub_date.year as year_list %}
{% for year in year_list %}
  Year: {{ year.grouper }}
  {% regroup year.list by pub_date.month as month_list %}
  {% for month in month_list %}
    Month: {{ month.grouper }}
    {% for archive in month.list %}
      {{ archive }}
    {% endfor %}
  {% endfor %}
{% endfor %}

I would personally try to put the logic in the view instead of in the template.
Here are a few related posts:

Django Year/Month based posts archive
In Django how to show a list of objects by year
Listing blog entries by year,month
Answer: There is no quick solution, but you may check dates() method.
Comment: For example, if you want it for month, `[(date, Model.objects.filter(pub_date__year=date.year, pub_date__month=date.month)) for date in Model.objects.dates('pub_date', 'month')]` will get you a list of `(date, QuerySet)` tuples for every month (assuming your field is named `pub_date`).


tratamento de string em pandas

Question: Boa Noite Senhores,
Tenho o seguinte Dataframe, importado de um xlsx.
<code>    NUM_LEGISLACAO  DSC_URL  COD_SITUACAO  ...    DSC_TIPO     num   ano
264    89.272/1984      NaN           2.0  ...   NORMATIVO  89.272  1984
265    90.396/1984      NaN          11.0  ...   NORMATIVO  90.396  1984
266    90.804/1985      NaN           2.0  ...    CONCRETO  90.804  1985
267     81195/1978      NaN           NaN  ...         NaN   81195  1978
268      5475/1905      NaN           NaN  ...         NaN   05475  1905
269    90.396/1984      NaN          11.0  ...   NORMATIVO  90.396-A  1984
</code>
Importei com o código abaixo:
<code>df1 = pd.read_excel(file01, sheet_name='Exportar Planilha')
df1['num'], df1['ano'] = df1['NUM_LEGISLACAO'].str.split('/').str

#notok
#substitui '.' e '-' no campo 'num'
df1['num'] = df1.num.str.replace('[\.-]', '')

#formata com 5 digitos
df1.num = df1.num.astype(str).str.rjust(5, '0')
df1['num'] = df1.num.astype(str).str.zfill(5)
</code>
Pretendo retirar '.' do campo 'num', e produzir o seguinte resultado:
<code>    NUM_LEGISLACAO  DSC_URL  COD_SITUACAO  ...    DSC_TIPO     num   ano
264    89.272/1984      NaN           2.0  ...   NORMATIVO  89272  1984
265    90.396/1984      NaN          11.0  ...   NORMATIVO  90396  1984
269    90.396/1984      NaN          11.0  ...   NORMATIVO  90396A  1984
</code>
Entretanto meu código não funciona e apresenta o seguinte erro:

TypeError: Type aliases cannot be used with isinstance().
Comment: Em *CSV* funciona: https://repl.it/repls/VerticalDarksalmonMicroscope
Answer: Encontrei o motivo da falha neste post https://stackoverflow.com/a/50496822/5132101.
Devido a um bug no Python 3.5.2 e anteriores, o erro acontece.
O meu ambiente é um Linux Ubuntu, que não traz update para esta versão do python, então para resolver, instalei um ambiente Anaconda, que vem com diversas versões Python disponíveis.
Detalhes em https://brito.blog.incolume.com.br/2018/06/anaconda.html

tratamento de string em pandas


How do I Split a string by empty lines?

Question: I want to split my string just by empty entries. I know you can remove these with the string options but in my situation I need them to split the string. Thank you!
string[] text = content.Split(' ');

For example you have this string:
Hi my Name is Max.
I'm 24 years old.

I like programming.

Split the string between old and I.
My Code:
            WebClient client = new WebClient();
            Stream stream = client.OpenRead("https://gist.githubusercontent.com/Quackmatic/f8deb2b64dd07ea0985d/raw/macbeth.txt");
            StreamReader reader = new StreamReader(stream);
            string[] text = reader.ReadToEnd().Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine(text[i]);
            }
            Console.ReadLine();

The string is splitted by every new line. The problem is I want to have full paragraphs of my text.
My Output:
string[0] = ACT I.
string[1] = SCENE I. An open place.
string[2] =[An open place. Thunder and lightning. Enter three Witches.]

What I want.
string[0] = ACT I.
string[1] = SCENE I. An open place.
            [An open place. Thunder and lightning. Enter three Witches.]
string[2] = FIRST WITCH.
            When shall we three meet again
            In thunder, lightning, or in rain?

or...
    Doubtful it stood;
    As two spent swimmers that do cling together
    And choke their art. The merciless Macdonwald,
    Worthy to be a rebel, for to that
    The multiplying villainies of nature
    Do swarm upon him, from the Western isles
    Of kerns and gallowglasses is supplied;
    And fortune, on his damned quarrel smiling,
    Show'd like a rebel's whore. But all's too weak;
    For brave Macbeth, well he deserves that name,
    Disdaining fortune, with his brandish'd steel,
    Which smok'd with bloody execution,
    Like valour's minion,
    Carv'd out his passage, till he fac'd the slave;
    And ne'er shook hands, nor bade farewell to him,
    Till he unseam'd him from the nave to the chaps,
    And fix'd his head upon our battlements

I thought I could get the result by splitting the text by empty lines.
.
Comment: What *exactly* do you mean by "empty entries"? What happens with the code you've got? Can you give sample input, actual output and expected output?
Comment: Are you trying to split a string at a new line or only when there is two new lines?
Comment: @heroeofTheDesert: to repeat the first comment: _"Can you give sample input, actual output and expected output? "_ You have now accomplished the first task.
Comment: With `empty entries`, you mean `white space`?
Comment: @John Skeet yes I already edited my question.
Comment: you want to split the string by "\n"?
Comment: Unfortunately, newlines in strings are not always the same. .NET will usually use the character sequence `"\r\n"`, but depending on where the string came from, it could instead use `"\n"` or even `"\r"`. That said, if you know for sure the character sequence in use in the string you can use it repeated twice in a row as your split string E.g. `"\r\n\r\n"`
Comment: @GregOks When I'm splitting the string by "\n" I will get three strings but I just want to split by the empty line between "old." and  "I"
Comment: depends on how have you stored all these words, is it string. or string[] or string[][]
Comment: @TimSchmelter sorry for taking this much time. I think he edited his comment? I didn't remember this part.
Comment: @heroeofTheDesert: now you have provided an example. But unfortunately it's still not clear. You want a `string[]` as result? But you want to keep some empty lines, others should be removed. What is the rule, why do you want to keep that after `ACT I` and why do you want to remove it  after `SCENE I. An open place.`? What is the resulting `string[]`. Show a desired output like Ministry has done [in his answer](http://stackoverflow.com/a/28944166/284240).
Comment: Yes I want a string[] as result. I don't want to keep empty lines. One moment.
Comment: @heroeofTheDesert: in what way is [Ministry's answer](http://stackoverflow.com/a/28944166/284240) incorrect?
Comment: @TimSchmelter it worked out for me now. Thank you for taking the time and keep helping. I'm  sorry for asking such a inaccurate question. Have a nice day!
Answer: var foo = bar.Split(new string[] {Environment.NewLine + Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);

It's important to have the combined Environment.NewLine + Environment.NewLine as this will only split when a new line is also followed by a new line (aka a blank line) and split accordingly
The result is:
foo[0] = "Hi my Name is Max.\r\nI'm 24 years old."
foo[1] = "I like programming."

Edit -- Based on your new input try give this a go:
var web = new WebClient();
var stream = web.OpenRead("https://gist.githubusercontent.com/Quackmatic/f8deb2b64dd07ea0985d/raw/macbeth.txt");
if (stream == null) return;
var reader = new StreamReader(stream).ReadToEnd();
var io = reader.Split(new string[] { "\n\n" }, StringSplitOptions.RemoveEmptyEntries);

From here you can iterate through and do what you please (ie. line[i].StartsWith("ACT") to put it into an object if you so wish)
Comment: @heroeofTheDesert All good. Please mark this as the accepted answer if it matches your criteria. Additionally, good luck on /r/dailyprogrammer ;)
Comment: nice to see that someone copying my answer and make som uppercaseletters to it is getting accepted while i get 5 downvotes... i think to improve my answer to the correct code should be possible to the OP...
Comment: The problem wasn't limited to the character casing. Additionally the Environment.NewLine didn't work using the macbeth.text.
Answer: if you are searching for empty lines you should do somthing like
"value".split(environment.newline+environment.newline)

Comment: Please don't answer questions that aren't clear at all by guessing what OP is trying to achieve.
Comment: In your rush to post an answer, you seem to have forgotten to include code that compiles. :p C# is case-sensitive.

How do I Split a string by empty lines?


jQuery animation isnt repeating

Question: Im pretty sure that my jQuery should below should work but when I use it in a Drupal site the animation doesn't repeat like it should.
http://smartpeopletalkfast.co.uk/t/
<code>$(document).ready(function() {
    if ( $(window).width() > 960) {

    function fadeOutFunc() {
        $('.image-list .bottom').delay(1000).fadeOut(500, function() {
            $('.image-list .bottom').delay(1000).fadeIn(500,fadeOutFunc);
        });
    }

    fadeOutFunc();

    //  jQuery('.image-list .bottom').css('opacity','0.6');

    }
});
</code>
Answer: Try putting js code using Drupal Behaviours
<code>(function($, Drupal)
{
  Drupal.behaviors.animation = {
    attach:function()
    {
      if ( $(window).width() > 960) {

      function fadeOutFunc() {
        $('.image-list .bottom').delay(1000).fadeOut(500, function() {
          $('.image-list .bottom').delay(1000).fadeIn(500,fadeOutFunc);
        });
    }

    fadeOutFunc();
    }
  };
}(jQuery, Drupal));
</code>
Comment: With the new code the animation doenst fire at all.

jQuery animation isnt repeating


For User before Update

Question: I have made an API to insert data of 7 fields (fullname, city, bloodgroup, password, mobileno, lastdonated, created_date) in a mysql database using INSERT, please help me to add some code to search if the user is already added using the mobileno field and only then add the record else show the message "User already exists".
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
if(count($_REQUEST) > 0)
{
    $conn = mysqli_connect("localhost", "creative_bloodapp", "PasSwORd", 'creative_bldapp');
        $fullname           =$_POST['fullname'];
        $city               =$_POST['city'];
        $bloodgroup         =$_POST['bloodgroup'];
        $password           =$_POST['password'];
        $mobileno           =$_POST['mobileno'];
        $lastdonated        =$_POST['lastdonated'];
        $created_date       = date('Y-m-d H:i:s');
    $sql = "INSERT INTO register (fullname, city, bloodgroup, password, mobileno, lastdonated, created_date) VALUES ('" . $fullname . "','" . $city . "','" . $bloodgroup . "','" . $password . "','" . $mobileno . "','" . $lastdonated . "','". $created_date . "');";
    $qur = $conn->query($sql);
    if($qur){
        $query="SELECT * FROM register ORDER BY mobileno DESC LIMIT 1;";
        $data=array();
        $result=mysqli_query($conn, $query);
        $row=mysqli_fetch_assoc($result);
        mysqli_close($conn);
        response(1,"User has been registered!",$row);
    }else{
        mysqli_close($conn);
        response(0,"Not Registered!",NULL);
    }
}
else
{
    response(0,"Not Registered!",NULL);
}
function response($status,$status_message,$data)
{
    header("HTTP/1.1 ".$status);
    $response['status']=$status;
    $response['status_message']=$status_message;
    $response['data']=$data;
    $json_response = json_encode($response);
    echo $json_response;
}
?>

Comment: just add a simple select count before the insertion begins first, it serves as your checker whether the mobile exists already or not, by the way, why not use prepared statements, you're using mysqli anyways
Comment: before the insert query do a select query to check if $mobileno   eqauls something in the database i.e $res = query(SELECT * FROM table where mobileno = '$mobileno') if(count($res) >=1) then echo "user exists"; exit;
Comment: Please add also some SQL injection prevention
Answer: Looking for something like this; I changed some queries and re-wrote a part for you. Also added mysqli_real_escape_string.
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
if(count($_REQUEST) > 0)
{
    $conn = mysqli_connect("localhost", "creative_bloodapp", "PasSwORd", 'creative_bldapp');
    $fullname           = mysqli_real_escape_string($conn, $_POST['fullname']);
    $city               = mysqli_real_escape_string($conn, $_POST['city']);
    $bloodgroup         = mysqli_real_escape_string($conn, $_POST['bloodgroup']);
    $password           = mysqli_real_escape_string($conn, $_POST['password']);
    $mobileno           = mysqli_real_escape_string($conn, $_POST['mobileno']);
    $lastdonated        = mysqli_real_escape_string($conn, $_POST['lastdonated']);
    $created_date       = date('Y-m-d H:i:s');

    $query="SELECT * FROM register  WHERE mobileno = '".$mobileno."'";
    $qur=mysqli_query($conn, $query);
    if(count(mysqli_num_rows($qur) !== 0)){
        $data=array();
        $result=mysqli_query($conn, $query);
        $row=mysqli_fetch_assoc($result);
        mysqli_close($conn);
        response(1,"User has been registered!",$row);
    }else{
        $sql = "INSERT INTO register (fullname, city, bloodgroup, password, mobileno, lastdonated, created_date) VALUES ('" . $fullname . "','" . $city . "','" . $bloodgroup . "','" . $password . "','" . $mobileno . "','" . $lastdonated . "','". $created_date . "');";
        $qur=mysqli_query($conn, $query);
        mysqli_close($conn);
        response(0,"Not Registered!",NULL);
    }
}
else
{
    response(0,"Not Registered!",NULL);
}
function response($status,$status_message,$data)
{
    header("HTTP/1.1 ".$status);
    $response['status']=$status;
    $response['status_message']=$status_message;
    $response['data']=$data;
    $json_response = json_encode($response);
    echo $json_response;
}

Answer: Yes, Make it mobileno unique key so
if($qur)
{
// new mobileno
//add it will take
}
else
{
// repeated i will not accept, you put mobileno exist.
}

Answer: <?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
if(count($_REQUEST) > 0)
{
    $conn = mysqli_connect("localhost", "creative_bloodapp", "PasSwORd", 'creative_bldapp');
    $fullname           = mysqli_real_escape_string($conn, $_POST['fullname']);
    $city               = mysqli_real_escape_string($conn, $_POST['city']);
    $bloodgroup         = mysqli_real_escape_string($conn, $_POST['bloodgroup']);
    $password           = mysqli_real_escape_string($conn, $_POST['password']);
    $mobileno           = mysqli_real_escape_string($conn, $_POST['mobileno']);
    $lastdonated        = mysqli_real_escape_string($conn, $_POST['lastdonated']);
    $created_date       = date('Y-m-d H:i:s');

    $verifysql = "select id from register where mobileno='".$mobileno."'";
    $qur = $conn->query($verifysql);
    if($qur->num_rows == 0){
       $sql = "INSERT INTO register (fullname, city, bloodgroup, password, mobileno, lastdonated, created_date) VALUES ('" . $fullname . "','" . $city . "','" . $bloodgroup . "','" . $password . "','" . $mobileno . "','" . $lastdonated . "','". $created_date . "');";
       $result = $conn->query($sql);
       if($result){
          mysqli_close($conn);
          response(200,"User has been registered!",$row);
       }else{
          mysqli_close($conn);
          response(500,"Registeration Failed",NULL);
       }
    }
    else{
        mysqli_close($conn);
        response(409,"User Already Exists!",NULL);
    }
}
else
{
  response(400,"Not Registered!",NULL);
}

For User before Update


how to change default output delimiter in Spark

Question: In spark shell, i'm reading an input file and trimming the field values next saving the final rdd using saveAsTextFile() method. The field separator in the input file is '|' but the in the output file I'm getting the field separator as ','.
Input Format: abc | def | xyz

Default Output Format: abc,def,xyz

Required output format something like abc|def|xyz
Is there anyway to change the default output delimiter value to '|', if yes than please suggest.
Comment: Possible duplicate of [remove parentheses from output in spark](http://stackoverflow.com/questions/29945330/remove-parentheses-from-output-in-spark)
Answer: For an RDD, you'll just need to make a string with a pipe separated value on the product iterator :
scala> val rdd = sc.parallelize(Seq(("a", 1, 3), ("b", 2, 10)))
// rdd: org.apache.spark.rdd.RDD[(String, Int, Int)] = ParallelCollectionRDD[11] at parallelize at <console>:27

scala> rdd.map { x => x.productIterator.toSeq.mkString("|") }
// res9: Array[String] = Array(a|1|3, b|2|10)

scala> scala> rdd.map { x => x.productIterator.toSeq.mkString("|") }.saveAsTextFile("test")

Now let's check the content of the files :
$ cat test/part-0000*
a|1|3
b|2|10


Prove $f^{\log_a g}=g^{\log_a f}$

Question:
Prove $f^{\log_a g}=g^{\log_a f}$

$$
y=f^{\log_a g}\implies \log_fy=\log_ag\implies g=a^{\log_fy}\\
g^{\log_a f}=a^{{\log_a f}.{\log_f y}}=a^{{\log_af}.{\log_ag}}=a^{{\log_ag}.{\log_af}}=a^{\log_af^{\log_ag}}=f^{\log_ag}
$$
Is it the right way to prove it ?
Comment: It seems like you can do it without introducing another variable.
Comment: Note that $f^\frac{\log_f g}{\log_f a}=(f^{\log_f g})^{\log_a f}$.
Comment: You recieved 3 answers to your question. Is any of them what you needed? If so, you should upvote all the useful answers and accept the answer that is most useful to you.
Comment: It's really rude to just abandon questions like this.
Answer: Hint:
$$x^y = a^{\log_a(x^y)}=a^{y\cdot \log_a x}$$
Answer: The function $y = \log_a x$ is one-to-one. Alternatively you could show that both sides have the same logarithm base $a$.
Answer: Let $y = \log_{a}(g)$ so that:
$$f^{\log_{a}(g)} = f^{y} = g^{\log_{g}(f^y)} = g^{y\log_{g}(f)} = g^{\log_{a}(g)\log_{g}(f)}$$
If we can show:
$$\log_{a}(g)\log_{g}(f) = \log_{a}(f)$$
we are done.
Observe:
$$\log_{a}(g)\log_{g}(f) = \log_{a}(g)\frac{\log_{a}(f)}{\log_{a}(g)} = \log_{a}(f)$$
Thus,
$$g^{\log_{a}(g)\log_{g}(f)} = g^{\log_{a}(f)}$$
(You can do this without introducing $y$, but I think it is easier to see with $y$)

Prove $f^{\log_a g}=g^{\log_a f}$


VUEJS: Property or method "indicatorTitle" is not defined

Question: Tenho uma variável simples e quero passa-la para meu v-for. Porém, recebo o erro "Property or method "indicatorTitle" is not defined on the instance but referenced".
O modo como estou tentando:

     {{ indicatorTitle }}

data: function () {
    return {
        titles: [
        { indicatorTitle: "Teste 3" },
        { indicatorTitle: "Teste 2" },
        { indicatorTitle: "Teste 1" }
        ]
    }
```

Comment: tens de o chamar a partir do objecto: `{{ title.indicatorTitle }}`
Comment: @HelderLucas: vai uma resposta? :)
Comment: Vou aceitar a resposta com prazer quando a fizer, @HelderLucas
Comment: Ish, tens razão, esqueci completamente. Muito obrigada
Answer: Sendo titles um objecto,indicatorTitle tem que ser chamado como uma propriedade do mesmo, como por exemplo: {{ title.indicatorTitle }} :)
Comment: Obrigada pela resposta! :)


Trying to Make an Accurate Model of a Stratocaster

Question: I'm refining a 3D model of a Fender Stratocaster and I have a question about the way the neck is configured. I don't know much about electric guitars (I play classical), although, after a visit to fender.com, I'm learning fast. On the model, the top level of the neck is slightly straighter than underneath -- well, it's hard to describe succinctly, so here's a picture:

Was the original modeler just sloppy (they were with some other parts), or is this for real?
Comment: VLQ image, but it doesn't look like it @DrMayhem - https://i.stack.imgur.com/xrxvS.png
Comment: I'm voting to close this question as off-topic because  how to build instruments (or models of instruments) is not included in the topics - this is not a a music question .
Comment: Another guitar with a zero fret? great news! Yes, I'm serious. they're not common enough.
Comment: Are your green and blue lines perpendicular to the frets?
Comment: Yes, doctor. I did a screen grab of the model from directly overhead, then imported the image into PS to add the lines and text.
Comment: Yes, What I called "zero fret" is actually the nut. Like I said,I'm learning.
Comment: Sorry. I thought music.stackexchange was likely to include luthiers.
Answer: From that diagram, it doesn't look like there is any difference in rake - it looks simply like you have not centred the neck correctly in your image.
While string lengths will all be slightly different, for intonation, as far as a standard neck goes, treat them all as identical length. The neck just has a taper.
Comment: Thank you. I suspect the original model was based on an image that wasn't quite overhead.