Creating a per module git repo environment for magento module development on one site

Question: I want to develop multiple Magento modules on one fresh install of Magento 1.7 so that each module can be pushed to an online repo and tracked individually.
I initially began by following this tutorial but can't get Magento to detect the module using symlinks. I have enabled the 'follow symlinks' option in the backend. I could be struggling here due to file permissions or something but I don't mind abandoning this approach for a .gitignore "whitelist". Something like
 *
 !app/etc/modules/My_Module.xml
 !app/etc/code/community/My/Module
 !app/etc/code/community/My/Module/*

This seems a much easier approach but where do I initialise each working directory because they are all spread out from ./ I need to git init many repositories at the same locations each with different .gitignore files. I'd actually prefer the symlinking options because it gives me one place i can package my extensions from.
Thanks in advance.
Answer: That tutorial references it, but if you haven't tried it yet I would recommend using modman as a much less maintenance heavy option compared to creating all the symlinks manually as per the tutorial.  It will do an identical job, and will automatically create the symlinks for you according to a simple configuration file allowing you to develop externally to the magento install and thus create a repository containing only the extension which it sounds like you would prefer.
It's worth checking permissions and ownership of the files in your install - note that symlinks themselves will only themselves ever have permissions of 777 (world read/write) but will use the permissions of the file they reference, so check the permissions of the files you are symlinking to which will need to be sufficient for the web server user to access them.
With respect to using a whitelist, you can't initialise multiple repositories at the same location, but branching would be another solution if you don't mind all extensions being in the same repository just on different branches.
To my mind considering your requirements using modman with correct user and group ownership and permissions is going to offer you the best solution.
Comment: Thanks, this is exactly what I was looking for. Sadly I think my boss is going to say it will take too long and I'll just have to keep writing modules on a per-site basis. :/
Comment: It will take a bit of time to get up and running but you could always try and convince your boss by giving him the argument that it can also be used to easily deploy extensions to multiple magento installs, the wiki has information on that.
Comment: I have set up the development environment using modman. This tool is terrific and I would say essential for anyone doing a reasonable amount of development work on Magento or another system that has the same folder structure 'issue'. I have written a guide to setting up a development environment for Magento modules using modman. PM me if you would like a link.
Comment: Great solution, I found a great tutorial in order to master this tool https://www.maxpronko.com/blog/magento-2-module-in-a-separate-repository


How to understand layering of multiple elements in composition (pop/jazz)

Question: I'm trying to understand more about how to compose music and most importantly combine multiple instruments at the same time.
I'm quite capable of composing a bass-line, chord progression, or main lead tune, but bringing the elements together at the same time seems more difficult for me.
Is there a good book on theory that will help with this issue.
I've studied the Modes in some detail before, chord progressions less so, but I understand them as moving between different points of the mode.
Essentially, while I'm certainly able to put together a convincing drum track, baseline and other small elements, bringing in another major element seems difficult to me.
I hope this gives you enough information for what I am looking for help with. I have played small amounts of Piano, Drums and Bass Guitar. I can sometimes achieve what I am looking for my greatly simplifying some of the elements, but I feel this is not really what I am looking for.
Could it be that you need the progression of each element to evolve in time with each other?
Any help greatly appreciated.
Answer:
Could it be that you need the progression of each element to evolve in time with each other?

Well, normally you wouldn't even talk of different chord progressions; it's just THE chord progression, which all instruments play over. The modes are usually global. So a typical workflow if you are content with one first single-instrument part would be to extract the modes from that first part and make them the basis of the other parts. In fact, you'll quickly start doing this quite automatically with a little practise. You can also simply improvise on the looped first track, starting with just unisono-ing the previous part (or what of it is playable on the next instrument) and evolving it to something different.
Comment: Thats great advice and extactly the kind of thing I'm looking for. Anything else anyone has to offer along these lines would be appreciated too!
Answer: A traditional approach to composition is to play/write out all the parts for the piano and create what is called the piano reduction score. From this you extract and assign parts for the ensemble. An analogy to painting: sketch the basic form on the canvas then work each part (usually from background to foreground) with color, shade, highlights etc.
In your case you are composing for "Piano, Drums and Bass Guitar". I would suggest working out the melody, harmony, and rhythm on the piano first. Once you have your patterns translated into beats, notes, and measures then start your recording from the beat up. That would be drums first, then bass, then piano. If you would prefer doing it another way at least provide yourself with a 'click' track as a beat reference so you can keep time as you lay in the remaining tracks. When you are done recording all the parts, just remove or mute the 'click' track before making the master mix.
When I compose I try to imagine the whole thing as it would sound when it is completed or I may already have this image in my mind and find myself taking it apart to see how it can be built. Another approach is to start with a simple melody and build on this to create the harmony (chords or extra voices) and development as variations or verses, chorus or bridge elements, all depending on the style etc. A good example of the additive method would be the fugues, canons, or preludes of J. S. Bach.
Since your target is Pop/Jazz, don't forget that in traditional jazz, everyone in the ensemble may take a solo. I sort of think this is dependent on how many players are in the group, and their ability to solo and improv. I wouldn't recommend everyone taking a solo in a 12 piece band. The solo may be different every time, or the composer may leave instructions on setting some musical boundaries on the solo, or even actually spell it out. Another thing that is cool about this is that you can make this a variable part of the piece, for example you may have 2 extra minutes to kill to complete your set, so why not extend the piece with some more improv and solos?
As the piano historically has been a very useful composing tool because it can cover both the range of notes of the orchestra as well as the dynamics ("quiet" to "loud, aka pianoforte) so too the modern day synthesizer with a multitrack recording device/software can be an extension of this. A good synth today will have keys weighted like a piano and offer a compatible action with the addition of extended voices (1000's). Linked to a multitrack recording machine or computer running recording software, the composer can now model, and mix his idea with more clarity than with a piano score.
Another approach is to use automated notation software with sample sounds such as Sybelius or Finale, which allows for notation and hearing and making the whole process of copying parts for each performer so much faster and easier than hiring a copyest.
Often the compositional process is more about the composer's process and how the composer has developed the optimal workflow to accomplish his or hers vision. Hence, every artist faces learning a methodology that embraces their journey. We all start out with learning the same process but end up changing it to accommodate our personal way of doing things.
Answer: It also depends on what kind of song you are trying to write. If your style of music is such that it is more groove based (i.e. more soul, funk, hip-hop, dance, soul-jazz or even some hard-bop) Then you generally start with the core element of that groove. For example, Cantaloupe Island by Herbie Hancock on Empyrean Isles (1964) probably wrote that song around the piano part. The music to Another One Bites the Dust by Queen probably started with that famous bass line. Once you have that core element of the groove then you just build the other instrumental parts around that based on what supports the groove but doesn't get in the way. To develop the song you either layer in other instruments that fit into the groove, remove instruments, change volume, fill add more/less notes to the groove to develop it, or just add other sections that you go to and then return to the groove. If its a good groove the foundation doesn't need to change much.
If you are writing a bop, cool jazz, or 60's Blue Note style then those songs generally start either with a 12, 16, 24, or 32 measure set of chord changes and then they write the melody or visa-verse.
A lot of rock/country music is based on a couple repeated chords for the verse, a couple other repeated chords for the chorus, and then something else for the bridge.
Finally lots of music is based around catchy hooks and everything else is very simple. No one notices the simplicity because the hook is so good.
An easy and fun way to learn how to do this is take a song with a structure that you like and begin to modify it. Change a rhythm, change chords, add notes, add parts, add instruments, whatever you feel like until no one can tell it was the original song. Even if you don't ever use that for anything you still have had a good lesson in developing a song. Once you'd done that a couple times you can start doing it with your original components and modify/create from there.


Is Amazon EC2 instances good for plain webhosting?

Question: I'm thinking about using an Amazon EC2 instance for hosting a few websites of mine. A personal homepage, a blog, etc. Is the cost low or should i grab a hosting package from HostGator or similar?
Answer: No typically amazon ec2 is more expensive for regular web hosting. Especially when you only need web hosting and wouldn't need shell access (unless you want to do some special stuff on your personal website).
Answer: If you're wanting a root-account level system to host your personal sites to then you will find a VPS solution to be a much more cost advantage; however, if you're running a site that needs near instant scalability and redundancy where cost isn't an issue then EC2 instances are an ideal choice. Given the pricing model bandwidth is not that much of cost issue, however when you're talking running an instance 24 hours a day it becomes another story.
I currently run 10 EC2 instances 24/7 and bandwidth and storage are by far the lowest costs to factor in. If you take my Linode VPS instance with 1024MB RAM I pay just around $40/month for it to run 24/7. Compare that to even an Amazon Small (m1.small) EC2 instance which has 1.7GB RAM running 24/7 for 30 days you're talking 720 hours at $0.12/hr you're looking at $86.40 just in hourly run time costs. You can quickly see how that would add up if you ran multiple instances. If you ran a new Micro EC2 instance that only provides 613MB RAM you're looking at around $21.60 which would save you from the VPS but you've got less RAM which could handle a small static website but if you're using a database that's usually not enough to handle things.
Answer: I highly recommend to rent a "normal" VPS if you are familiar with Linux system administration. A VPS is cheaper and often has useful features, such as a VNC access when the system won't boot up.
Using a cloud instance maybe very interesting, but is maybe the wrong approach here.


How to insert to database using silverlight Dataset

Question: How can I enter dataset into the database using data
An example please
Answer: You can't access a database directly from a Silverlight client.  There are several ways to accomplish this but you basically need to call a web service from Silverlight.  See the following article for a step by step example: https://technet.microsoft.com/en-us/library/cc197937(VS.95).aspx


Push to an array and keep the array n items long

Question: How do I push an object to an array, then when the array becomes, say, 100 items in size, remove the first one and push again, and so on?
It could be a method, like arr.push('log item', 100)
How do I implement it better?
Answer: You might be looking for something like this:
if(arr.length === 100)
        arr.shift();
arr.push(VAL);

A method more like the OP's original request, replacing the push() with a new one with the option of limiting the size of the array
Array.prototype.originalPush = Array.prototype.push;
Array.prototype.push = function(val,limit)
{
    if(limit && this.length == limit)
        this.shift();
    this.originalPush(val);
}

Answer: You can simpy shift when you go over fixed length:

Array.prototype.push_maxlength = function(item, length) {
  this.push(item);
  if (this.length > length) {
    this.shift();
  }
}

var a = [1, 2, 3];

for (var i = 0; i < 10; ++i) {
  a.push_maxlength(i, 5);
  console.log(JSON.stringify(a));
}
Answer: myArray.slice(1) will return an array without the first item. So something along the lines of :
myArray.push(myNewData);
if (myArray.length > 100) {
  myArray = myArray.slice(1);
}

Answer: Check length!
function addTo100(array, newItem){
    if (array.length == 100){
        array.shift();
    }
    array.push(newItem);
    return array;
}

Answer: function pushMax(arr, val, maxLength) {
    arr.push(val);

    if (arr.length > maxLength) {
        array.shift();
    }
}

pushMax(arr, 'log item', 100);


CSS property overflow:hidden causes inner divs to appear below main div

Question: Is there a way to make my #inner_div stop appearing behind the #main_div if it exceeds a certain width? I tried removing the overflow:hidden from #main_div in css but that causes the background of the #main_div to load very slowly, so I would like to find another solution if possible. Thanks
Main div css:
#main_div {
  -moz-border-radius:5px;
  -moz-box-shadow: 0 3px 3px rgba(255, 255, 255, 0.1), 0 3px 0 #BBBBBB, 0 4px 0 #AAAAAA, 0 5px 3px #444444;
   background: none repeat scroll 0 0 #F6F6F6;
   border: 1px solid #FFFFFF;
   margin: 20px auto;
   overflow: hidden;
   padding: 10px;
   width: 970px;
}

Inner div css:
.inner_div{
   font-size:12px;
   font-weight:normal;
   font-style:normal;
   margin: 5px 0px 0px 10px;
   border-style: solid;
   border-width: 1px;
   border-color: #000000;
   z-index: 0;
   visibility: hidden;
   position: absolute;
   /* white-space: nowrap;*/
   text-align: left;
   padding: 5px 5px 5px 5px;
   width:200px;
}

Answer: Instead of using overflow:hidden, you should use the new "micro clearfix".
Go here: http://nicolasgallagher.com/micro-clearfix-hack/
In your markup, you simply just add the class "cf" on #main_div


Binding to DataGridView - Is there a way to "bind" the background color of a cell?

Question: I am binding a List to a DataGridView. One property of the SomeObject class will be a status code (ex. Red, Yellow, Green). Can I "bind" the status to the background color of a cell easily? How about binding to a tooltip also?
Comment: I really hope you get an answer to this, and that it's possible,  I've been unable to figure this out, I set the background color after the databinding by altering each cell style.  Unfortunately that is really slow :(  datagridview1.Rows[1].Cells[2].Style.BackColor = Color.Red
Answer: You can write a handler for the DataGridView's CellFormatting event to customise the background colour. Here's a worked example (you'll need to have dragged a DataGridView onto the default Form then double-clicked on the CellFormatting event to create a handler):
<code>using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private BindingSource _source = new BindingSource();

        public Form1()
        {
            InitializeComponent();

            _source.Add(new MyData(Status.Amber, "Item A"));
            _source.Add(new MyData(Status.Red, "Item B"));
            _source.Add(new MyData(Status.Green, "Item C"));
            _source.Add(new MyData(Status.Green, "Item D"));

            dataGridView1.DataSource = _source;
            dataGridView1.Columns[0].Visible = false;
        }

        private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex == 1)
            {
                DataGridView dgv = sender as DataGridView;
                MyData data = dgv.Rows[e.RowIndex].DataBoundItem as MyData;

                switch (data.Status)
                {
                    case Status.Green:
                        e.CellStyle.BackColor = Color.Green;
                        break;
                    case Status.Amber:
                        e.CellStyle.BackColor = Color.Orange;
                        break;
                    case Status.Red:
                        e.CellStyle.BackColor = Color.Red;
                        break;
                }
            }
        }
    }

    public class MyData
    {
        public Status Status { get; set; }
        public string Text { get; set; }

        public MyData(Status status, string text)
        {
            Status = status;
            Text = text;
        }
    }

    public enum Status
    {
        Green,
        Amber,
        Red
    }
}
</code>
The objects here just have a Status and Text for simplicity. I create a BindingSource for an example set of these objects, then use that as the data source for the DataGridView. By default, the grid automatically generates columns when you bind, so there's no need to do that manually. I also hide the first column, which is bound to the Status value, as we're going to colour the Text cells instead.
To actually do the painting, we respond to the CellFormatting event. We get a reference to the DataGridView by casting sender, then use the RowIndex property of the DataGridViewCellFormattingEventArgs object to get at the data item iteself (each Row has a DataBoundItem property that conveniently gives us this). As DataBoundItem is an object type, we need to cast it to our specific type, then we can actually get to the Status property itself...phew!
I haven't had any experience with tooltip programming, but I would have thought that you should respond to the MouseHover event, then work on discovering which row is being pointed at to start with.
I hope this helps.
Comment: +1, Great answer.  I found the last row was an empty row, so had to check if MyData was null.  Apart from that, great!
Comment: @Sint - formatting is only applied to on-screen items, so there shouldn't be a performance issue. If you want to apply a style to the entire row, you could add a handler to the RowPostPaint event: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowpostpaint%28v=vs.110%29.aspx
Comment: This works great, only question is whether there is a way to do this row at a time instead of a cell. Just wondering if there is any performance hit when you have 1000+ rows, 10+ columns.
Answer: Out of the box, any DataGridViewColumn can be bound to only one property of the objects in the DataSource, the name of the property being given by the DataPropertyName of each DataGridViewColumn (you'll have specific column types like: DataGridViewTextBoxColumn, ...).
You could use the DataGridView.CellFormatting event to change the style of the cell depending on the databound item. In the In the DataGridViewCellFormattingEventArgs of this event you get the row index, from there you can get the current object (the source of the row). From there, you could use any property of the object to influence your cell.
A good starting point (similar idea): here
A second idea would be do develop your own DataGridViewColumn type and add properties for other things you need to bind to. For example, the same way it has the built in DataPropertyName, you could add your own: BackgroundColorPropertyName. A starting point for building custom DataGridViewColumns can be found here.


CouchDB will not install as a service on Azure Windows VM

Question: I have previously installed CouchDB on my Azure Windows VM (Classic) without any problems using the installer setup-couchdb-1.6.1_R16B02.exe downloaded from http://couchdb.apache.org/
Today I have uninstalled the existing CouchDB installation and service with the intention of installing it again from scratch. Unfortunately, whenever I run the installer now it fails to create a windows service. More info:

I am running the installer and the command tool as Administrator
I have removed existing services using the SC command and by editing the registry (tried both methods)
I have tried creating the service after installing CouchDB using the installer by running the command:

erlsrv.exe add "Apache CouchDB" -workdir "%COUCH%\bin" -onfail
  restart_always -args "-sasl errlog_type error -s couch +A 4 +W w"
  -comment "Apache CouchDB 1.6.1"

This seems to create a service (which you can see in the Windows Services) but any attempt to start the service results in an error:

Windows could not start the Apache CouchDB service on Local Computer.
Error 1067: The process terminated unexpectedly.

I have tried uninstalling the CouchDB application, restarting the server, re-installing CouchDB using the installer again. No joy. Also then tried running the command to create the service. Still no joy.
When I use the command

erlsrv list

I can see the services that I've tried to add in the past. Any attempt to remove them results in the error message:

erosrv: Unable to remove service (not enough privileges?)
Error: The handle is invalid

(I am using the handle as provided by the erlsrv list command)

there are no events in the events log that I can find that explain why this is failing

How can I get CouchDB to install as a service correctly?
Answer: TL;DR: Re-install in a directory path with no spaces in it, then manually create the service.
OK so at some point in my Googling today I came across this answer which gave me the clue that I should install in a path without spaces in it. So my solution was to:

uninstall the CouchDB application via Windows Control Panel.
run the uninstall.exe in any remaining installations of CouchDB and delete those directories.
remove the existing services using the SC command.
reinstall using the installer into C:\CouchDB (note: no spaces!). Select the option to install as a service (even though this doesn't quite work).
run the command to manually create the service. Note that I'm not using the %COUCH% variable as it doesn't seem to exist on my system at this point:

erlsrv.exe add "CouchDB" -workdir "C:\CouchDB\bin" -onfail restart_always -args "-sasl errlog_type error -s couch +A 4 +W w" -comment "CouchDB 1.6.1"

This command finally managed to properly create a windows service for CouchDB that started correctly. Browsing to http://localhost:5984/_utils/ now brings me to the Futon UI. And relax!


Google DataFlow: read from Kafka and save to GCS - how to guarantee exactly-once?

Question: I'm going to create Cloud Dataflow pipeline (using Apache beam) which assumes next steps:

Reading messages from Kafka
Processing messages
Writing processed messages to Google Cloud Storage

I would like to commit offset to Kafka only if the message is stored in GCS succesfully, that is, implement exactly-once semantic to this flow.
How can I do it, is there any out-of-box support in KafkaIO.Read of at least any possibility to manage offsets manually?
Answer: There is a Kafka Connect plugin for this https://docs.confluent.io/current/connect/kafka-connect-gcs/gcs_connector.html
If you prefer to not use Kafka Connect, the source is open for that plugin and you can see how exactly once is achieved. However, I'd suggest giving it a go with Connect. It's pretty straightforward.
Comment: Thank you @dawsaw.

Would it work with Apache Beam pipeline?
Comment: It will just move messages between Kafka and GCS. I don't think it really helps if beam is a strict requirement here though you can do transforms. However the method of exactly once could work in your own beam pipeline so you could use it as an example.
Comment: It is not open source


Best distance measure to use to compare vectors of angles

Question: Context
I have two sets of data that I want to compare. Each data element in both sets is a vector containing 22 angles (all between $-\pi$ and $\pi$). The angles relate to a given human pose configuration, so a pose is defined by 22 joint angles.
What I am ultimately trying to do is determine the "closeness" of the two sets of data. So for each pose (22D vector) in one set, I want to find its nearest neighbour in the other set, and create a distance plot for each of the closest pairs.
Questions

Can I simply use Euclidean distance?

To be meaningful, I assume that the distance metric would need to be defined as: $\theta = |\theta_1 - \theta_2| \quad mod \quad \pi$, where $|...|$ is absolute value and mod is modulo. Then using the resulting 22 thetas, I can perform the standard Euclidean distance calculation, $\sqrt{t_1^2 + t_2^2 + \ldots + t_{22}^2}$.
Is this correct?

Would another distance metric be more useful, such as chi-square, or Bhattacharyya, or some other metric? If so, could you please provide some insight as to why.
Comment: As a side note: I don't think you mean $|\theta_1 - \theta_2| \mod \pi$. Rather something like $\min\{|\theta_1 - \theta_2|, 2 \pi - |\theta_1 - \theta_2|\}$.
Comment: Rather than working with angles, I suggest converting to (x, y)-coordinates on the unit-circle first. You can then calculate normally (distances and the like), and averaging isn't a problem like with angles.
Comment: Your problem will probably become much easier to solve if you can specify the consequences of "getting it wrong".  So if you say the data sets are the same or similar, but they in fact aren't, what will happen to you?  Will it depend on "how wrong" your decision was?  What will happen if you declare the data/poses different, but they are in fact the same or similar?  What is lost?  answering these questions will help determine *what matters* for the comparison *you* want to make.  This ensures that you are answering the right question.
Comment: @Josh Erik P.'s suggestion is a good one.  Alternatively, consider each angle $\theta$ to be a point $\left(\cos(\theta), \sin(\theta)\right)$ on the unit circle and compute the Euclidean distances between them using the usual (Pythagorean) formula.  The difference between these distances and the angular distances shouldn't matter.  (I believe this may be what Caracal suggested, too.)
Comment: @Josh The average of, e.g.,  $\pi/4$ and $7\pi/4$ is $\pi$. In many circumstances, this doesn't make sense, and it should be $0$ instead. In your specific situation, this might not be an issue since maybe human joints don't have a range of motion past $\pi$. Also, in your case, maybe you want the aforementioned average to be $\pi$ since the joint motion is uni-directional. @whuber's suggestion is exactly what I meant.
Comment: @suncoolsu The motive is to determine if my training set has enough similar examples to infer the poses of my test set. I am using a learning-based approach to pose estimation, and I am beginning to suspect that the data I am using is too different across data sets. I want to ensure that for each pose in a test set, there is at least a "reasonably similar" pose in the training set. Visually (reanimating the poses) it appears that my suspicion is well-founded, but I want to analyse it quantitatively.
Comment: @probabilityislogic The consequence is simply a pose that is not representative of the ground truth pose. It would depend on the estimation approach used as to what would occur. If knn was used then the nearest neighbour would be too distant. What is considered "too distant"? It depends on the application, but as a general rule, it should at least be indicative of the action being performed (e.g. in a walking sequence, you would always want to have the person in an upright position). However, in ridge regression, the learnt mapping is wrong and likely to result in output that is rubbish.
Comment: @Josh, could you put up a couple of pictures / stick diagrams of various poses ? They'd be a nice example of the relation between reality and strings of numbers.
Comment: what is your motive behind "determining the closeness" of these data sets? What you are trying to do may be Ok.., but may inference can be improved if you are interested in other specifics like `mean configuration` or equivalent.
Comment: @caracal Can you please explain what problem exists when averaging angles? Is it specific to a particular representation, or a general problem regardless of representation? Thanks.
Comment: @Erik, I just corrected what @Josh had and I think @whuber is right.
Comment: @whuber Using the unit circle seems like the best approach. I can then convert each distance between two angles back into an angle ( theta = cos^-1((2-dist^2)/2) ), given the properties the unit circle and the law of cosines, right?
Comment: @caracal Thanks for the example and also the suggestion of the unit circle representation; I understand what you mean now.
Comment: @probabilityislogic Adding to my previous comment, the learnt mapping isn't necessarily wrong (of course you have to be careful of overfitting, and other considerations... perhaps you can't even use a linear regressor given the problem statement), but applying a learnt mapping for doing push-ups to a walking sequence is going to give very wrong output poses in every case. Whereas, a jogging sequence mapping, whilst still not perfect, would yield much better results, even though it is still not the best mapping to use.
Answer: you can calculate the covariance matrix for each set and then calculate the Hausdorff distance between the two set using the Mahalanobis distance.
The Mahalanobis distance is a useful way of determining similarity of an unknown sample set to a known one. It differs from Euclidean distance in that it takes into account the correlations of the data set and is scale-invariant.
Answer: What are you trying to do with the nearest neighbor information?
I would answer that question, and then compare the different distance measures in light of that.
For example, say you are trying to classify poses based on the joint configuration, and would like joint vectors from the same pose to be close together.  A straightforward way to evaluate the suitability of different distance metrics is to use each of them in a KNN classifier, and compare the out-of-sample accuracies of each of the resulting models.
Answer: This sounds like it is similar to a certain application of Information Retrieval (IR). A few years ago I attended a talk about gait recognition that sounds similar to what you are doing. In Information Retrieval, "documents" (in your case: a person's angle data) are compared to some query (which in your case could be "is there a person with angle data (.., ..)"). Then the documents are listed in the order of the one that matches the closest down to the one that matches the least. That, in turn, means that one central component of IR is putting a document in some kind of vector space (in your case: angle space) and comparing it to one specific query or example document or measuring their distance. (See below.) If you have a sound definition of the distance between two individual vectors, all you have to do is coming up with a measure for the distance of two data sets. (Traditionally in IR the distance in vector space model is calculated either by the cosine measure or Euclidean distance but I don't remember how they did it in that case.)
In IR there is also a mechanism called "relevance feedback" that, conceptually, works with the distance of two sets of documents. That mechanism normally uses a measure of distance that sums up all individual distances between all pairs of documents (or in your case: person vectors). Maybe that is of use to you.
The following page has some papers that seem relevant to your issue: http://www.mpi-inf.mpg.de/~mmueller/index_publications.html
Especially this one http://www.mpi-inf.mpg.de/~mmueller/publications/2006_DemuthRoederMuellerEberhardt_MocapRetrievalSystem_ECIR.pdf seems interesting.
The talk of Müller that I attended mentions similarity measures from Kovar and Gleicher called "point cloud" (see http://portal.acm.org/citation.cfm?id=1186562.1015760&coll=DL&dl=ACM) and one called "quaternions".
Hope, it helps.
Comment: It would be useful to have the reference if you are able to find it. Thanks.
Answer: This problem is called Distance Metric Learning.  Every distance metric can be represented as $\sqrt{(x-y)^tA(x-y)}$ where $A$ is positive semi-definite. Methods under this sub-area, learn the optimal $A$ for your data. In fact, if the optimal $A$ happens to be an identity matrix, it is okay to use euclidean distances. If it is the inverse covariance, it would be optimal to use the Mahalanobis distance, and so on and so forth. Hence, a distance metric learning method must be used to learn the optimal $A$, to learn the right distance metric.
Answer: One problem with using the angles as a proxy for shape is that small perturbations in the angles can lead to large perturbations in the shape. Further, different angle configurations could result in the same (or similar) shape.


Transmute works but mutate does not

Question: I have the dataset below along with other columns not shown here:
  v0102      v0103      child.below14 child.above14
1 31000010   1                      0             0
2 31000010   1                      0             0
3 31000010   1                      1             0
4 31000010   1                      1             0
5 31605621   1                      0             0
6 31605621   1                      1             0
7 31605621   1                      1             0
8 31605877   1                      0             0
9 31605877   1                      1             0

I want to groupby the first two columns and count the number of children below and above 14 years old. When I try with transmute, I get the expected answer:
df.pnad.mg %>% group_by(v0102, v0103) %>% transmute(children.below14 = sum(child.below14), children.above14 = sum(child.above14))

   v0102      v0103      children.below14 children.above14
 1 31000010   1                         3                0
 2 31000010   1                         3                0
 3 31000010   1                         3                0
 4 31000010   1                         3                0
 5 31605621   1                         2                0
 6 31605621   1                         2                0
 7 31605621   1                         2                0
 8 31605621   1                         2                0
 9 31605877   1                         1                0

However, when I switch from transmute to mutate, the output seems to ignore the group_by() verb:
df.pnad.mg %>% group_by(v0102, v0103) %>% mutate(children.below14 = sum(child.below14), children.above14 = sum(child.above14))

  v0102      v0103      children.below14 children.above14
1 31000010   1                      8092             7949
2 31000010   1                      8092             7949
3 31000010   1                      8092             7949
4 31000010   1                      8092             7949
5 31000010   1                      8092             7949
6 31605621   1                      8092             7949
7 31605621   1                      8092             7949
8 31605621   1                      8092             7949
9 31605877   1                      8092             7949

Am I missing something?
Comment: Can you run `packageVersion("dplyr")`? I get your expected output using 1.0.2.
Answer: The function you want is summarize not mutate.
df.pnad.mg %>%
  group_by(v0102, v0103) %>%
  summarize(children.below14 = sum(child.below14),
            children.above14 = sum(child.above14))

When you use mutate it will calculate the sums, but it keeps all of the rows.
Using the nine rows of your data, this is the output I get:
`summarise()` regrouping output by 'v0102' (override with `.groups` argument)
# A tibble: 3 x 4
# Groups:   v0102 [3]
     v0102 v0103 children.below14 children.above14
     <dbl> <dbl>            <dbl>            <dbl>
1 31000010     1                2                0
2 31605621     1                2                0
3 31605877     1                1                0

If your desire is to keep all rows, then mutate should work. I cannot reproduce your mutate issue in dplyr 1.0.2. Here is my output for mutate:
df.pnad.mg %>%
  group_by(v0102, v0103) %>%
  mutate(children.below14 = sum(child.below14),
         children.above14 = sum(child.above14))
# A tibble: 9 x 6
# Groups:   v0102, v0103 [3]
     v0102 v0103 child.below14 child.above14 children.below14 children.above14
     <dbl> <dbl>         <dbl>         <dbl>            <dbl>            <dbl>
1 31000010     1             0             0                2                0
2 31000010     1             0             0                2                0
3 31000010     1             1             0                2                0
4 31000010     1             1             0                2                0
5 31605621     1             0             0                2                0
6 31605621     1             1             0                2                0
7 31605621     1             1             0                2                0
8 31605877     1             0             0                1                0
9 31605877     1             1             0                1                0

If you want to create these new columns and drop the old ones, then transmute is what you do.
Comment: @GustavoRangel - This is exactly what summarize does.
Comment: I want to create a new column with the number of children above and below 14 for each pair of (v0102, v0103). I don't believe summarize does that.
Comment: Sorry If I am not being clear. Your anwser gives me a 3-row table, instead of the 9 I need to put them together with the original dataset.
Comment: @GustavoRangel - I cannot reproduce the issue you have with `mutate`. If `transmute` works, why not just use it?
Comment: I decided to reinstall dplyr (same version 1.0.4) and now I get the expected answer. Pretty weird, but thank you so much for your effort!
Answer: This can be solved using across in the following manner:
library("tidyverse")
dta <- read_delim(
    file = "id v0102      v0103      child.below14 child.above14
1 31000010   1                      0             0
2 31000010   1                      0             0
3 31000010   1                      1             0
4 31000010   1                      1             0
5 31605621   1                      0             0
6 31605621   1                      1             0
7 31605621   1                      1             0
8 31605877   1                      0             0
9 31605877   1                      1             0",
delim = " ",
col_types = cols(.default = col_integer()),
trim_ws = TRUE
)

group_by(dta, v0102, v0103, .add = TRUE) %>%
    mutate(across(
        .cols = starts_with("child"),
        .fns = sum,
        .names = "sum_{.col}"
    )) %>%
    ungroup()

Results
# A tibble: 9 x 7
     id    v0102 v0103 child.below14 child.above14 sum_child.below14 sum_child.above14
  <int>    <int> <int>         <int>         <int>             <int>             <int>
1     1 31000010     1             0             0                 2                 0
2     2 31000010     1             0             0                 2                 0
3     3 31000010     1             1             0                 2                 0
4     4 31000010     1             1             0                 2                 0
5     5 31605621     1             0             0                 2                 0
6     6 31605621     1             1             0                 2                 0
7     7 31605621     1             1             0                 2                 0
8     8 31605877     1             0             0                 1                 0
9     9 31605877     1             1             0                 1                 0

Notes

.names argument takes glue specification, it's worthwhile to reflect on that so the obtained names are meaningful
.add in group_by makes sense if there are any other groups you may want to preserve.

Transmute works but mutate does not


Nested polyrhythms

Question: In my research on polyrhythms I have discovered the term "nested polyrhythm" with regard to some of Frank Zappa's works. I have not been able to find a clear definition of it or any examples.
Would someone please explain the term to me and show me some scores where they are heavily employed?
Comment: I posted a question asking about the simplest possible nested polyrhythm - actually nested triplets. See https://music.stackexchange.com/q/38434/9426
Comment: Thank you! Your question doesn't exactly picture a nested polyrhythm, but it does mention the other instruments' parts playing 4/4 straight, which does a good job at explaining to me what it would be like. I am not certain if the score you got from your local composer qualifies as a "nested polyrhythm". Do 2+ voices have to have nested tuplets for the polyrhythm to be considered nested? I don't know. But I don't think it matters. I will try to respond to my own question later and wait for any more input in the meantime.
Answer: Judging by the information Brian has kindly linked me to, the notion of "nested" polyrhythms relies on a tuplet subdivision inside of another tuplet, for example:

If the second voice were to play straight quarter notes in the second bar, it would create a nested polyrhythm. It is unclear whether both voices need to have nested tuplets for a polyrhythm to be considered "nested", but I assume they don't.

Nested polyrhythms


Block wrapping DIV disable with theme hook?

Question: I've managed to suppress the wrapping markup for a few blocks using
block--block--1.tpl.php
region--banner.tpl.php
but now it's getting messy as I have several blocks which require no additional wrpaping markup so I would ideally like to do this in a theme function with a switch case...but can't find any example that works...
function front_preprocess_block(&$vars, $hook) {
$to_delete = array('block-block-4');

//if(in_array($vars['block']->delta , $to_delete)) {
//  $vars['template_files'][0] = 'block-empty';
//}

print_r($vars);

}
I need to remove wrppaing DIV's for about 4 blocks onlys...ideas???
Answer: You can specify an additional variable in hook_preprocess_block() and check for that variable in block.tpl.php file, example:
function front_preprocess_block(&$vars, $hook) {
  //dpm($vars);
  $vars['must_be_removed'] = FALSE;
  if(/* CONDITION e.g. $vars['elements']['#block']->delta == 'MY_BLOCK_DELTA' */) {
    $vars['must_be_removed'] = TRUE;
  }
}

and block.tpl.php file;
<?php if($must_be_removed): ?>
  <?php print $content ?>
<?php else: ?>
<div id="<?php print $block_html_id; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>>

  <?php print render($title_prefix); ?>
<?php if ($block->subject): ?>
  <h2<?php print $title_attributes; ?>><?php print $block->subject ?>

<?php endif;?>
  <?php print render($title_suffix); ?>

  <div class="content"<?php print $content_attributes; ?>>
    <?php print $content ?>

<?php endif; ?>

Comment: Ohhh...so I can't stub out the markup just from a function but rather use the catch-all block.tpl.php and conditional tests...OK that works :) thank you kindly
Comment: @Alex.Barylski I'm glad if I could help you..


Packing boxes and proof of Riemann Hypothesis

Question: From Scott Aaronson's blog:

There's a finite (and not
  unimaginably-large) set of boxes, such
  that if we knew how to pack those
  boxes into the trunk of your car, then
  we'd also know a proof of the Riemann
  Hypothesis. Indeed, every formal proof
  of the Riemann Hypothesis with at most
  (say) a million symbols corresponds to
  some way of packing the boxes into
  your trunk, and vice versa.
  Furthermore, a list of the boxes and
  their dimensions can be feasibly
  written down.

His later commented to explain where he get this from: "3-dimensional bin-packing is NP-complete."
I don't see how these two are related.
Another question inspired by the same article is here.
Answer: The question of whether a formal proof of the Riemann Hypothesis exists (with at most a million symbols) is a problem in NP: given such a proof, it can be verified to be correct in polynomial time.
Bin-packing is NP-complete: this means that every problem in NP can be reduced to bin packing. In particular, the problem mentioned in the previous paragraph can. (This is a reduction that can be made explicit, so once we specify the proof verifier etc., we can carry out the steps of the reduction to get an instance of bin packing. We also need the reduction to be "parsimonious" i.e. solutions correspond one-to-one; I believe it is.)
Comment: The "solutions correspond one-to-one" (and onto) is key, or else his statement doesn't hold.  I find that very hard to believe - reductions from A to B are rarely such that every problem in A corresponds to exactly one problem in B.
Comment: Problems don't have to correspond, only solutions for a *fixed instance* of each problem. I believe we do have such a "parsimonious" reduction (they're quite common actually), but even if we don't, something similar in spirit still holds: if we can solve bin packing, then we can solve it a few times to obtain a proof of the Riemann hypothesis. (E.g. solve the bin packing instances corresponding to "does there exist a proof with first bit 0?" then repeat once you know the first bit, etc.)
Comment: so we are assuming any proof can be verified in polynomial time? If that's true then it all makes sense.
Comment: @Chao Xu: Yes, a "formal proof" (see [Wikipedia](http://en.wikipedia.org/wiki/Formal_proof) or [this Notices of the AMS issue](http://www.ams.org/notices/200811/)) is a proof written in a certain precise form that can be checked by computer. Actually, if we fix a bound on the proof length at 1 million, we don't even need to say "polynomial time", since the size is a constant. :-)
Comment: See also [this answer](http://math.stackexchange.com/questions/944/proving-the-riemann-hypothesis-without-revealing-anything-other-than-you-proved-i/1441#1441) by `T..`.


How to use PAT on Azure DevOPS Server to clone a git repo

Question: Hi we are trying to clone a git repo from our local Azure DevOps server 2020.0.1. We are using the command bellow, but it is not working. Should this be possible?
The documentation I try to follow is this. But it is a bit unclear.
git clone https://{an username:yourPAT}@yourURL/yourOrgName/yourProjectName/_git/yourRepoName

We then get an error: "fatal: Authentication failed for "
We also tried variations like 'yourname:yourPAT', 'yourPAT', ':yourPAT', 'yourPAT:'
We want to use PAT's together with SmartGit
We then tried to use the other method mentioned (but when reading this is only needed when using basic authentication, we never enabled this on our ADOS-server, and is also not an authentication method on our IIS-website:
$MyPat = 'yourPAT'
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$MyPat"))
git -c http.extraHeader="Authorization: Basic $B64Pat" clone https://{yourURL/yourOrgName/yourProjectName/_git/yourRepoName

This one is working
The PAT we created is with full scope and access to all organizations.
The PAT is working to add an Agent.
We can also use it to access the RESTAPI (with curl you should -u and random or empty username, so bla;yourPAT).
Any advice is appreciated.
Answer: Based on your description, when you use the basic auth to run the git command, it could work.
It seems that the basic auth is enabled.
If you enable IIS Basic Authentication for Azure Devops server, PATs aren't valid. See Enabling IIS Basic Authentication invalidates using Personal Access Tokens.

If you use Git with IIS Basic Authentication, Git breaks because it requires PATs for user authentication. Although we don't recommend you use IIS Basic Authentication, by adding an extra header to Git requests, you can use Git with IIS Basic Authentication:

You could open IIS Manager -> IIS -> Authentication  and check if the  Basic Authentication is disabled.

On the other hand, you could remove the Azure DevOps Server related credentials from Credential Manager:
Open the control panel on windows–> Click on User Accounts–> Click on Manage your Credentials–>Click on Windows Credentials, locate the entry for your remote git repository–>Click on the item in the list and select Remove–> Finally try to use PAT again to clone a git Repo.
Comment: The Basic Authenticator is not installed on the server
Comment: Removing the credential form the local Credential Manager does not work. Also I removed: credential.helper from the Git config.


How to block all users/visitors in my website that disable javascript?

Question: I got a lot of bots on my website. The problem is that they increase our bounce rate which makes us look bad for google. If users bounce they dont like the site. That is a bad signal for SEO
most of these bots have javascript disabled. On the other hand no real user disables javascript. is it possible block all users/visitors in my website that disable javascript? Thanks
Comment: Wrong question. Let me help you with this: "How can I fix our web analytics software, so that it ignores bots?"
Comment: And about that "No real user disables Javascript" you are in dire need of reading this: https://gds.blog.gov.uk/2013/10/21/how-many-people-are-missing-out-on-javascript-enhancement/
Comment: Some real users disable javascript too, it may be a bad signal for those user if you kick them of your site.
Comment: I'm sure blocking all bots / no-js-visitors (_Which includes Google's_) will increase your Google ranking! \*Cough*
Comment: Maybe this would be worth a read.. http://en.linuxreviews.org/HOWTO_stop_automated_spam-bots_using_.htaccess
Comment: If user has JavaScript disabled, Google is not tracking them already (because it uses JS to do so), so I don't think they are contributing towards your overall bounce rate.
Comment: Boldewyn sorry but my question is not wrong. Thank you
Comment: Pierre.Sassoulas yes thee are some users and those users are the one i want to block.
Comment: Boldewyn i will read it and will give you update. Thanks
Comment: pbwned i will also read it and give you update as soon as am done reading the link you gave. Thanks
Comment: martynasma am not sure about your point but for now I need to block the user that disable javascript. Thanks
Comment: @martynasma What about iframes/images in `` tag?
Comment: @Justinas I don't think GA has that fallback in their officially-generated tracking code anymore.
Answer: There is one file that is named robots.txt to prevent certain robots from accessing your site. More information about that here.
If you wish to prevent some content viewable without JS, just load it using JS (ajax) or use CSS to apply overlay for your web and remove it with JS after page loads.

Robots have no idea if there is any user in world (e.g. zombie apocalypse). You have to decide what you want - detect if JS is working OR detect robot and prevent it from accessing site. Your google analytics code will not work without JS if placed as simple script in header. If GA code contains  tag, remove it and any user that don't have JS will not send any information to GA.
Comment: Thank you Justinas. I will give you update as soon test and i read the link you gave me.
Comment: Justinas i think the robots.text will solve my problem but how does robots will detect if the user javascript is disable? Thanks
Comment: @MarkAnthonyBarangan: robots.txt is a simple text file. It works because bots (like Google, Bing etc.) are supposed to read it and not crawl the links/url listed in that text file. It's a voluntary thing. An evil person can of course write bots that ignore that file. An evil person can also write a bot using phantomjs or selenium which would have javascript enabled.
Comment: @MarkAnthonyBarangan: If you doubt such programmers (who use phantomjs to scrape websites) exist let me tell you that these days I tend to use phantomjs to scrape websites because too many websites generate content with javascript making old-school screen scraping next to useless.


Getting an error while installing drupal 7 using xampp

Question: Getting an error while installing drupal 7 using xampp

An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows. Path:
  http://localhost/tes/install.php?profile=standard&locale=en&id=1&op=do
  StatusText: OK ResponseText: Fatal error: Maximum execution time of 30
  seconds exceeded in C:\XAMPP\htdocs\tes\includes\database\database.inc
  on line 2171

I also tried reinstalling xampp but still didnt work out
Comment: http://stackoverflow.com/questions/5164930/fatal-error-maximum-execution-time-of-30-seconds-exceeded
Answer: Try to compare & update these values in php.ini.

max_execution_time = 300
max_input_time = 180
max_input_nesting_level = 300
memory_limit = 512M

Note : After these changes, restart the server.
Comment: @ReckeR Have you restarted the server after changes?
Comment: nope...still not working..!!!
Comment: okay..the error gone...installed successfully...but I can't login...it doesn't even give any error...it just says access denied
Comment: actually it just worked out with firefox but still not working with damn chrome...!!!
Comment: once try to clear browser cache.
Comment: I cleaned all the cache from everywhere but still didn't work.. Nway I'm not gonna bother any more... Thanks a lot man!
Comment: You welcome @ReckeR


BitTorrent in the Office?

Question: I read in places that BitTorrent is either not very good on a LAN, or brings no benefit.
It seems that for file sharing though, it could be in theory a good way of things in a corporate environment ?

Is it really inappropriate for LANs ?
It would have be private of course: no way should any data leave the corporate n/w.
Would we need a 'tracker' server to publish things ?

Thanks,
John
Comment: @runDown That's just a benefit of having a the files published on your LAN. the distribution method is irrelevant there.
Comment: It's great because you can then load it up on your portable player of choice and watch your TV shows on the ride home from work.
Answer: The obvious way to keep it private is through use of firewalls and not publishing the tracker outside of your office.  Trackers themselves do need to be published, as I remember.
The basic problem that BitTorrent is solving is how to get thousands of people to efficiently download at high speed from a point source on the Internet.  The bottleneck in this situation is the connection from the server to the Internet; after that, the packets go in all different directions on different connections.  In an office LAN, the equivalent connection is going to be the Ethernet cable from the server to the switch, and the easiest way to reduce that as a bottleneck is to use gigabit Ethernet, not to use a complicated software solution.  It's also possible that the bottleneck is the switch itself that is routing the packets; in a case like this, the speed of distribution will entirely depend on the switch, and BitTorrent will actually slow things down (on a local and global basis) by adding overhead to the file transfers.
Answer: There are two benefits of bittorrent:

Files are distributed and therefore less likely to go away.
Fast file transfer thanks to many people serving a file.

In a LAN the connection is usually the limiting speed factor, not the server.
The benefit of distributed files is often not needed because there is usually a reliable server.
Bittorrent is quite bad for the network because it opens up many connections and can block other people from using the internet.
I'd not use it for file distribution in a LAN.
Answer: BitTorrent is great for distributing files where you don't need a big server (farm) hosting the file, as clients also become servers and as the popularity of the file grows, so does the capacity for distributing the file. This is where the brilliance of BT lies, and why it is a very good for low/no-budget operations to distribute data to a large "audience". Robustness is also a factor.
For LAN these conditions are not at all present, and you are better off with traditional technologies.

BitTorrent in the Office?


Writing to subprocess.Popen.stdin not Executing Correctly

Question: Why do the "subprocess.Popen.stdin.write" commands seem to fail?
#!/usr/bin/env python3
# coding=utf-8
import os
import subprocess

bash = subprocess.Popen(['bash'],
    stdout=subprocess.PIPE, stdin=subprocess.PIPE,
    stderr=subprocess.PIPE, shell=True)

(shell=True: see edit 2)
bash.stdin.write(b'echo foo\n')
print(bash.stdout.readline())
bash.stdin.write(b'echo bar\n')
print(bash.stdout.readline())

edit: It blocks at the first subprocess.Popen.stdout.readline(), probably because there are no lines in subprocess.Popen.stdout. It is supposed to print out:
foo
bar

edit 2: This still hangs.
Comment: Do you get any error message? What does it do and what it is supposed to do?
Comment: it won't do it. bash has a number of execution modes and what you are looking for is shell mode. what you can do is to do `shell=True` when you call `Popen` but you will create a security hole. you should check the doc: https://docs.python.org/2/library/subprocess.html
Comment: what happens you do bash? apparently it looks working for me, it's like this because your bash print some of these when it launches in shell mode. another solution to this is `ptty`, it's more correct but more complicated. if you want to do the right thing, you will want to check that as well.
Answer: This answer for my question works as long as you run GNU/Linux(maybe others, haven't tested) and install pexpect("pip install pexpect").
#!/usr/bin/env python3
# coding=utf-8
"""
Python command line software control example
"""
import pexpect

encode = 'UTF-8'

bash = pexpect.spawn('/usr/bin/env bash', encoding=encode)

bash.sendline('echo foo')
print(bash.readline())
bash.sendline('echo bar')
print(bash.readline())


Drupal 7 - Print & email Pages

Question: I'm using "Printer, email and PDF versions" Module (Drupal 7). Its functions are Print pages &  forward the page content through email. When i share a page to another person through email, the message is clipped in there inbox and reporting as Phishing , also images are not displaying.
We have to configure anything from admin side.? why does this issue occurs?
Answer: Email clients are typically configured not to show images by default for security reasons (Example: hide offensive images, block malicious/harmful images, etc).  See https://security.stackexchange.com/questions/7489/why-would-someone-want-to-block-images-in-email.
Similarly, if an email client detects that the From address of your email doesn't match the actual server that sent it, then your email may be flagged as a phishing email.  See http://drupal.org/node/336038#comment-4735232.
Consider using a module like an SMTP Authentication module so that you can send emails through an smtp server such as Google's if you're using a Gmail address.

Drupal 7 - Print & email Pages


Help with proving that all ζ ∈ ℚ have a periodic decimal expansion

Question: I've been trying to prove that all ζ ∈ ℚ have periodic decimal expansion. I assume that a terminating decimal expansion counts as a periodic decimal expansion as well since the zeros are periodic as well.
I managed to prove that for all ζ ∈ ℝ with a periodic decimal expansion we have that ζ ∈ ℚ. However, I don't know how to prove that all ζ ∈ ℚ have a periodic decimal expansion. Any tips on how I can prove this?
I've seen answers to my question involving terms like "mod" and "ring" but am not familiar with these terms so my question still stands.
Answer: The decimal expansion of a rational number is the result of the operation of long division. Look at the long division algorithm for a specific rational number that results in a repeating decimal. Notice that three are only so many remainders that come up. Once you see the same one again, you're in repetition.
Can you get a proof out of that observation?
Comment: I'll look into it, thanks for the comment.


Proving that any two consecutive elements of codomain of a function are relatively prime

Question: $h$ is defined as follows: $ h(1) = h(2) = 1; h(n) = (h(n-1))^2 + h(n-2)$ if $n > 2$.
Prove that for all n>1 that the $gcd(h(n), h(n-1)) = 1$.

My attempt with proof by induction:
Let $P(n)$ be the statement that $gcd(h(n), h(n-1)) = 1$.
$P(2)$ is true because $gcd(h(2),h(1)) = gcd(1,1) = 1$
Assume $P(n)$. We shall prove $P(n+1)$.
We know that gcd(a,b) = gcd(b,r) if there exists q and r ints such that a = bq+r .
Thus, $gcd(h(n+1),h(n)) = gcd(h(n),h(n-1)),$ where $h(n+1) = a$, $h(n) = b$, and $h(n-1) = r$.
(from the function definition seemed to fit $a=bq+r$, with $b=q$)
By the inductive hypothesis, $gcd(h(n), h(n-1)) = 1$
Hence, P(n+1) is True.
Any flaws?
Comment: This is incorrect. When you divide h(n+1) to h(n) you don't know that the remainder is h(n-1).
Comment: isn't the function defined in basically a = bq +r form? with b = q each time. So h(n+1) = h(n)^2 + h(n-1) ?  h(5) = 27, h(4) = 5, and h(3) = 2.   27=5*5 +3.  r =3
Answer: Assume that $d>1$ divides both $h(n)$ and $h(n-1)$. Then from the function definition, $d$ divides $h(n-2)$. Then it divides $h(n-3)$ and so on, you go back as much as needed... finally $d$ divides $h(1)$ which is $1$. Contradiction (since $d>1$).


Estimation of critical values in Spearman rank correlation

Question: According to Wikipedia, to evaluate significance of the Spearman rank correlation, you can use:
$$t = r \sqrt{\frac{n-2}{1-r^2}}$$
but I don't understand how to use this or how this generates the values as shown here:
http://web.anglia.ac.uk/numbers/biostatistics/spearman/local_folder/critical_values.html
Nothing I try matches and online explanations are scarce.
Comment: `how to use this`. Isn't it that `t` to plug into Student's distribution with `n-2` df?
Comment: Apparently, but none of it matches the critical value tables so I don't know how to use any of this.
Comment: Your formula is incorrect (you have an extra $r$): $$t = \sqrt{\frac{n-2}{1-r_{s}^{2}}}$$
Comment: @Alexis See http://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient#Determining_significance
Comment: My mistake! Confused formula for the standard error of $r_{s}$. :)
Answer: There's no great mystery here.

The distribution of the Spearman correlation is discrete. (The set of ranks of $n$ values are discrete, so the Spearman correlation will necessarily be discrete.)
The relevant Wikipedia page lists several approximations for the distribution of the Spearman correlation coefficient; I think the t-approximation is the second listed. The resulting p-values are not exact in small samples (but are reasonably close considering it's a continuous approximation of a discrete distribution - see the plot).
Since the exact small sample distribution (under the null) for the Spearman correlation can be computed, exact small sample tables exist. The table you link to appears to be a table of critical correlations (yielding type I error no greater than the listed significance levels) derived from the exact distribution.

A continuity correction would probably help here.
Edit: actually, it looks like a suitable continuity correction helps quite a lot overall (however it's slightly less accurate for small portions of the range of $r_s$, so while most of the time it improves the approximation, sometimes it doesn't).
--
How to use the t-statistic that Wikipedia gives: you can get one- or two-tailed p-values from the cdf of the $t$ with $n-2$ d.f. just in the same way as you would for any t-statistic with given degrees of freedom.
You can get critical values from the inverse CDF of the $t$. As noted above, these will be approximate, but the approximation kicks in pretty quickly. You don't need very large $n$ before it's suitable for most purposes.
Comment: Wait ... you want me to teach you enough to write *code* for it? How much time am I to invest in this enterprise?
Comment: Is there a way to compute such values directly without using R or Stata, etc?
Comment: What values are we computing? p-values? critical values? If critical values, for what statistic?
Comment: Any/all of it. I've been searching for this sort of thing all day long (literally) with little success because of how vague everything is. I don't like solutions that are basically "just use this table" or "use this pt() function in R". I want to actually understand what everything means so I can write the code myself. I can write the code but I just need to know what it is I need to actually compute!
Comment: @Glen_b Well this is all free / open to the courtesy of people willing to spend time, so technically, nothing is expected. That being said, what I have in mind shouldn't take more than a minute or two for someone who is sufficiently well versed in the material. What I mean is stuff like "if you have a spearman / pearson r value, you can compute the p values this way, the values should match this table, this is what a critical value is and how it's computed, etc." If some nasty distribution is involved I can just write a binary search or numeric integration approximator, no big deal.
Comment: The problem has been first and foremost finding the _right_ way to compute all this stuff so it matches all the values I see in all these tables and online calculators and such.
Comment: Try this as a starting point http://www.emis.de/journals/MV/074/mv07402.pdf  ... That's about all I can do in 1 minute.
Comment: @Glen_b I understand enough to know the magnitude of what I'm asking and what is possible. I've already gone through the paper and my initial suspicions were correct. I wasn't (trying) to be snarky at you. I am just impatient with people who assume that what I'm asking is crazy when it's not. I'm a big believer of "If you can't state it simply, you don't understand it enough" or however the quote goes.
Answer: Here's how reconcile your table. For instance, look at the df=15 and $\alpha=0.05$, you see the critical value 0.446. Plug this thing into the formula, and look at the value of cumulative distribution function of Student t distribution with df=15-2. Here's the code in R:
<code>> pt(0.446*sqrt(13/(1-0.446^2)),13)
[1] 0.9521751
</code>
You see that the right tail is about 5%, so, for two tailed test you get 10% in the tails - exactly what you asked with $\alpha=0.1$.
The formula in Wikipedia tell you that the expression is from Student t with n-2 degrees of freedom. Btw, this is how MATLAB calculates Spearman's critical value when there's a tie. Otherwise, it uses AS89 algo, to which I referred you in your other thread, but you didn't seem to like it :)
Comment: In general I don't like using functions I don't understand. I prefer being able to compute everything in my own program so I know all the guts and details.
Comment: @user62753, it's a good principled position, but at some point you got to stop. You're not going to implement exp and log, I'm assuming. You may claim that you understand them, but do you really? I bet you don't know how exactly exp is implemented inside CPU.
Comment: I have implemented them before in the past, actually. I understand how exp() is computed with respect to mathematics. In the CPU there may be other optimizations. But that's a one-off example. I don't need to know _everything_, but for things like statistics where even the high-level concepts are hard to understand, I want to actually implement the stuff.
Comment: Sort of like how you study better when you write and take notes. For me, I learn better when I actually write code.
Comment: @user62753 the best way to learn is to look at the actual code.


How can I make Apache rewrite not break an image?

Question: I have a very simple html page sitting at example.com. It consists solely of the following index.html:

The page loads exactly as expected when I go to example.com, but I wanted to make it so any requests to example.com are redirected to this front page (so example.com/catfood takes a user to example.com). I added the following to .htaccess for this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/
RewriteRule ^ / [R=301]

It redirects correctly, but it breaks the image. I believe this is happening because the request to example.com/images/picture1.jpg is now being redirected to the index page, but I'm not sure what I need to add to my .htaccess to allow the blanket redirection to happen while still loading this image on the front page.
Answer: Add another RewriteCond saying that the rule only applies if the request doesn't point to an existing file.
RewriteCond   %{REQUEST_FILENAME} !-f

So:
RewriteEngine On
RewriteCond   %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !=/
RewriteRule ^ / [R=301]

See
https://httpd.apache.org/docs/current/mod/mod_rewrite.html


Como utilizar a escolha do form select na página html

Question: Preciso saber o que o usuário escolheu dentro de um <select>.
No código abaixo eu preciso saber qual o código da coleta escolhida pelo usuário, para assim mostrar os itens que ainda não foram coletados.

Nº da Coleta

<?php
      echo ("<select name=\"colCodigo\">");

      $coletas = new Coletas();
      $coletas = $coletas->distinct();

      foreach ($coletas as $c)
      {
          $cod = $c["colCodigo"];

          echo ("<option>$cod</option>");
      }
      echo ("</select>");
?>

Comment: Nesse código nenhuma parte serve para saber qual o escolhido.
Comment: Você precisa colocar um `value` no seu `option`
Answer: Supondo que sua tabela tenha um id para cada coleta, seu código deveria ficar assim:

Nº da Coleta

<?php
      echo ("<select name=\"colCodigo\">");

      $coletas = new Coletas();
      $coletas = $coletas->distinct();

      foreach ($coletas as $c)
      {
          $cod = $c["colCodigo"];

          echo ("<option value='".$c["id"]."'>$cod</option>");
      }
      echo ("</select>");
?>

Assim, quando seu formulário for enviado poderá pegar o value do select.
Supondo que seja enviado via POST poderá pegar assim: $valor=$_POST['colCodigo'];
Comment: Ou pode usar o próprio "cod": `echo ("$cod");`. Assim a variável `$valor` (no momento de ler o `$_POST`) já terá o valor original do atributo **colCodigo**.


Get Distinct Category Name From Class

Question: I  have a class with  following structure :-
  public class Gallery
{
         private string _category;
            public string Category
                {
                    get
                    {
                        return _category;
                    }
                    set
                    {
                        _category = value;
                    }
                }
        }

I created a list object like this :-  List<Gallery> GalleryList = new List<Gallery>();
I have added items to this list  object from sharepoint list. Now I need distinct category name from this list object. I tried  GalleryList.Distinct() . But I am getting error. Please help me if anyone knows the answer.
Comment: "I am getting error" doesn't give us any information...
Comment: please also state the error so others might have more chance in helping you.. - wow, hi Master Jon..
Comment: I tried '  List DistinctCategory = GalleryList.Select(x => x.Category).Distinct().ToList(); ' and it isworking. Thanks.
Comment: I missed using system.Linq. That was the issue.
Answer: If you just need the category names, you need to project from the list of galleries to a sequence of category names - and then Distinct will work:
// Variable name changed to match C# conventions
List<Gallery> galleryList = ...;
IEnumerable<string> distinctCategories = galleryList.Select(x => x.Category)
                                                    .Distinct();

If you want a List<string>, just add a call to ToList at the end.
You'll need a using directive of:
using System.Linq;

as well.
Note that calling galleryList.Distinct() itself should compile (if you have the using directive) but it will just be comparing objects by reference as you haven't overridden Equals/GetHashCode.
If you actually need a collection of galleries, all of which have distinct categories, then you can use MoreLINQ which has a DistinctBy method:
IEnumerable<Gallery> distinct = galleryList.DistinctBy(x => x.Category);

In that case you'd need a using directive for the MoreLinq namespace.
You should also learn about automatically implemented properties. Your Gallery class can be written a lot more concisely as:
public class Gallery
{
    public string Category { get; set; }
}

Answer: GalleryList.DistinctBy(x => x._category);

Comment: On its own, that won't compile - `DistinctBy` isn't part of LINQ. It's part of MoreLINQ and I dare say some other libraries, but you haven't mentioned anything like that.

Get Distinct Category Name From Class


PHP version Check

Question: So I'm basically trying to create a tool that used across platforms, including sometimes legacy php version.
I don't plan on supporting anything less than 5.4 so I'd like to use something like below; however, instead of the application dying, I get various syntax errors. One of the first to start alerting is using brackets to define arrays.
Is there anyway to get around this?
if (version_compare(phpversion(), '5.4', '<')) {
    die('This tool does not support anything < PHP 5.4
Your PHP version is: '.phpversion() );
}

$array= ['a','b','c'];

Comment: PHP checks the script syntax before running any of it. So if you use new syntax, it will never get to the `version_compare()`. You have to stick to old syntax.
Comment: Possible duplicate of [How to get the PHP Version?](https://stackoverflow.com/questions/2113955/how-to-get-the-php-version)
Comment: @Seblor He already knows how to get the version, don't you see the code?
Comment: @Barmar I may have skipped it, I read the question before the edit. My bad.
Answer: The file you are doing a version_check for should simply not use any newer PHP features or include any files that do. If you want the version_check to work on PHP 4, it can only use PHP 4 features.
Comment: It can call newer functions, it just has to limit itself to legacy syntax. The version check will work as long as the syntax is valid.
Comment: Thanks Barmar, this was is what I was afraid of.   The brackets would by far be the easiest thing to address.

PHP version Check


Is $(1-L)Y_t=\epsilon_t \to Y_t=(1-L)^{-1} \epsilon_t$ mathematically correct?

Question: Consider an AR(1) model with coefficient $\rho =1$, i.e. a random walk, $Y_t=Y_{t-1}+\epsilon_t$. We usually say that since the AR polynomial has a unit root, it cannot be inverted and therefore the AR(1) cannot be written as an MA($\infty$).
Putting this into numbers, my understanding is that if we rewrite the model using the lag operator,
$(1-L)Y_t=\epsilon_t \to Y_t=(1-L)^{-1} \epsilon_t$,
then the second expression is not defined, since $(1-L)^{-1}$ does not exist. However, Hayashi (2000, p.372) does actually define this as
$ (1-L)^{-1}=1+L+L^2+L^3+...$
Hence I understand my original question is actually mathematically correct. But then:
1) Are all lag polynomials invertible?
2) Why do we refer to a stationary AR(1) as having an invertible AR polynomial and to a non-stationary AR(1) as having a non-invertible AR polynomial?
Answer: Regarding your questions:
1.) No, only stationary time series have invertible AR polynomials, and
2.) the AR(1) model is stationary iff the polynomial $\phi(z) = 1-\phi z$ doesn't have a root equal to plus or minus $1$. For higher-order AR(p) models, with $p > 1$, this $z$ can be a complex number. But in the case of an AR(1), this condition is the same as $\phi$ not being equal to plus or minus $1$. As long as this isn't true, there exists a $\delta > 0$ such that $\frac{1}{\phi(z)} = \sum_{j=-\infty}^{\infty} \phi^j z^j$ for all $1 - \delta < |z| < 1+\delta$, and
$$
\sum_{j=-\infty}^{\infty} |\phi|^j < \infty \tag{*}.
$$
This condition is called absolute summability, and it is needed to even define linear processes.
Why? Intuitively, you can see that if $\phi = \pm 1$, then the above sum wouldn't be finite, and it doesn't make sense to write
$$
\lim_{n \to \infty} X_t^n = \lim_{n \to \infty}\sum_{j=-n}^{n} \phi^j \epsilon_{t-j} = \sum_{j=-\infty}^{\infty} \phi^j \epsilon_{t-j}.
$$
The limit would not exist in either the mean square sense or the almost-surely sense.
Comment: Hi Taylor, thank you for your answer. Just to clarify: given 1.) and 2.), how can I reconcile that with my reference to Hayashi (and with the title of my question), i.e. with a unit root $(1-\phi L)^{-1}=(1-L)^{-1}=1+L+L^2+...$ (the polynomial is inverted even though the series is not stationary)?
Comment: @econ86 I can't say with any certainty because I haven't read the paper. If he/she didn't assume stationarity and defined that anyway, then he/she made a mistake, because you need stationarity to define that. If there's a unit root, you can difference your data, though. That's the "I" in "ARIMA."
Answer: There is a lot of information missing, e.g. no-one will know what your variables are.
In general, with $\rho=1$, you have to ensure that the operator $L$ has no eigenvalue of 1. Otherwise the sequence on the left hand side does not converge in the direction of that eigenvector/eigenfunction.
Comment: I reframed the question, hope it is now understandable.
Comment: Hi: In that particular case, you can invert it that way because the difference is stationary. But  a ( truly ) non-stationary AR(1) can't be inverted for greater than 1 AR(1) coefficient . you happened to use the example of a random walk which, when differenced, is not explosive so it can be written as an infinite sum of epslon's. ( but that's not really an MA).
Comment: well, it's an MA but it's an MA where all the coefficients are (1)  so really non stationary itself in that the errors are all permanent. Usually, the MA has transitory error terms that die out in the long run.
Comment: mlofton: so you are saying that an AR(1) with rho=1 is nonstat and its AR polynomial can be inverted; AR(1) with rho>1 is nonstat and its AR polynomial cannot be inverted. Is that correct? Then 1/(1-rhoL) in the latter case is not defined?
Comment: Hi: $Y_t = Y_{t-1} + \epsilon_{t}$ isn't really an AR(1). It's more correct to say that the first difference is white noise. This pseudo- "AR(1)" is not stationary nor is it really AR(1) because it has a unit root. By unit root, I just mean that the AR(1) coefficient equals one and for the AR(1) model to be stationary, the absolute value of the AR(1) coefficient should really be strictly less than one. I think this is what Taylor is saying also.


How to send mail using exim4 via gmail smtp: how to enable SPF or DKIM without a domain?

Question: I would like to send mail from my debian box to my personal gmail account.
When I try to send emails, I receive an error from Google. This is what I can read in /var/log/exim4/mainlog:
2023-04-13 21:31:41 1pn2fV-0032Fu-IA <= firstname.lastname@example.com U=roberto P=local S=409
2023-04-13 21:31:41 1pn2fV-0032Fu-IA H=gmail-smtp-in.l.google.com [2a00:1450:4013:c03::1a] Network is unreachable
2023-04-13 21:31:42 1pn2fV-0032Fu-IA ** email@example.com R=dnslookup T=remote_smtp H=gmail-smtp-in.l.google.com [188.8.131.52] X=TLS1.3:ECDHE_X25519__ECDSA_SECP256R1_SHA256__AES_256_GCM:256 CV=yes DN="CN=mx.google.com": SMTP error from remote mail server after pipelined end of data: 550-5.7.26 This mail is unauthenticated, which poses a security risk to the\n550-5.7.26 sender and Gmail users, and has been blocked. The sender must\n550-5.7.26 authenticate with at least one of SPF or DKIM. For this message,\n550-5.7.26 DKIM checks did not pass and SPF check for [pioneer.zar.it] did not\n550-5.7.26 pass with ip: [188.8.131.52]. The sender should visit\n550-5.7.26  https://support.google.com/mail/answer/81126#authentication for\n550 5.7.26 instructions on setting up authentication. p5-20020aa7d305000000b005066ca2f63fsi2195148edq.197 - gsmtp
2023-04-13 21:31:42 1pn2fW-0032Fy-P6 <= <> R=1pn2fV-0032Fu-IA U=Debian-exim P=local S=2980
2023-04-13 21:31:42 1pn2fV-0032Fu-IA Completed
2023-04-13 21:31:42 1pn2fW-0032Fy-P6 => roberto <email@example.com> R=local_user T=mail_spool
2023-04-13 21:31:42 1pn2fW-0032Fy-P6 Completed

The "pioneer.zar.it" domain is a local unregistered domain. How can I set SPF or DKIM if that domain doesn't exist?
My OS is Debian 11, and my update-exim4.conf.conf is:
dc_eximconfig_configtype='internet'
dc_other_hostnames='pioneer.zar.it'
dc_local_interfaces='127.0.0.1 ; ::1'
dc_readhost=''
dc_relay_domains=''
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost='smtp.gmail.com::587'
CFILEMODE='644'
dc_use_split_config='false'
dc_hide_mailname='false'
dc_mailname_in_oh='true'
dc_localdelivery='mail_spool'

[edit] Thanks to @user1686, I found a solution: my system is sending mail as a smarthost, so I changed the first line in update-exim4.conf.conf as follows:
dc_eximconfig_configtype='smarthost'

Besides, I don't own the zar.it domain (I used it because I thought that it wasn't registered), so I changed the second line as follows:
dc_other_hostnames=''

And now I am able to send emails.
Answer:
The "pioneer.zar.it" domain is a local unregistered domain. How can I set SPF or DKIM if that domain doesn't exist?

"zar.it" is neither local, nor unregistered. In fact, it has been registered since 2000. Even the specific subdomain, "pioneer.zar.it", exists in public DNS and has one A record.

If you are the owner of the zar.it domain, you can add the SPF (TXT) records to it like you would any other record, even if there are no corresponding A/AAAA records.
There is no additional registration needed for subdomains of a registered domain, such as pioneer.zar.it if you already own zar.it – owning the domain automatically grants ownership of all its subdomains; the entire hierarchy is delegated to your nameservers.

If you are saying that you're trying to send mail with someone else's domain in "From:", then the rejection message is entirely expected – it means SPF is correctly doing its job by preventing you from sending spoofed messages. Use a different domain.
Like in the previous point, ownership of a domain automatically grants ownership of all of its subdomains, so if someone else already owns zar.it, then they own pioneer.zar.it and set its SPF/DMARC policies as well.

In addition to that, as you have configured your server to use Gmail as a "smarthost", sending mail through the "authenticated mail submission" port 465/587 (instead of the usual "servre-to-server mail exchange" port 25), it means Gmail doesn't consider your messages to be mail from an external site – they are treated as messages from your Gmail account back to yourself.
I believe Gmail's policies may disallow such messages regardless of SPF or DKIM – as long as you're sending from a specific Gmail account, you will likely be required to use that account as the "From:" address.
Comment: No, it probably won't. Remember that you're using Gmail as a "smarthost", therefore your server is sending mail _from your Gmail account_ back to the same account, so it needs to use your account's address as "From". It is not treated as "mail from an external domain" at all.
Comment: You would need to configure Exim to masquerade the entire sending address (not just the domain) with your smarthost account's address – probably [something like this](https://www.exim.org/exim-html-current/doc/html/spec_html/ch-address_rewriting.html). The system's "real" domain name won't matter as much if rewriting is performed, though try to avoid using someone else's domain regardless (use `.home.arpa` if you have nothing else).
Comment: `.home.arpa` is the only domain that's explicitly reserved for that purpose (it's like 192.168.x). `.local` is the domain used for mDNS, so although it's also private and people use it, using it for internal DNS may cause unexpected conflicts. A made-up domain that *doesn't* exist in global DNS is questionable. Making up a TLD used to be common but now with the amount of new TLDs it's also slightly risky (e.g. people using `.dev` started having problems when it became a real TLD). Can be done with care though, e.g. I use `.sym` (even though I have a global domain as well).
Comment: When it comes to mail specifically, you really only have *one* option: If you're setting up a standalone mail site, you **have to** use a real domain name (otherwise many systems will refuse to accept mail from you). Doesn't matter what the rest of the system uses, but the sent mail headers and envelope need to use a "From" that exists in the global DNS and *is under your control*. And when using a smarthost, it's even more specific: Exim with a smarthost is no different from e.g. Thunderbird, you have to send mail from the specific address (user@domain) that the smarthost server allows you.
Comment: Oh! I didn't chek, I am not the owner of that domain. I don't own a domain, I only want to send email from my little server to my gmail account. Will it be ok if I configure my server with a non-existent domain?
Comment: So how should I configure my system? Maybe a .local domain? And how could I solve the issue related to Gmail? In general, I would like to be able to send messages using Gmail smtp server, to my own address or even to other addresses.
Comment: Thank you. What about a `.local` domain? What are best practices for local domains?


$L^{2}$ spaces, bounding the measure of a set

Question: Let $f \in L^{2} ([0,1], \mathcal{A},\mu)$ where $\mu$ is the usual Lebesgue measure, such that $||f||_{2}=1$ and
$$
\int_{0}^{1} f d \mu \geq \alpha > 0
$$
Let $E_{\beta}= \{ x \in [0,1] | f(x) > \beta \}$.
Then, for every $\beta \in (0,\alpha)$
$$
\mu ( E_{\beta} ) \geq (\alpha-\beta)^{2}
$$
I had problems with this exercise. To be sincere, I don't know even where to start from. The only relevant inequality that I know is Chevyshev inequality but it bounds the measure of $E_{\beta}$ from above, not from below. I've tried to do some trick with integrals and charasteristic function to bound the $L^{2}$ norm of $\alpha-\beta$ from above with the $L^{2}$ norm of $\chi_{E_{\beta}}$, but I haven't succeded. My biggest concern is the lack of absolute values marks on the definition of $E_{\beta}$ which doesn't allow me to make the conclusion $x > y \Rightarrow x^{2} > y^{2}$.
Any hints?
Answer: You said that you didn't know where to start.
Let's start with what we know, namely $\alpha \leq \int_0^1 f \, d \mu$. We now want to connect this to the quantity $\mu(E_\beta)$ that we want to show something about. The most natural approach is to write
$$
\alpha \leq \int_0^1 f \, d\mu = \int_0^1 f \, 1_{E_\beta} \, d \mu + \int_0^1 f \, 1_{E_\beta^c} \, d\mu.
$$
Now, note that $f \leq \beta$ on $E_\beta^c$, which implies that $\int_0^1 f \, 1_{E_\beta^c} \, d \mu \leq \int_0^1 \beta \, 1_{E_\beta^c} \, d \mu \leq \beta$, since $\beta \geq 0$.
We have thus shown
$$
\alpha \leq \int_0^1 f \, 1_{E_\beta} \, d \mu + \beta.
$$
First try to figure out yourself how to proceed from here. If you don't see it after staring at the equation for ~10 minutes, look at the hint below.

 Hint: Cauchy-Schwarz inequality.

And here the full solution:

 Note that until now we did not use the fact that $\|f\|_2 = 1$. To make use of this estimate, we use the Cauchy-Schwarz inequality, which shows
 \begin{align*}\alpha \leq \beta + \int_0^1 f \, 1_{E_\beta} \, d \mu \leq \beta + \int_0^1 |f| \, 1_{E_\beta} \, d \mu \leq \beta + \sqrt{\int_0^1 |f|^2 \, d \mu} \sqrt{\int_0^1 1_{E_\beta} \, d \mu} = \beta + \sqrt{\mu(E_\beta)}. \end{align*} Rearranging this inequality will give you the desired estimate.


Por que usar somente return, sem retornar nenhum dado?

Question: Estudando o código de um framework me deparei com o seguinte trecho de código:
if (file_exists('lib/util/' . $className . '.php'))
{
     include 'lib/util/' . $className . '.php';
     return;
}

Qual o objetivo do uso do return sem ter nenhuma variável ou expressão para retornar? É possível fazer isso só no PHP ou em outras linguagens como Java também?
Comment: Não é duplicata, essa pergunta que você citou é sobre usar um ou vários `return` no corpo de um método. A minha é referente ao uso do `return` sem atributo para retornar.
Comment: Parece duplicata de [Por que devo usar apenas um "return" em cada função?](http://pt.stackoverflow.com/q/2477/28595)
Answer: Existem casos em que você só quer executar uma rotina, seguir em algoritmo, um procedimento, sem gerar resultados. Ele faz uma ação, mas não produz um valor para ser usado em uma expressão. Cada linguagem pode dar um nome e um jeito de tratar isto.
Isto é possível virtualmente em todas as linguagens. Algumas exigem que esse algoritmo tenha outro nome (procedure, por exemplo). Falo disso em Qual a diferença entre funções e procedimentos?.
Matematicamente falando uma função deve retornar algum valor. Muitas linguagens permitem que elas não retornem porque não há muita vantagem prática dar outro nome só porque não retorna um valor.
Em linguagens estaticamente tipadas o normal é definir uma convenção de retorno dependendo da sintaxe dela. Algumas exigem que o tipo seja void (Java, por exemplo) ou algum outro nome (unit anda na moda). Na verdade, esse não costuma ser um tipo de dado efetivamente.
Em linguagens de tipagem dinâmica é normal a função não ter um tipo, então retornar um valor ou não, para o compilador, dá na mesma. Claro que se retornar "nada" em função que se espera o retorno de um valor, será um erro lógico (que pode ser contornado).
Já vi vários casos da função ser confusa e começa retornando um valor de um tipo, depois há uma manutenção e ela cria um outro caminho de execução e retorna sem valor. Em linguagens dinâmicas (não todas) isso costuma ser possível já que retornar nada na verdade é retornar um nulo, o que não deixa de ser um valor (diferente de um void).
Em tese esses procedimentos não precisam de um comando return. Se existir, obviamente não deve retornar valor (ou pelo menos ele será descartado em linguagens estáticas). Claro que há casos que o procedimento precisa terminar antes da sua última linha. Um comando return é para controle de fluxo e é usado para terminar a execução imediatamente.
Algumas linguagens, mesmo em funções completas (que retornam valor), permitem que o return seja omitido para produzir um resultado. Mas é claro que o comando sempre será necessário se quiser interromper a execução antes do seu fim. Este é o objetivo primário de todo return, retornar um valor é apenas sua função secundária. A palavra "retorno" deve ser lida como "retorne ao local chamador" e não "retorne um valor". Exatamente por isso tem linguagem que até usa a variável Result como padrão para identificar o que deve ser usado como resultado no fim da função. Embora todo mundo compreenda "retornar um valor", o correto é "resulte um valor e retorne para o chamador".
Algumas linguagens permitem resultar mais de um valor (normalmente é um truque interno).
Aí do lado direito tem uma pergunta relacionada importante sobre o assunto.
Artigo na Wikipedia sobre o return. Sobre o tipo de retorno.
Coloquei no GitHub para referência futura.
Answer: É possível. Por exemplo a função de imprimir é uma função que não retorna nada, vai apenas executar a impressão (equivalente ao include no seu exemplo) e terminar.
Comment: Seria a mesma coisa que deixar sem? Ou em outras linguagens ser um método `void`?
Comment: Não posso falar de todas as linguagens. Mas as que eu conheço, nas que é preciso declarar o tipo de variável que vai ser returnada, sim é `void`


Named parameters functions in Clojure

Question: This code discussing named arguments in Clojure from "The Joy of Clojure":
(defn slope [& {:keys [p1 p2] :or {p1 [0 0] p2 [1 1]}}]
   (float (/ (- (p2 1) (p1 1))
             (- (p2 0) (p1 0)))))

(slope :p1 [4 15] :p2 [3 21])

The function itself, I understand it -no problem with destructuring- but I don't understand the calling.
Are we passing four arguments to slope? how vectors are getting assigned to :p1 and :p2?
Answer: You are passing four arguments to slope, yes. The [] part of slope specifies the parameters, in which & means "slurp all additional parameters into this form", which then specifies that it is looking for arguments that form a map with keys p1 and p2 (and gives default values if either doesn't exist).
Comment: I got that but when calling: (slope :p1 [4 15] :p2 [3 21])  how p1 gets the value [4 15] and p2 [3 21] ?
Comment: `p1` got the value `[4 15]` because the arguments `:p1 [4 15] :p2 [3 21]` are treated as a map, and the parameter block in `slope` says to bind the variables `p1` and `p2` to their corresponding values in that map.

Named parameters functions in Clojure


Erro na comparação entre um EditText e um String

Question: Estou tentando comparar o texto inserido em uma EditText com um item da minha ArrayList, porém a condição nunca é verdadeira.
int aux=-1;

for (int i = 0; i < lista2.size(); i++) {
    if (edContato.getText().equals(lista2.get(i))){
        aux = i;
        break;
    }
}

if (rbExcluir.isChecked()) {
    if(aux>=0){
        principal();
        lista2.remove(aux);
        aplicarLista();
    }
    else {
        dialogo.setTitle("Erro!");
        dialogo.setMessage("Contato não encontrado!");
        dialogo.setNeutralButton("OK", null);
        dialogo.show();
        excluir_alterar();
    }

Sou iniciante em programação para Android e até onde eu sei, no Java essa comparação funcionaria. Estou deixando alguma coisa passar? Essa situação requer algum outro método de comparação?
Answer: Você está a comparar um Editable com um String.
O objecto retornado pelo método EditText#getText() é do tipo Editable.
Para obter a string no EditText tem de usar o método toString() do Editable.
Em vez de
edContato.getText().equals(lista2.get(i))

use
edContato.getText().toString().equals(lista2.get(i))

Comment: Tentei isso e não funcionou. Ele continua não entrando na condição.
Comment: Então é porque a lista2 não tem nenhum item igual ao conteúdo do EditText.
Comment: Eu coloquei no meio do código um AlertDialog que me retorna os dois valores, apenas para fins de teste, e os dois conteúdos são aparentemente idênticos. Tentei até converter tanto o EditText quanto o item da lista para string e ainda assim a condição continua falsa.
Comment: De que tipo é o ArrayList?
Comment: Não defini um tipo ao declarar o ArrayList. Estou fazendo o seguinte: tenho um ListView (lista) para mostrar os dados inseridos no ArrayList (lista2) com o auxílio de um ArrayAdapter (adp) do tipo String. Seria essa a sua pergunta?
Comment: Que tipo de objecto está a guardar no ArrayList? São Strings?
Comment: Eu pego o conteúdo de um EditText e adiciono no ArrayList:

lista2.add(editText1.getText());
Comment: Encontrei o erro! Converti o conteúdo do EditText para String antes de adicionar à lista e agora estou conseguindo remover os itens. Obrigado pela ajuda!
Comment: Sempre que declarar um ArrayList indique o tipo que ele vai receber: `ArrayList lista2;`. Se o tivesse feito o compilador teria avisado que havia um erro quando você usou `lista2.add(editText1.getText());`