Nginx and 1000 WordPress Installs - Optimization

Question: I'm trying to create a rather unusual (imo) configuration where I have:

nginx
php-fastcgi
mysql
1000 seperate WordPress installs (with WP Super Cache). Each WP install corresponds to a separate subdomain.

Furthermore, I have 1000 cron jobs being called every hour that in turn call a WP plugin (using wget) which retrieves data from an API and posts it to the respective blog.
This is all being run on a virtual server with 1024MB of RAM, 4 shared processors, etc. The server is not doing well, especially during the times that the cron jobs are being executed. Nginx constantly throws 504 errors and the site has a significant lag.

Am I crazy for having 1000 individual WP installs? Should I be using WP-MU and will this help significantly? (I have certain plugin restrictions that I prefer having seperate installs but could switch if need be.)
Instead of having 1000 unique cron jobs - should be calling say a bash script that will then process the 1000 HTTP requests I need? Could this be done in a succesive order instead of a sequential one?
Any other kind of suggestion you may have for optimization? Should I be proxying to Apache instead of just using nginx, etc. Any kind of advice would be appreciated.

Thanks in advance
Update:
Thanks a lot for your response. I'm going to switch to WP-MU and re-do the cron jobs. I'm currently using spawn-fcgi but will switch to php-fpm. Appreciate the advice
Answer: 1) 1000 unique installs will remove any benefit that caching can provide you.  Ideally you would run one install (which would be cached in memory via APC or similar), with a bunch of different databases.  WP-SuperCache might help with your caching issues though, as it should render everything to static HTML files.  Basically, you want to remove as much dynamic content as you can from each page.
2) Running all 1000 jobs sequentially is probably a bad idea (are you sure 1000 requests can complete in an hour?).  At the same time, running 1000 jobs in parallel is also a bad idea (Can your web server withstand 1000/reqs/sec?).  I'd suggest something in the middle.  Perhaps you start 10 processes, and each does 100 blogs with a random delay between them.
3) If you can use pure nginx + php-fastcgi, stick with it.  Apache is not going to help you in any way.
Are you using php-fastcgi (ex: spawn-fcgi) or php-fpm?  php-fpm would be my suggestion, as you can set it up to spawn more processes when the load is higher.
Answer: All good advice there from devicenull. I'm in a similar position for a client, having many installs of the same software. Xcache (similar to APC) greatly improved performance but I had to give 4gbs of memory to cache.
With WP-Super-Cache the vast majority of your web requests should be for pure HTML/images which are very fast. Are you sure its not your 1000 cronjobs that are causing the general site delays? I would think they'd take most of the hour to execute!


Finding posterior mean, median and mode

Question: Consider the probability, $\theta$, that a randomly selected person in NYC is from Manhattan. We collect data as we walk down Times Square. We ask three people whether they are from Manhattan, and all three respond with yes.
Assuming a flat prior for $\theta$,
a) Find the posterior distribution of $\theta$, conditional on observed data. Also find the mean and mode of $\theta$, while also deriving an expression for median of $\theta$ as well.
b) Find the predictive distribution that a randomly selected fourth person is also from Manhattan.
By flat prior does it mean that in this case, since it's a yes or no question, I am to assume that the probability of a yes on any given answer is 0.5? And if this is the case, how would the normal situation, where we have posterior $\propto$ likelihood $\times$ prior apply in this case?
Would really appreciate detailed help for the other parts as well. Thanks in advance!
Answer: I doubt that sampling in Times Square will give unbiased information about New York City as a whole, but ignoring that:

A flat prior is one with a constant density, here on the interval $[0,1]$, so your prior is $\pi_0(\theta)=1$ for $0 \le \theta \le 1$
The likelihood here is proportional to the conditional probability that all three would say yes, which is $\theta^3$
So the posterior distribution is proportional to the product of these, i.e. also proportional to $\theta^3$ in $[0,1]$

I will leave it to you to find the constant of proportionality, mean, mode, median etc.
Comment: I will find the mean, median and mode, but would it be possible give me some direction for the constant of proportionality?
Comment: @MatthijsBjornlund  You want the posterior density to give probabilities, so if it is $k \theta^3$ on $[0,1]$ then you want $\int\limits_0^1 k \theta^3\, d\theta = 1$
Comment: Thus, $k=4$. That really simplifies things. However, while the mean and median are easy enough, what would the median look like for this case? Since it is the "mid-point" of the distribution, would it just be $$\int_0^{0.5) 4\theta^3 = 0.5^4 = 0.0625?$$ That seems smaller than it should be.
Comment: @MatthijsBjornlund The median would be the value of $m$ for which  $\int\limits_0^m 4 \theta^3\, d\theta = \frac12$ and also $\int\limits_m^1 4 \theta^3\, d\theta = \frac12$

Finding posterior mean, median and mode


How to get ride of positioning in mobile version of css

Question: I am making Responsive site. I have seen that absolute positioning has been used in some elements. How can i get rid of position in mobile version of coding declaring Media Queries.
Such as : For getting ride of float we use float:none in mobile version of Media Queries.
In this way how can i get ride of absolute and relative position using css.
Answer: position: static;

This is the default, "normal" position for elements.
MDN reference


Android architecture components paging DataSource.Factory error

Question: I'm trying to make my DataSource.Factory class, but I get an error when trying to return my PageKeyedDataSource implementation.
class SubredditPageKeyedDataSource(private val service: LedditService,
                               private val subredditName: String): PageKeyedDataSource<String, Children<DataX>>() {

@SuppressLint("CheckResult")
override fun loadInitial(params: LoadInitialParams<String>, callback: LoadInitialCallback<String, Children<DataX>>) {
    service.getSubredditTopics(subredditName).subscribe { result -> callback.onResult(result.data.children, result.data.before, result.data.after) }
}

@SuppressLint("CheckResult")
override fun loadAfter(params: LoadParams<String>, callback: LoadCallback<String, Children<DataX>>) {
    service.getSubredditTopicsAfter(subredditName, after = params.key).subscribe {result -> callback.onResult(result.data.children, result.data.after)}
}

override fun loadBefore(params: LoadParams<String>, callback: LoadCallback<String, Children<DataX>>) {
    // ignored, since we only ever append to our initial load
}

}
Now heres my factory:
class SubredditDataSourceFactory(private val service: LedditService,
                             private val subredditName: String): DataSource.Factory<String, List<Children<DataX>>>() {

override fun create(): DataSource<String, List<Children<DataX>>> {
    return SubredditPageKeyedDataSource(service, subredditName)
    }
}

When returning my DataSource in the above create() method, AndroidStudio gives me an IDE error:
Type mismatch.
Required: DataSource<String, List<Children<DataX>>>
Found: SubredditPageKeyedDataSource

Am I going insane? PageKeyedDataSource extends from ContiguousDataSource which is a DataSource. Why am I getting a type mismatch? I've checked 2 different examples of the paging library and their implementation is exactly like mine. Unless I missed something???
Answer: The types don't actually match.
Your factory is for:
PageKeyedDataSource<String, List<Children<DataX>>>

But your datasource implements the type:
PageKeyedDataSource<String, Children<DataX>>

Notice that one has a list of children on the right side, the other a single child.
The one without the List<> should be correct, try removing that part from your code.
Comment: Thanks, knew It was probably some sort of oversight on my part.


ReportViewer crashes because of Microsoft.ReportingServices.Rendering.RichText.CachedFont GetFont

Question: I have a simple WinForms app with ReportViewer control. Most of time it works okay but sometimes displays unrecoverable red cross mark in ReportViewer window or crashes when I scroll through report. I can't figure any factors that cause this behavior but it appears completely random. I hooked an exception catcher and that's what I've got:
Exception.GetType().Name: NullReferenceException
Exception.Message: Object reference not set to an instance of an object.
Exception.TargetSite Microsoft.ReportingServices.Rendering.RichText.CachedFont GetFont(Microsoft.ReportingServices.Rendering.RichText.ITextRunProps, Byte, Boolean)
Has anyone happen to encounter this problem? Any ways to work this around?
Answer: Ok, found it.
The crashes were caused by inline translation software ABBYY Linvgo, which reads words under mouse cursor and displays translation in a tooltip. Looks like it attempted to mess with ReportViewer's memory space or something which caused access violation and subsequent crash.
After I closed this soft the stability of ReportViewer improved drastically.
So you may consider closing any sassy soft if you experience similar problems.


Not allow Korean character(Hangul) for input text

Question: I want to allow typing Latin Characters but I don't want user can type Korean Hangul characters.
Please help me answer. Thank you in advance.
Comment: Why do you need to restrict the text to Latin Characters only?
Comment: This is the table of Unicode ranges of the basic multilingual plane: https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane . If you want to restrict only Korean (and not Chinese, Japanese, Indonesian, etc.), you need to match any character in the Hangul ranges (there are 5 of them).
Answer: Based on this article,
https://en.wikipedia.org/wiki/Korean_language_and_computers
You would want to do something like this (untested):
<code>$(document).on('keypress', 'input', function (e) {
    var key = event.which || event.keyCode;

    // Hangul Syllables
    if (key >= 0xAC00 && key <= 0xD7A3) {
        e.preventDefault();
    }

    // Hangul Jamo
    if (key >= 0x1100 && key <= 0x11FF) {
        e.preventDefault();
    }

    // Hangul Compatibility Jamo
    if (key >= 0x3130 && key <= 0x318F) {
        e.preventDefault();
    }

    // Hangul Jamo Extended-A
    if (key >= 0xA960 && key <= 0xA97F) {
        e.preventDefault();
    }

    // Hangul Jamo Extended-B
    if (key >= 0xD7B0 && key <= 0xD7FF) {
        e.preventDefault();
    }
});
</code>
However, this would not stop anyone from copying/pasting Hangul characters into the input field, you would need to find something separate for that.
A more simplified way is to use form validation (this is a more simplified approach):
<code><input type="text" pattern="[^가-힣]+">
</code>
What you should do is instead be testing for the characters on the server side and returning a form error.
Comment: $("#TLPHN").on("keypress keyup blur",function (event) {
  var val = $(this).val();
    if(/[\u3131-\uD79D]/gi.test(val)){ //  /[^\u0000-\u007F]/gi : unicode chars, /[\u3131-\uD79D]/gi : kor chars
     $(this).val(val.replace(/[\u3131-\uD79D]/gi, ""));
    }
 });


Bias-Variance decomposition for non-squared loss

Question: While the Bias-Variance decomposition of the squared loss is part of any introductory ML class, I am curious to know if similar decompositions can be done for other loss functions, e.g., cross entropy?
Comment: A near-duplicate:  https://stats.stackexchange.com/questions/192286/bias-variance-decomposition  See through the list https://stats.stackexchange.com/search?q=bias+varian*+decompo*+answers%3A1
Comment: Do the following search in google scholar: "bias-variance tradeoff for general loss function" (without the quotes). Many very relevant hits
Answer: These two papers might be relevant:

Shivaswamy, et al, Bias-Variance Decomposition for Ranking, WSDM 2021
Yang, et al, Rethinking Bias-Variance Trade-off for Generalization of Neural Networks, PMLR 2020

The latter states some result for binary cross entropy.


Gaps between numbers of the form $pq$

Question: Mathematicians keep improving Zhang's bound on gaps between primes. According to Wikipedia, there are infinitely many pairs of primes such that their difference is no more than 246. This is all very exciting.
What does it tell us about gaps between products of two distinct primes? Can we say that there are infinitely many pairs of numbers of the form $pq$, for distinct primes $p$ and $q$, such that their difference is less than some $K$? To be clear, I mean pairs of numbers $(a,b)$, where $a=p_1q_1$ and $b=p_2q_2$, where $p_i\neq q_i$, but it's okay if $p_i=q_j$, or $p_i=p_j$ when $i\neq j$.
Thanks in advance for any insights on this.
Answer: Goldston, Graham, Pintz, and Yildirim showed that one can take $K=6$ in your statement! (another link) Indeed they could show this even before Zhang's breakthrough.
Comment: Thank you! This is great. Now I'm thinking of a follow-up question, on upper bounds for gaps between these numbers, but I'll ask that separately.
Comment: I think you'll find information about that via a Google (or, better yet, MathSciNet) search.

Gaps between numbers of the form $pq$


How to serialize empty arrays when converting to XML with Json.Net

Question: I need to convert some Json to XML but when I do it removes all empty arrays/list/collections/etc...
How can I get it to include the arrays as empty items?
Example Json:
{
  "EmptyCollection": [],
  "OtherPorperty\": "TestValue"
}

C# Code:
var jsonString = "{ \"EmptyCollection\": [], \"OtherPorperty\":\"TestValue\" }";

var xmlDoc = JsonConvert.DeserializeXmlNode(jsonString, "root", true);
Console.WriteLine(xmlDoc.InnerXml);

Actual result is
<root>
  <OtherPorperty>TestValue</OtherPorperty>
</root>

Desired result is
<root>
  <EmptyCollection></EmptyCollection>
  <OtherPorperty>TestValue</OtherPorperty>
</root>

or

<root>
  <EmptyCollection />
  <OtherPorperty>TestValue</OtherPorperty>
</root>

Using the writeArrayAtribute doesn't seem to work.
Answer: I believe there is a problem with the meaning. Personally I believe that the conversion done by the Json library is fine as it is and you can't get one of the two results proposed by you.
The Tag  in every scenario proposed doesn't mean ( from XML point of view ) that it is an empty array. But it means that the property (not an array ) EmptyCollection is empty. You will lose something.
I suggest you to test for the absence of the tag as "no information" a.k.a "no entry in the array"
Comment: An empty element and empty collection are not strictly the same but it is a closer conversion than current. Currently it is lossy. I need to be able to convert it back but it is not possible as it states the field is required and is missing.
Comment: If you need the field one common approach should be define a null element. In many algorithms, like in a red-black tree, the leaf isn't a node with two null pointers but a node with null value.

So instead having something like:

You can try to obtain:
null
or

(just as example)

Probably you need to use as source a Json like:
{ Collection:[ { myelem: null } ] }

Hope this helps.
Comment: I have a large object graph that I am serializing and I don't really want to check all the collections and add null items to them and remove them again later.
Comment: One chance is to add the null element as last one in every case. ( Like in a C-String ). So your "JSON array / XML tag" is everytime filled with something and is easy to detect or skip


When was the beginning of polyphony?

Question: I've read a lot about Greek and ancient music. The history books say this music was only monophonic and we know only from iconical research (studying pictures from ancient times) of the practice of the ancient period.
My assumption is that the music was rarely notated and if it was, then only monophonically, but when it was played it must have been polyphonic.
Is there any evidence in historical literature or are there other theories of other researchers that support my hypothesis?
Edit:
I assume that there were more different instruments playing at once  and not unisono.
e.g. Nebukadnezar or the battle of Jericho. Maybe I have to overthink my understanding of polyphony. I thought monophonic implies all instrument or voicing are playing the same tune ... what in my imagination was almost impossible. I would imagine that one or more singer have been accompanied by a harp or a lyra in chords (eventually fourths and not triads and also there could have been happenings with improvisation in a poly rhythmic and hetero-phonic art and kind.
Comment: Why would you assume that it was performed polyphonically?  Do you suppose that there were ensembles performing but for some reason nobody ever depicted that?
Comment: Are you asking specifically whether polyphony was used in Ancient Greek music? Because the standard answer to the title question is that true polyphony (as opposed to simple bourdon and organum) arose in Europe at the end of 10th century.
Comment: I  (like the others here) don't know anything much about details of polyphony-*history.* But speaking in terms of archetypes, I feel polyphony is deeply, essentially Christian (just as the tanpura is fundamentally Hindu) So I'd search more along christian lines than musical lines.
Comment: @phoog: I'll modify my question as the comment will get too long
Comment: I infer from your "when it was played it must have been polyphonic" statement that you think it's likely that more than one person took part in the performance (singing together, say). Maybe you're right. But even though "polyphonic" means "multiple voices" (or something like that), I don't think it strictly refers to whether (say) there are multiple human voices performing. An ensemble of people singing a unison melody is monophonic, because the music itself has a single "voice". Adding a counter-melody would make it polyphonic. See https://music.stackexchange.com/a/22284/24580
Comment: @phoog, yes, this was exactly my assumption, but as in my revised question maybe polyphony is only referring to the upcoming voice leading like the link of mlibby and Caleb are describing.
Comment: @Rusi: I would have answered to you that most typical in early Christian music was that there were no instruments and no other voices. But now I've found that I had probably a different concept of polyphony from the others here! What I was thinking of is called **heterophony.** The differentiation is obviously the same as in other areas like in partnerships.) So I would agree that the begin of polyphony was in the church music in the aera of notre-dame. That's what all harmony teachers are saying (if we don't count the primitive forms like bordun and organum).
Comment: wasn't it Alexander Bell?
Answer: The oldest treatise describing polyphonic music in the European tradition is Musica Enchiriadis from the ninth century. It describes the practice of singing organum in a way that is surprisingly easy to grasp for us, modern musicians:

How ancient the practice was at that point is difficult to say. Iconography in itself cannot establish whether a certain musical practice is polyphonic or not: in two photos of an (Arab) Andalusian orchestra and a gamelan ensemble respectively one sees many musicians playing together. Only one of them shows music being played that we would call "polyphonic"
Comment: Deducing "there was no polyphonic music" from "we don't have any polyphonic notation" is, of course, plainly wrong. But concluding that there was polyphonic music from e.g. depictions of  people playing in groups, of even using instruments like the double [aulos](https://en.wikipedia.org/wiki/Aulos) is problematic as well, in my opinion. I would say: we just don't know.
Comment: @ Hans:his picture I know well too. My question means: if we don't have found notation of more than one voices  as there was no notation possible or usual ... is it logical to deduce that there didn't exist any polyphony or more than one voices in the "common practice" of ancient music?
Comment: "*concluding that there was polyphonic music from depictions of people playing in groups, of even using instruments like the double aulos is problematic as well* that's what I've done. As I thought it would have been rather more difficult to play in unisono than each player in his own way e.g. imitating or responding.  But as I've written in my answer this art of music is not  counted as polyphonic but it is called heterophony.
Answer: I've found today this youtube video:

May be this would give an answer. Maybe this all is only speculation.

The history books say this music was only monophonic

Edit:
What I've meant in my question obviously is called heterophony
(I have to admit I've never heard this term before. But this is a good concept to differentiate between the music of ancient cultures and what is called polyphony in music in the ars nova aera.
heterophony: two or more instruments or singers playing/singing the same melody, but with each performer slightly varying the rhythm or speed of the melody or adding different ornaments to the melody. Two bluegrass fiddlers playing the same traditional fiddle tune together will typically each vary the melody a bit and each add different ornaments.: two or more instruments or singers playing/singing the same melody, but with each performer slightly varying the rhythm or speed of the melody or adding different ornaments to the melody. Two bluegrass fiddlers playing the same traditional fiddle tune together will typically each vary the melody a bit and each add different ornaments
https://en.wikipedia.org/wiki/Music
So it seems to me that begin of polyphony might presuppose a system of notation for different voices and this is the period we've already known.
Homophony? Heterophony or Polyphony?
You'll find more information in this link ...
http://theconversation.com/ancient-greek-music-now-we-finally-know-what-it-sounded-like-99895
Comment: _What I've meant in my question obviously is called heterophony_ : please edit your question then, because now your answer, however interesting,  is not an answer to the original question!
Comment: No, I didn't mean at that point  "heterophony" as I didn't know the term. How could other users with a similar question  find an answer when they are wondering whether polyphony existed in the Greek era?
Answer: Well, it's controversial, but some scholars have claimed that the Hurrian notation from about 1400 BCE represents polyphony.  See Anne Kilmer's article.  While some scholars have agreed and viewed this as possibly the first notated polyphony (notably including Richard Taruskin in his Oxford History of Western Music), many other possible interpretations of the Hurrian notation exist.  Martin West critiques many of these interpretations, including Kilmer's, but nobody really knows the proper way to decipher this notation (they're just speculating, often based on the assumption that polyphony simply didn't exist in ancient times, with no evidence, so the notation supposedly couldn't possibly mean that?), so it could very well be a polyphonic work.
Answer: Gerhard Nestler writes inhis HISTORY OF MUSIC (1962, 4. ed. 1990)

Two appearances determine the sound of the music of England, the third and the Durtonalität.  Probably people in England used to sing more vocally before than elsewhere.  The earliest news of polyphonic singing comes from a bishop Aldheim, who lived 640-709.  Giraldus Cambrensis describes a popular polyphonic singing in northern England in his "Descriptio Cambriae" around 1200. The first written example is a two-part hymn to St. Magnus from the end of the 13th century.  But the deciding factor is that the main interval of this English two-part singing is the third.  We ask in astonishment how the third is?  We know that in the scale formation according to the fifth-principle of Pythagoras the third had to be regarded as an imperfect consonance, since the Pythagorean third has a difference of 81/80 to the mathematically pure third.

(translated by Google)
It is to say that polyphonic is the translation of mehrstimmig. I don't know whether this also includes organum and fauxbourdon. But right now I have found another information - the reason for this 2. answer:
The earliest known practical example of polyphonic music - a piece of choral music written for more than one part - has been found in a British Library manuscript in London.
link
Dec. 2014

Varelli's research suggests that the author of the newly-found piece – a short "antiphon" with a second voice providing a vocal accompaniment – was writing around the year 900.
Comment: "We know that in the scale formation according to the fifth-principle of Pythagoras the third had to be regarded as an imperfect consonance, since the Pythagorean third has a difference of 81/80 to the mathematically pure third": that's only true for fixed pitch instruments.  It's entirely likely that two people singing thirds would adjust the tuning so the thirds would be pure.
Comment: @phoog - The third was considered too dissonant for the ending a piece until much later than one would expect, and according to various text-books this changed only with the arrival of the' consonance Angloise'.
Comment: @PeterJ My suspicion is that the third was considered dissonant because it was dissonant on the keyboard.  I find it hard to believe that singers would not very quickly discover the narrower acoustically pure interval naturally when singing without other instruments.  Out of curiosity, what do you mean by "one would expect" or by "much later" than that?  Josquin's famous Ave Maria has been cited as a piece that implies Pythagorean tuning, and it indeed ends with an open fifth.  But his *Missa Hercules dux Ferrariae* has final chords with thirds in them.
Comment: @phoog - I suspect that the thrid was considered unstable rather than dissonant, and this would apply regardless of tuning. . .
Comment: @PeterJ I only used the term "dissonant" because you did. You haven't answered my question about "much later than one would expect."  When would you expect thirds to have been considered appropriate for ending a piece, and when did they actually start being used in that context?
Comment: @phoog - I remember being surprised to learn that the consonance angloise was a new thing in the fifteenth century. I assumed the third had always been a consonant (or stable) interval. As this was vocal music I doubt its late arrival  had anything to with tuning.  .

When was the beginning of polyphony?


OpenSL ES precise start of playback

Question: I am working on an Android app that uses OpenSL ES for audio input/output. However, I've been struggling to come up with a solution that would enable to start playback at a precisely given time (e.g. I want to start playing in exactly 3.2 seconds from now on). Is this even possible?
Answer: I finally solved the issue by allocating a larger buffer that I am filling with zeros in the beginning according to sample rate. Seems to work well.

OpenSL ES precise start of playback


Setup fail2ban with apf

Question: Along with BFD we have recently installed fail2ban on our server, it is CentOS and it uses APF to block IPs.
I have hunted online on how to get the two to work however when an IP is blocked by fail2ban it doesn't show up in APF.
I have manually changed the actionban in iptables-multiport.conf to point to apd instead of iptables but it still doesn't work.
jail.local
<code>[exim]

enabled = true
filter  = exim
logpath = /var/log/exim/mainlog
action  = iptables-multiport[name=exim,port="25,465,587"]
       sendmail-whois[name=exim, firstname.lastname@example.com, firstname.lastname@example.com, sendername="Fail2Ban"]
#action = apf[name=eximfail2ban]
#        sendmail-whois[name=exim, firstname.lastname@example.com, firstname.lastname@example.com, sendername="Fail2Ban"]
</code>
any suggestions?
Comment: What's in the log for fail2ban at startup?
Comment: @sebix fail2ban is loading fine as it is told to email in startup and I get emails for exim "Hi,

The jail dovecot has been started successfully.

Regards,

Fail2Ban
"
Answer: I have finally solved this, runnning the commands manually from the configuration showed that it needed the full path to APF.
Once this was added it started to work!

Setup fail2ban with apf


Can a value appearing more frequently for a class help predict it?

Question: I am trying to analyse my data before doing multi-class classification with SVM.
I have several variables. I pick one of them and study it.
This is a categorical variable. It can have the value 0 or the value 1.
Most of the time, it has the value 0. But sometimes it gets a 1.
I studied the frequency of ones and I got the following results:
The variable has the value 1 :

2.71% for all classes
2.22% for class 1.
2.53% for class 2.
4.79% for class 3.
2.23% for class 4.
1.99% for class 5.

Can I consider that this variable is important for predicting class 3 or is it incorrect?
Answer: The immediate answer is: it's not clear yet - this analysis doesn't tell you enough to say.
You seem to want to say something like "I just picked up one data point, and it was a 1 - should I guess that it's class 3?" The first problem with that is that it depends on how MANY class 3 samples there are. If there were equal numbers of every category, it would be the best guess. But if there is only one class 3 sample, and a million from the other categories, it's a terrible guess!
The other thing to mention is that it's impossible to (meaningfully) classify your data into six categories using only one binary feature, so if you have other variables, you should see what else they tell you. They might have a very different story.
Comment: Is there a reason you haven't run the svm yet? Are you looking for a different way to analyze things, or were you just curious about this approach?
Comment: I already ran the SVM but I am trying to learn how to do feature-selection. And it seems to me that a lot of it comes from analysing the data. But I don't really know what to look for as I am not very strong on statistics. I also wanted to see if I could find a specific variable which would be good for classifying a particular classe. So if I have 100 variables, I could pick 20 for classifying one class, 34 for classifying another and so on...
Comment: Well, using an SVM _is_ analyzing the data -- the point is understanding what you're seeing. Feature selection means finding only the features that matter, so in general, you can take features out, re-run the model, and see if your predictions are any worse. If not, you can remove that feature. There are more sophisticated ways of doing it, but that's the general principal. Also, I'm not sure exactly what you're suggesting by having subsets of variables for different classes, but in general, you only want 1 model for all your predictions. I suggest a tutorial on feature selection.


Problem with my floor...

Question: Let the set of numbers $A,n$ be of defined as $A_n = \text{the }n\text{'th value of }x\text{ such that }2\not\mid\lfloor{ x^2 - \sqrt{x}}\rfloor$, and $n$ is a positive integer.
So as the first 10 sums are:
$$\begin{align}
x&&\lfloor{ x^2 - \sqrt{x}}\rfloor\\
1 &&0\\
2 &&2\\
3 &&7\\
4 &&14\\
5 &&22\\
6 &&33\\
7 &&46\\
8 &&61\\
9 &&78\\
10 &&96\\
\end{align}$$
The terms of $A$ is $A_1 = 3, A_2 =6,A_3 = 8,$ and so on.
I'm trying to determine whether the following is correct:
$$2 n+\lfloor{\frac{1}{2}+\frac{1}{2} \sqrt{8 n - 7}}\rfloor = A_n$$
$A_n = $ Complement of the Connell sequence
This is a real pain, as I have little to no experience in working with the floor function. How can this be (dis)proven?
Any help would be appreciated.
Comment: I think you want to reverse / simplify the definition to the nth positive $x$ for which the floor of $x^2=\sqrt{x}$ is odd.
Comment: The notation $a|b$ means that $a$ divides $b$, so you should say $2\not |...$.
Answer: I'll just start writing down my thoughts. I don't know where they'll end...
You want $\lfloor{ x^2 - \sqrt{x}}\rfloor$ to be odd. Because you only look at integers $x$, we know that $\lfloor{ x^2 - \sqrt{x}}\rfloor=x^2+\lfloor -\sqrt x\rfloor=x^2-\lceil\sqrt x\rceil$. Now, you want $\lceil \sqrt x\rceil$ to have the opposite parity of $x$ (because $x^2$ has the same parity as $x$. You know that $\lceil\sqrt x\rceil$ is odd when $(2k)^2<x\leq(2k+1)^2$ for some integer $k$. It is even when $(2k+1)^2< x\leq(2k+2)^2$.
Now, we find the following values:
$$
3,6,8,11,13,15,18,20,22,24,27,29,31,33,35,38,\dots
$$
As you can see, you get all even or odd values between consecutive squares, and when crossing a square, you change the parity. Also, the differences are always $2$, except when crossing a square; then they are $3$.
Your formula gives these numbers too, so it seems to be correct. (Now, I assume you came this far yourself...)
We know every group of numbers of the same parity is one larger than its predecessor. We want to solve $\frac{k(k+1)}2=n$ to find the number of the group $n$ is in. This is what we want to add to $2n$ to make a correction for the steps of size $3$. Solving it gives $\lfloor\frac{1}{2} \left(\sqrt{8 n+1}-1\right)\rfloor$. We still have to add $1$ to correct for the offset. (this can/should be proven/explained more carefully) Now, we obtain exactly the formula you gave yourself. This is (almost) enough explanation to make it a proof IMO.

Problem with my floor...


Is a morphism with finite fibers birational?

Question: Let $f: X \rightarrow Y$ be a morphism of projective varieties such that its fibers have finitely many points. Is $f$ birational on its image?
Thanks.
Comment: A birational map is generically one-to-one, by definition.
Comment: Ok, but which are the isomorphic open sets?
Comment: Dear rla, I don't understand your question.
Answer: The answer is no in general. $X$ and $Y$ can be two smooth projective curves of different genera which are by no means birational.
Comment: Dear @Robert you are right. I made a tremendous confusion. I am trying to show that a certain divisor is big, what is sufficient to show that its associated morphism has finite fibers. This guarantees that the morphism associated to a tensor power of the divisor is birational and not necessarily the morphism associated to the divisor. Thanks.


Show that a set of vectors spans $\Bbb R^3$?

Question: Let $ S = \{ (1,1,0), (0,1,1), (1,0,1) \} \subset \Bbb R^3 .$
a) Show that S spans $\Bbb R^3$
b) Show that S is a basis for $\Bbb R^3 $
I cannot use the rank-dimension method for (a). Is it possible to show via combination of 3 vectors? What would the final equations be like? I tried using this method but I don't think it's the final answer.
$x+z = a \\
x+y=b\\
y+z=c$
So what do I do from here.
I'm not sure how to do (b).
Answer: Let $$v\in \Bbb R^3$$ Then v = (v1,v2,v3). Let s1 = (1,1,0), s2 = (0,1,1), s3 = (1,0,1).
So by row reducing the matrix (s1 s2 s3 v), we get that  $$v = ((v_1+v_2-v_3)/2)*s_1 + ((-v_1+v_2+v_3)/2)*s2 + ((v_1-v_2+v_3)/2)*s_3$$
And since v was chosen arbitrarily this means that $$S\ \text{spans}\ \Bbb R^3$$
Now all you need to do is show that S is linearly independent. (Hint: show that there is only one solution to this (s1 s2 s3 x) where x is the zero vector.
Answer: to show $S$ spans $\mathbb{R}^3$, consider the set of all linear combinations of $S$ - make a matrix with $S$ as column vectors, and all linear combinations of $S$ are the image of $\mathbb{R}^3$ under left multiplication by $A$. So claim that $S$ spans $\mathbb{R}^3$ implies that for each $(a,b,c)^T \in \mathbb{R}^3$, there is a solution to the system $S (x,y,z)^T = (a,b,c)^T$. Solve the system directly, there exists a unique solution.
The uniqueness implies it's a basis also (since uniqueness implies linear independence of the elements of $S$).


Regex finds too many matches

Question: I think I almost got my Regex down now (thanks to this community). I have the following Regex:
== [A-Za-z\\s]+ ==

I am looking through text from Wikipedia, so this is how I'm going to split the text up after retrieval. An example:
== References == or == External Links ==

But some times I will get things such as:
=== Some thing === <-- This is not picked up. Great!
==== Some other Thing ==== <-- "== Some other Thing ==" is picked up. Bad!

I tried changing it to the following with no satisfactory result:
/^== [A-Za-z\\s]+ ==$/
(?<![\w\d])== [A-Za-z\\s]+ ==(?![\w\d])
/\b== [A-Za-z\\s]+ ==\b/

Any help with my regex?
Comment: I would help immensely if you told us what you wanted to match :-)  In English first perhaps?
Comment: Your regexp picks up anything between `==`. Why shouldn't it pick up `Some other Thing`?
Comment: Ahh, you want to match between `==` but not between `===`.
Comment: @Barmar I want to *only* match between == and nothing else.
Comment: ... or do you need to match as many ==== as there are?
Comment: I bet on the negative lookarounds. However, if they do not work, it might be because of the regex flavor which is used. In that case maybe add a tag to the question indicating which one should be considered for answering. sed, perl, ...
Answer: Use negative lookarounds to prohibit matching when there's an extra =.
(?<!=)== [A-Za-z\s]+ ==(?!=)

DEMO
Comment: I think this might be it. I didn't know negative lookaround was a thing (Regex is basically black magic to me <.<). Give me a sec.
Answer: Does this work for you?
[=]+ [A-Za-z\\s]+ [=]+
I know it does not make the 2 sides match, but it should pick up all instances now.
You can also change [=]+ to [=]{1,3} if you need to limit it.
Comment: Sorry, I didn't see the comments. If you want exactly == change the code from `[=]+` to `[=]{2}`.
Comment: What's the difference between `[=]{2}` and `==` as in his original regexp?
Comment: The problem he has is that matching exactly `==` doesn't preclude matching `===`, because the match starts after the first `=`.
Answer: You could achieve it with
(?<!=)==\s*([^=]+)\s*==(?!=)

See a demo here.
This uses negative lookarounds and a negated character class.

Just for the sake of training purposes and to give you an alternative, you could use subroutines as well:
(?(DEFINE)
    (?<left>(?<!=)(?==))
    (?<right>(?<==)(?!=))
    (?<separator>(?&left)==(?&right))

)
(?&separator)
(.+?)
(?&separator)

See a demo for this on regex101.com as well.

Regex finds too many matches


In GSOAP, what is the difference between client and server mode?

Question: I use GSOAP to implement a simple program that fullfills ONVIF discovery functionality.
(The NVT, NVR part, not the Device Manager, i.e Client part)
The program needs to
1) Send "ProbeMatch" messages in response to "Probe" messages of the ONVIF DM.
2) Send "Hello" messages occasionally.
I downloaded and launched "gsoap" tool without any problem. I generated h and c files, and created a project in Eclipse.
When I generate C files in "Client" mode, I can build the Eclipse project. There are 3 functions defined in soapClient.cpp but I do not know how to use them in main function ( What are the parameters ns2_HelloType and ns2_ResolveType). And, when do I call these functions?
When I generate C files in "Server" mode, I cannot build the Eclipse project because those functions have signatures in h files but are not defined. I have to define them according to the tutorial of gsoap. (Calculator Example)
http://www.cs.fsu.edu/~engelen/soapdoc2.html
Actually, I couldn't manage to understand the concepts "Server" and "Client". Which part of the ONVIF specification is client, which is the server? Hello, Bye etc. are the functions of the "device" itself so is the device SOAP Server? Can anybody clarify those concepts?
Best Regards,
Firat
Comment: @OttavioCampana - I understand that. The concepts are similar to create C bindings for both client and server apps.  The question he is asking is to clear up concepts surrounding server/client.
Comment: There is a ***[tutorial here](https://decibel.ni.com/content/docs/DOC-22167)***.  Open the zip, and read the documents included in the docs directory.  This example uses a different development environment than you may be using, but it provides a step by step _how to_ on building the gsoap files for a client. (btw, which is what you need).
Comment: he needs a server, he's implementing an NVT and not a client.
Answer: What kind of device are you trying to implement? A Network Video Transmitter (NVT)? In this case you need to implement the server.
The client is the part of the VMS that connects to the devices.
When you generate the server part, you need to implement the functions that do something when the correspondent function is invoked from a VMS. This is why you get a build failure.
Answer: You asked several questions.  This will address only those concerning gsoap, client/server.  Regarding your question: I couldn't manage to understand the concepts "Server" and "Client" , Can anybody clarify those concepts?....  So, in the most general terms:
If you are using gsoap, it is because you want to use C bindings to stitch together some component of a web service, either on the server side, or on the client side.
A simple web service Server/Client scenario:
The server, in simplified terms, listens for a request from a client, and based on some provided information from the requester (i.e. the client), queries its data source, usually a database, using the input data, packages up the requested data and returns it to the client.  Think of getting the weather from your phone.  Your phone, the client, sends some small piece of information such as postal code, to a known WSDL end point.  The weather data is returned and displayed on your phone app.
Using gsoap it would look like this:, The request sent from your phone is simply entered as human readable text: 98873-1234, read in from an application using the gsoap C bindings into a C data structure.  The C binding (C function) converts the struct data to XML SOAP format using the functionality in gsoap libraries, and sends the XML data  via tcp/ip to the WSDL end point of the server.   The server side gsoap libraries within an application receive this data, convert it from the XML SOAP format into C type data most likely as a member of a struct.  The data is then used to build a query string to the database and make a query.  The query is sent to the database.   The response, XML SOAP, is again converted to C type data, and using the C bindings (C functions)  provided by gsoap, sent back to the requesting client.
Again, in very simple terms it looks like this:
ServerSide database<->SQL<->gsoapApp<->tcp/ip<->gsoapApp<->userInterfaceDisplay ClientSide
There is a client application example here.  Although this example is targeted toward client side applications, the concept for server side gsoap code generation is very similar.
Comment: client and servers gsoap-based applications have a big difference: client applications have all the necessary routines to interact with a devices, but the server files are not complete: the functions that handle the received commands need to be defined and written by the user. That's the reason why he's not able to compile.


What is the proper approach and place for normative statements on Economics SE?

Question: Note- This question is an extension from a discussion in the comments of this answer. Thanks to @denesp for the recommendation for this meta question, and @AlecosPapadopoulos for the cited answer above and a thoughtful reply!
Ultimately, I guess my question for the broader community is: what is the proper place for, and usage of, normative claims in an answer and/or question? I agree that normative statements should be minimized and positive statements should take overwhelming priority wherever possible, but does that mean there is no place for normative judgments/statements on Economics SE?
The main field where I see this issue coming to a head is in Social Choice. I'm concerned that a blanket ban on any normative evaluation severely undermines our ability to engage in some of the most well-published and historically interesting areas of social choice theory. Several of the most cited and well-regarded papers in that field incorporate ethics and value judgments, and therefore would themselves be considered "off topic" if they were discussed on the forum (assuming these judgments are banned, that is).
As a point of emphasis, some examples of this reality are:
Utilitarianism and Its Critiques
Harsanyi's 1955 work that is one of the early economic outlines of Utilitarianism proposes "to examine the precise ethical meaning of Fleming's crucial postulate" and examines it's "acceptab[ility] according to common ethical standards."
Diamond's 1967 critique of Utilitarianism also motivates itself largely on normative and ethical grounds, as he states "I wish to argue that one [of Harsanyi's axioms] is not consistent with notions of justice held by some individuals. Since this is an ethical discussion, the argument will take the form of an example which suggests the problem inherent in the axiom..."
Classical Texts in Bargaining Theory:
John Nash's 1950 paper on bargaining which justifies his solution primarily on normative grounds, suggesting "It is the purpose of this paper to give a theoretical discussion of this problem and to obtain a definite 'solution'- making, of course, certain idealizations in order to do so. A 'solution' here means a determination of the amount of satisfaction each individual should expect to get from the situation, or, rather, a determination of how much it should be worth to each of these individuals to have this opportunity to bargain."
Kalai Smorodinsky's 1975 alternative Itself is also motivated, in part, on ethical grounds. Monotonicity, as an axiom, is rooted in the perceived "unfairness" of comparing different solutions of bargaining games.
It seems difficult, in light of these crucial works in economic thought, to completely dismiss normative assessment on this site. However, that said, it clearly should only be applied when "necessary" (for lack of a better term). Does anyone have any thoughts on the matter?
Thank you!
Answer: This question is kinda making me call into question what I thought I knew about the difference between positive and normative statements. :)
But, yeah, I think that any question which invites purely subjective answers probably doesn't belong on the site. I don't think that this is really a problem. In the Diamond 1967 paper that you cited, for example, the point is whether or not the axiom in question represents the notions of justice held by the average person. This seems like something that is testable and, therefore, invites non-subjective answers. On the other hand, if the discussion were "do I personally like that axiom or not?" would be a subjective question.
Answer: The general Stack Exchange rule seems to be that we should avoid statements or questions that are purely opinion-based. Thus, it would be off-topic to express a like or dislike for a particular axiom, distribution of wealth or any other object. Similarly, we shouldn't solicit such statements.
However, this should not be equated with avoiding normative statements altogether. There are plenty of those in economics, there are many classes taught in normative economics, and this community would not reflect the discipline if we were to shy away from them.
For example, consider the standard discussion that you have in a Public Economics class about optimal income taxation (e.g., using the Mirrlees model). There is an extensive  economics literature on how normative conclusions change about tax rates, depending on the social welfare function.
We can go further than that though, and look at normative statements about normative criteria themselves. For example, there are plenty of papers about whether some social welfare functions are better than others in some way. A distinguishing feature of them is that they are clear about exactly what is desirable (or not) about particular approaches.
For example, Kaplow & Shavell, 1999 show that a particular class of welfare functions violate the pareto principle. This is useful and very much on-topic for this site. It would perhaps not be appropriate to start a discussion of whether or not you like the pareto principle.
I therefore partly disagree with the statement by @AlecosPapadopoulos in the cited answer.

Now, the fact that even without hoarding, rich people may stay rich or become richer, the fact that there are people dying of hunger while others live lavish life-styles, and how do we judge the existence and degree of financial inequality we observe, is as I said in the beginning, a totally different matter, and off-topic on this site.

To rule as off-topic any discussion of "how we judge the degree of financial inequality we observe" would be to rule out discussion of a significant and important part of the economics literature.
Perhaps it would be better to state simply that it would be off-topic to provide a purely opinion-based discussion of normative issues such as the distribution of wealth. Discussion the application, properties and/or choice of well-defined normative criteria could definitely be relevant if it answers the question at hand.
Comment: Thank you for responding constructively to a post of mine. I re-read my passage and I found myself fully disagreeing with myself (the passage is deplorably vague and confusing), so I changed it.


Major league athletes with extra regular season games played

Question: I'm looking for athletes in the top North American Leagues: NFL, MLB, NBA, and NHL that played more games in a season than games scheduled for a team.
For example, each NFL team is scheduled to play 16 games per regular season. I'm wondering if there has been any player who played more than 16 games in a season. This can happen if a player gets traded to a team with less games played and plays all games for both teams (or all teams if he played for more than 2 teams in that season).
To make this clear I'd like to know if there have been cases of athletes who played

17 or more NFL games
163 or more MLB games
83 or more NBA or NHL games

in one regular season given that the NFL and MLB teams play 16 and 162 games respectively and NBA and NHL teams play 82 games each regular season.
Answer: In short, YES
Several examples with detail:
NFL: (source) . All of these were because of trades and extra bye-week game scheduling.

MLB:
(via trade)
Frank Taveras played 11 for the Pittsburgh Pirates and 153 for the NY Mets in 1979.
Willie Montanezin 1976 played 60 games for the SF Giants and 103 games for the Atlanta Braves.
(not via a trade but extra regular season games) - Games that end with a tie score, due most commonly to darkness (in the old days), rain-outs, or curfews are replayed, with the result not counted in the standings, but all of the individual stats count for the players.
In 1962, Maury Wills of the LA Dodgers played all 165 games. When the 1962 season ended the San Francisco Giants and the Dodgers were tied with a 101-61 record. ... Wills played in all 162 regular season games and the 3 tie-breaker games, which are counted as regular season games, much like today's one-game playoffs are counted as regular season contests.  In the same season, Jose Pagan played 161 of 162 regular season games and 3 extra games for the opposing SF Giants.
In 1965 the Chicago Cubs played in 164 regular season games, because two of them ended in ties (due to darkness, so apparently they could not be made up).  In that year Ron Santo and Billy Williams played all 164 games and Ernie Banks played in 163.
There are several other examples of ties impacting individual stats but not team W-L.
NHL:
Quant Hockeysays 170 players played more than 82 regular season games.
Jimmy Carson has the regular season record for NHL players with 86 in 1992-1993 - traded mid-season, he played 52 with the Detroit Redwings and then 34 with the LA Kings.
Bob Kudelski tied Carson a year later playing 42 games for the Ottawa Senators and then 44 with the Florida Panthers.
NBA:
Walt Bellamy has the NBA record for most regular season games played (88) in the 1968-69 season.  Traded during the season, he played 35 games with the New York Knicks and then 53 games with the Detroit Pistons.


htaccess proxy redirect for root and only root

Question: I'm trying to redirect only the root domain (and not its subfolders) to another URL, without changing the address. I'm using .htaccess and redirecting with [P] flag, which works fine for subdirectories but not for the root.
When writing the following .htaccess everything works fine, but in 'regular' redirect and not proxy:
RewriteEngine on
Rewriterule ^$ http://mysubdomain.mydomain.com/ [R,L]

When changing to mod_proxy, it doesn't work (does not redirect without an error):
RewriteEngine on
Rewriterule ^$ http://mysubdomain.mydomain.com/ [P]

It is important to me to keep the original address in the browser address bar.
any idea?
Thanks
Answer: It's probably doesn't work because the rule doesn;t apply.
In most cases the root is not empty, but contains a request to index.html or default.html . Give this snippet a try:
RewriteEngine  on
RewriteRule    "default.html"  "http://mysubdomain.mydomain.com/"  [P]


Adding settings to Settings

Question: The application I am developing is in large parts a background-only Service BUT requires some settings that the user must add. Is there a way to integrate applications with the common Settings application/view/activity?
Answer:
Is there a way to integrate
  applications with the common Settings
  application/view/activity?

Only by modifying the firmware. Android does not support SDK applications defining or adding global preferences.
You can use the same look and feel for your own settings activity by use of PreferenceActivity and preference XML files. But you will then still need to have that activity appear in the Launcher.
Comment: @an00b: "TTS engines do that all the time" -- strictly speaking, they do not. They can publish their own settings activity, that the Settings app can elect to link to. That is not possible for arbitrary apps, as per the OP.
Comment: Actually that isn't 100% true. TTS engines do that all the time without modifying firmware and without requiring root access. I just don't know [how](http://stackoverflow.com/q/12096555/636571) they do it.
Comment: OK but how do they get the Settings app to elect to link to? What protocol/api/hook is being used to make their settings activity invokable from the System Settings? I am currently researching this and I have no clue where to begin: http://stackoverflow.com/q/12096555/636571

Adding settings to Settings


Como identificar os repositórios existentes no meu github?

Question: Estou fazendo um curso básico de github e só me passaram que o push tem que ser feito para "origin master".
 Porém quando faço o comando no terminal (linha de comando) recebo a seguinte mensagem:

MacBook-Pro-de-Julio:Curso de Git juliobarreto$ git email@example.com:juliocezarjr/curso-git.git github1 Cloning into
  'github1'... ssh: connect to host github.com port 22: Operation timed
  out fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository
  exists.

Obs: Não sei se tem alguma relação, mas pelo curso, era pra eu clonar o repositório usando uma SSH Key, só que não deu certo. Só consegui clonar o repositório pelo URL.
Comment: A propósito, creio que aqui você não se interessa pelo GitHub (serviço que provê hospedagem de projetos git + questões de redes sociais + talvez CI?), e sim o git propriamente dito. Saber os repositórios no GitHub é só abrir seu perfil, repositórios.
Comment: Meu problema acontece quando tento clonar um repositório do github. Então meu interesse no github é na medida em que não consigo clonar um repositório github.
Answer: Execute o comando:
<code>git remote -v
</code>
A relação são as URL's para onde é possível enviar o push. Deve existir pelo menos uma e por padrão é nomeada como Origin. Veja se a URL bate com a que está enviando o push.
Você também deve ter acesso ao repositório remoto, se está tentando fazer um push para um repo da sua conta do Github, o remote local deve apontar para a URL do repo no Github, aquela mesma que você usou para clonar.
Comment: O comando "git remote -v" não executa nada no meu terminal. Estou fazendo alguma coisa errada?
Comment: Você está na pasta do repositório? Se não tem nenhum retorno, é por que você não tem um remote cadastrado


Transformar um vetor de bytes em DataSet

Question: Estou lendo um arquivo de excel (xls, xlsx, csv) e exibindo seu conteúdo em uma página nova usando DataSet. Eu consigo fazer para xls e xlsx, mas pra csv não ta rolando.
public static DataSet result;

public static void prepareFile(HttpPostedFileBase file) {
        Stream stream = file.InputStream;
        IExcelDataReader reader = null;
        byte[] fileDataCsv;

        if (file.FileName.EndsWith(".csv")) {
            BinaryReader binaryReader = new BinaryReader(file.InputStream, Encoding.UTF8);
            fileDataCsv = binaryReader.ReadBytes(file.ContentLength);
            showCsv(fileDataCsv);
        } else if (file.FileName.EndsWith(".xls")) {
            reader = ExcelReaderFactory.CreateBinaryReader(stream);
            showXls(reader);
        } else if (file.FileName.EndsWith(".xlsx")) {
            reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
            showXls(reader);
        } else {
            //TODO: Message error
            return;
        }
    }

Vi em alguns foruns algumas pessoas chegando bem perto do que queria usando byte[], mas não consigo descobrir o que preciso fazer para transformar esses byte[] em DataSet.
Alguma ideia?
PS: Sei que posso estar fazendo errado, então fico aberto a exibir esse arquivo .csv de qualquer outra forma.
Answer: Eu faria de outra forma:
 //Declaro o StreamReader para o caminho onde se encontra o arquivo
        StreamReader rd = new StreamReader(@"e:\file.csv");
        //Declaro uma string que será utilizada para receber a linha completa do arquivo
        string linha = null;
        //Declaro um array do tipo string que será utilizado para adicionar o conteudo da linha separado
        string[] linhaseparada = null;
        //realizo o while para ler o conteudo da linha
        while ((linha = rd.ReadLine()) != null)
        {
            //com o split adiciono a string 'quebrada' dentro do array
            linhaseparada = linha.Split(';');
            //aqui incluo o método necessário para continuar o trabalho

        }
        rd.Close();

Comment: Obrigado! Fiz algumas modificações no meu código e consegui adequar :)


How can I dynamically add drupal behaviors to a form from php using ajax?

Question: I am creating a form which dynamically changes based on the value of a select element.  What happens is this:

The user selects a value from the select element
The select element uses Drupal's ajax methods to reload the form, now with some new elements for further configuration
Some of the new elements need to be turned into jQuery widgets.

Now, the obvious solution here is to use behaviors to run the widget initialization code.  The issue is that I don't know ahead of time which elements need to have what code run on them.  I will only know that at the time the ajax portion of the form loads.
Currently, my solution is to have a very short JavaScript file which is solely responsible for adding new behaviors which in turn run the jQuery UI code that I need.
An alternate solution is to pre-load all of the possible configuration elements and inject all of the behaviors ahead of time.  For various reasons this isn't a good idea, not least because I rather like lazy loading.
My question is: is there some way to attach behaviors in php through Drupal's ajax mechanism, like there is a way to modify the settings?
Answer: Yes you can attach Drupal Behaviors to newly added elements (DOM nodes):
You can check ahah.js (in Drupal.ahah.prototype.success):
// Attach all javascript behaviors to the new content, if it was successfully
// added to the page, this if statement allows #ahah[wrapper] to be optional.
if (new_content.parents('html').length > 0) {
  Drupal.attachBehaviors(new_content);
}

Or if your script creates the elements (answer on stackoverflow about drupal-behaviours):
var newNodes = $('Hello World').appendTo('#someDiv');
Drupal.attachBehaviors(newNodes);

Comment: Thanks for your answer, but this isn't quite the question I asked.  I know how to add behaviors in javascript.  I am wondering if there is a way to tell Drupal to do it from php, through something like drupal_add_js().
Answer: Just to know. Are you using #states from Form API?
I think you should use drupal_add_js through a hook_form_alter in order to make sure that the widget plugin will be already loaded in the page and then use the behavior just to  call the method responsible to property convert the element into a JQuery UI element. Using this approach I think you shouldn't worry about adding a behavior on the ajax response.
Comment: I'd use #attached instead of drupal_add_js, reduces some of the overheads and easier to alter from other functions later through the lifecycle.
Answer: This item answers your question if you was dealing with a custom callback: drupal_add_js within AJAX callback
djayp34's answer should help you in your scenario though:
drupal_add_js doesn't work properly in an AJAX callback. If you need to execute a JavaScript function within an AJAX callback, here's a way :
First in your form, you have to create (you can just import it) the JavaScript function :
function my_module_form($form, &$form_state) {
// [...]
  drupal_add_js(
    'Drupal.ajax.prototype.commands.myFunction = function(ajax, response, status) {
     // Whatever you want to do.
        }',
        'inline'
     );
 // [...]
 return $form;
}

Then in your AJAX callback, you need to call the function you have created :
function my_module_my_ajax_callback($form, &$form_state) {
  // [...]
  $commands[] = array("command" => 'myFunction',);
  // [...]
  return array('#type' => 'ajax', '#commands' => $commands);
}


A subset of a metric space $X$ is nowhere dense iff the complement of it's closure is (everywhere) dense?

Question: If $A\subset X$  is nowhere dense, then $int({\overline A)} = \phi$.
$\implies$ No neighbourhood of $x \in A$ is in ${\overline A}$.
$\implies $ Every neighbourhood of $x$ is in $({\overline A})^c.$
$\implies x$ is a limit point of $({\overline A})^c$.
I'm stuck now on how to show the closure of $({\overline A})^c$ is $X$, and the converse part also.
Comment: No neighborhood of $x \in A$ is in $\overline A$ $\not \implies$ every neighbohood of x is in $(\overline A)^c$.  In fact $x \in A \subset \overline A$ so $x \not \in (\overline A)^c$ so no neighborhood of x is in $(\overline A)^c$.
Comment: $(\overline A)^c$ *isn't X.  and can't be shown to be X.  $\overline{(\overline A)^c}$ is X and can be shown by showing every point of X is a limit point of $(\overline A)^c$.
Answer: $int \overline A = \emptyset$
No neighborhood of $x \in \overline A$ is entirely in $ \overline A$.
$\implies$ every neighborhood of $x \in \overline A$ contains a point of $\overline A^c$.
So every point of $\overline A$ is a limit point of $\overline A^c$.
Every point of X is in either in $\overline A^c$ or $\overline A$ so every point of X is either in $\overline A^c$ or is a limit point of $\overline A^c$.
So $\overline A^c$ is dense in X.
===
if $x \in int \overline A$ (i.e. if $int \overline A$ is not empty). Then there exists a neighborhood of $x$ that is entirely in $\overline A$.  Thus x is not an limit point of $\overline A ^c$.  And $x \in \overline A$ so x $x \not \in \overline A ^c$.  So the existence of $x$ shows not every point of $X$ is a limit point or a point of $\overline A ^c$.
So $\overline A ^c$ is not dense in X.
Answer: Your assumption is that the interior of $\bar{A}$ is empty and you want to prove that $X\setminus\bar{A}$ is dense.
Let $x\in X$ and consider an open neighborhood $U$ of $x$ (an open ball, if you prefer).
We need to show that $U\cap(X\setminus\bar{A})\ne\emptyset$. But, if $U\cap(X\setminus\bar{A})=\emptyset$, we have that
$$
U\subseteq \bar{A}
$$
and therefore $x$ belongs to the interior of $\bar{A}$.
Conversely, assume $U\cap(X\setminus\bar{A})$ is dense in $X$. Suppose $x$ belongs to the interior of $\bar{A}$. Then there exists an open neighborhood $U$ of $x$ such that $U\subseteq \bar{A}$. This implies $U\cap(X\setminus\bar{A})=\emptyset$, contradicting the hypothesis that $U\cap(X\setminus\bar{A})$ is dense in $X$.


Parsing a HTML Table

Question: So far I have the following code:
Dim wreqBalQtr As HttpWebRequest = WebRequest.Create("http://www.reuters.com/finance/stocks/incomeStatement/detail?stmtType=BAL&perType=INT&symbol=" & tickerValue)
wreqBalQtr.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:22.214.171.124) Gecko/20091102 Firefox/3.5.5"
wreqBalQtr.Method = "get"
Dim proxBalQtr As IWebProxy = wreqBalQtr.Proxy
proxBalQtr.Credentials = CredentialCache.DefaultCredentials
Dim documentBalQtr As New HtmlAgilityPack.HtmlDocument
Dim webBalQtr As New HtmlAgilityPack.HtmlWeb
webBalQtr.UseCookies = True
webBalQtr.PreRequest = New HtmlAgilityPack.HtmlWeb.PreRequestHandler(AddressOf onPreReq)
wreqBalQtr.CookieContainer = cookies
Dim resBalQtr As HttpWebResponse = wreqBalQtr.GetResponse()
documentBalQtr.Load(resBalQtr.GetResponseStream, True)
Dim TotalCurrentAssets = documentBalQtr.DocumentNode.SelectSingleNode("//table[@class='dataTable Financials']//tr[13]//td[3]")

And the HTML is:

        In Millions of U.S. Dollars

        (except for per share items)

        2012

        2012-09-30

        2012

        2012-06-30

        2012

        2012-03-31

        2011

        2011-12-31

        Reclassified

        2012-06-30

        2011

        2011-09-30

        Cash
        6,224.0
          7,463.0
          11,239.0
          4,712.0
          4,209.0

        Cash & Equivalents
        10,036.0
          7,974.0
          11,869.0
          5,271.0
          6,421.0

        Short Term Investments
        29,464.0
          27,685.0
          26,208.0
          34,643.0
          31,930.0

        Cash and Short Term Investments
        45,724.0
          43,122.0
          49,316.0
          44,626.0
          42,560.0

        Accounts Receivable - Trade, Net
        7,259.0
          6,866.0
          5,163.0
          5,427.0
          4,583.0

        Notes Receivable - Short Term
        --
          --
          --
          --
          --

        Receivables - Other
        550.0
          475.0
          550.0
          745.0
          1,278.0

        Total Receivables, Net
        7,809.0
          7,341.0
          5,713.0
          6,172.0
          5,861.0

        Total Inventory
        618.0
          634.0
          --
          35.0
          --

        Prepaid Expenses
        2,440.0
          2,614.0
          1,779.0
          1,710.0
          1,406.0

        Other Current Assets, Total
        230.0
          146.0
          51.0
          215.0
          215.0

        Total Current Assets
        56,821.0
          53,857.0
          56,859.0
          52,758.0
          50,042.0

        Property/Plant/Equipment, Total - Gross
        17,038.0
          16,137.0
          14,963.0
          14,400.0
          13,815.0

        Accumulated Depreciation, Total
        (5,637.0)
          (5,228.0)
          (5,088.0)
          (4,797.0)
          (4,611.0)

        Property/Plant/Equipment, Total - Net
        11,401.0
          10,909.0
          9,875.0
          9,603.0
          9,204.0

        Goodwill, Net
        10,485.0
          10,120.0
          7,325.0
          7,346.0
          6,989.0

        Intangibles, Net
        7,754.0
          7,862.0
          1,541.0
          1,578.0
          1,474.0

        Long Term Investments
        1,063.0
          1,040.0
          880.0
          790.0
          891.0

        Note Receivable - Long Term
        --
          --
          --
          --
          --

        Other Long Term Assets, Total
        2,206.0
          2,263.0
          664.0
          499.0
          488.0

        Other Assets, Total
        --
          --
          --
          --
          --

        Total Assets
        89,730.0
          86,051.0
          77,144.0
          72,574.0
          69,088.0

        Accounts Payable
        2,233.0
          2,419.0
          760.0
          588.0
          563.0

        Payable/Accrued
        --
          --
          --
          --
          --

        Accrued Expenses
        6,347.0
          5,551.0
          3,429.0
          4,356.0
          3,563.0

        Notes Payable/Short Term Debt
        3,218.0
          3,218.0
          2,468.0
          1,218.0
          1,218.0

        Current Port. of  LT Debt/Capital Leases
        --
          --
          --
          --
          --

        Other Current liabilities, Total
        2,636.0
          2,840.0
          3,085.0
          2,751.0
          3,544.0

        Total Current Liabilities
        14,434.0
          14,028.0
          9,742.0
          8,913.0
          8,888.0

        Long Term Debt
        2,988.0
          2,987.0
          2,987.0
          2,986.0
          2,986.0

        Capital Lease Obligations
        --
          --
          --
          --
          --

        Total Long Term Debt
        2,988.0
          2,987.0
          2,987.0
          2,986.0
          2,986.0

        Total Debt
        6,206.0
          6,205.0
          5,455.0
          4,204.0
          4,204.0

        Deferred Income Tax
        1,461.0
          1,509.0
          384.0
          287.0
          263.0

        Minority Interest
        --
          --
          --
          --
          --

        Other Liabilities, Total
        2,819.0
          2,806.0
          2,319.0
          2,243.0
          2,121.0

        Total Liabilities
        21,702.0
          21,330.0
          15,432.0
          14,429.0
          14,258.0

        Redeemable Preferred Stock, Total
        --
          --
          --
          --
          --

        Preferred Stock - Non Redeemable, Net
        0.0
          0.0
          0.0
          0.0
          0.0

        Common Stock, Total
        22,204.0
          21,357.0
          20,795.0
          20,264.0
          19,697.0

        Additional Paid-In Capital
        --
          --
          --
          --
          --

        Retained Earnings (Accumulated Deficit)
        45,456.0
          43,280.0
          40,495.0
          37,605.0
          34,901.0

        Treasury Stock - Common
        --
          --
          --
          --
          --

        ESOP Debt Guarantee
        --
          --
          --
          --
          --

        Unrealized Gain (Loss)
        566.0
          389.0
          416.0
          327.0
          99.0

        Other Equity, Total
        (198.0)
          (305.0)
          6.0
          (51.0)
          133.0

        Total Equity
        68,028.0
          64,721.0
          61,712.0
          58,145.0
          54,830.0

        Total Liabilities & Shareholders' Equity
        89,730.0
          86,051.0
          77,144.0
          72,574.0
          69,088.0

        Shares Outs - Common Stock Primary Issue
        264.52
          261.58
          259.50
          257.55
          255.70

        Shares Outstanding - Common Issue 2
        64.04
          65.36
          66.40
          67.34
          68.05

        Shares Outstanding - Common Issue 3
        --
          --
          --
          --
          --

        Shares Outstanding - Common Issue 4
        --
          --
          --
          --
          --

        Total Common Shares Outstanding
        328.55
          326.94
          325.91
          324.89
          323.76

        Total Preferred Shares Outstanding
        --
          --
          --
          --
          --

When I try to use the variable TotalCurrentAssets to pull the second column from the Total Current Assets row (the number should be 53,857.0).  I get "NullReferenceException was unhandled by user code. Object reference not not set to an instance of object."
Does this mean that the variable TotalCurrentAssets returns nothing?  I'm assuming that my error is in my last line of code.
ADDITIONAL INFORMATION
I don't know if the impacts my problem or not but I run this code before the code from my original post:
Dim wreqBeta As HttpWebRequest = WebRequest.Create("http://www.reuters.com/finance/stocks/overview?symbol=" & tickerValue)
        wreqBeta.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:18.104.22.168) Gecko/20091102 Firefox/3.5.5"
        wreqBeta.Method = "get"
        Dim proxBeta As IWebProxy = wreqBeta.Proxy
        proxBeta.Credentials = CredentialCache.DefaultCredentials
        Dim documentBeta As New HtmlAgilityPack.HtmlDocument
        Dim webBeta As New HtmlAgilityPack.HtmlWeb
        webBeta.UseCookies = True
        webBeta.PreRequest = New HtmlAgilityPack.HtmlWeb.PreRequestHandler(AddressOf onPreReq)
        wreqBeta.CookieContainer = cookies
        Dim resBeta As HttpWebResponse = wreqBeta.GetResponse()
        documentBeta.Load(resBeta.GetResponseStream, True)
        Dim beta = documentBeta.DocumentNode.SelectSingleNode("//div[@id='overallRatios']//table[@class='dataTable']//tr[1]//td[2]")

Do I need to close anything from this code before starting to parse the new webpage?
Comment: What's your `tickerValue` in the url? Then we could test it.
Comment: Sorry!  I am testing using tickerValue = GOOG.  Thanks!
Comment: I tried your code and the HTML returned by the Uri you're calling does not contain a table with that class at all. Thus, it's logical that you're not finding the cell. Use `Console.WriteLine(documentBalQtr.DocumentNode.OuterHtml)` to see the HTML being returned. It looks like you're doing some form of authentication, but since you didn't include that code, I can't test that.
Comment: I believe that I have figured out my problem.  The webpage that I am trying to parse requires that I be logged in to access the page.  I believe that this is why the HTML does not contain the table I'm searching for.  Thanks for your help!
Comment: XPath is actually 1 indexed... See: http://stackoverflow.com/questions/3319341/why-do-indexes-in-xpath-start-with-1-and-not-0
Comment: I just tried    Dim TotalCurrentAssets = documentBalQtr.DocumentNode.SelectSingleNode("//table[@class='dataTable Financials']tr[12]td[2]") and it returned "'//table[@class='dataTable Financials']tr[12]td[2]' has an invalid token.
Comment: You can replace the `//` by `/`, not remove them altogether.
Comment: I see.  I tried Dim TotalCurrentAssets = documentBalQtr.DocumentNode.SelectSingleNode("//table[@class='dataTable financials']/tr[13]/td[3]") but I am back to the same NullReferenceException error.
Comment: I don't know what you mean by "doing some form of authentication".  What code should I include so that you would know?
Comment: What is the contents of the `onPreReq` method? Your code can use some better cleanup of IDisposable members, but that is probably not what's breaking it.
Comment: Private Function onPreReq(ByVal req As HttpWebRequest)

        req.CookieContainer = cookies
        Return True

    End Function
Answer: Name matching for attributes is case sensitive. Your HTML contains *f* inancials, your code expects *F* inancials.
You can use //table[upper-case(@class)=upper-case('dataTable financials')] to prevent these type of issues when case sensitivity is not important. or you can use the XPath 2.0 matches function.
On top of that, make sure that the webpage you're accessing actually returns the data you're expecting. In my local test the page being returned does not contain a table with data similar to your sample.
Place a watch on documentBalQtr.DocumentNode.OuterHtml to verify your page actually matches what you're expecting.
Comment: Just replace `wreqBalQtr.UserAgent` with your string, instead of the FireFox link. But this will not actually use your browser to open the webpages. It will just trick the server into thinking you're connecting from Chrome. The .NET Framework will use its own internal routines to download the files. But that would be a different question.
Comment: No. The server will not be tricked. To log in, you will need to have your application submit the proper HTML post request and then store the cookies that the server returns. Can't you use a normal webservice to retrieve these values from somewhere? Again, post a different question for these types of answers.
Comment: I just changed it to     Dim TotalCurrentAssets = documentBalQtr.DocumentNode.SelectSingleNode("//table[@class='dataTable financials']//tr[13]//td[3]")    but I got the same NullReferenceException error.
Comment: When you run it in the debugger, where exactly do you get the NullReferenceException, this works just fine on my machine, but I'm not fetching the file from the web, instead I just copy/pasted your HTML snippet to my visual studio solution. I expect you had more than one bug in your code to begin with.
Comment: I get the NullReferenceException at this line dr("Current Ratio (MRQ)") = TotalCurrentAssets.InnerText
Comment: Updated my answer to include the fact that the HTML being returned doesn't match what you're expecting. If this answers your question, please mark it as such.
Comment: I want to use Google Chrome open my webpages.  I need to change wreqBeta.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:22.214.171.124) Gecko/20091102 Firefox/3.5.5"  How do I do this?
Comment: I marked you answer.  Thank you very much!  In Chrome I have the username and password saved so that I don't have to always input them to access the webpage.  Will the server be tricked by this and allow me to access the page?  What string would I use for Chrome instead of FireFox?
Comment: What kind of normal webservice?  I have searched quite a bit for one that would work and have found nothing.  Anything that you could suggest would really help!
Comment: Yahoo offers a number of Finance related webservices. As are others. Some free, some paid. http://developer.yahoo.com/finance/company.html

Parsing a HTML Table


Using Ableton with a 2015 MacBook

Question: I intend to produce music with Ableton Live 9 suite in a 2015 MacBook with 1.3 Ghz (turbo boost up to 2.7Ghz) with 8GB RAM, and 512GB storage.
Is this likely to experience lag - if so, how can I avoid that?
Comment: Your specs are fine. I have an older MBP that runs live suite great. The interface you use will have a big effect though. I suggest a thunderbolt interface.
Answer: Your processor and RAM are not going to be the bottleneck here. Your audio interface will be the critical path, as this is where latency will make itself known.
As Todd commented, you'll want to use an audio interface connected by Thunderbolt (as it has the lowest latency)
A good audio interface will also have the benefit of providing input impedance matching, a low noise floor and possibly eq and gain controls.
Answer: I'm thinking this lag you're talking about might be audio latency?
From wiki article link:

Professional digital audio equipment has latency associated with two general processes: conversion from one format to another, and digital signal processing (DSP) tasks such as equalization, compression and routing. Analog audio equipment has no appreciable latency.

I'd do some reading up on audio latency and see if it's a problem with your set up, or maybe the latency is normal. It's hard to tell without seeing/hearing it myself.
Answer: I use Ableton Live on a MacBook Pro with the following specs and it generally works fine and without noticeable lag:

MacBook Pro (Retina, Mid 2012)
2.3 GHz Intel Core i7
8 GB 1600 MHz DDR3

I don't use an external audio interface to do this (although I can optionally run a mic in via an audio interface and that works fine too). I set the buffer size at 128 samples and the sample rate at 48000 and my output latency shows as 7.38 ms. In fact, I use it to directly trigger samples, which is arguably a scenario when you would feel/hear the latency the most.
Additionally, I am using a bit of software synths and  effects processing chains.
As long as you're not trying to do a ton of other stuff on the system at the same time, I think it's fine and won't produce pops or glitches.
Do you already have the MacBook? If so, you can always try the Ableton demo before you buy it...
Answer: PC guy here, but you could run it though an external sound card, like Komplete 6.
Or you could load better music drivers; on a PC for example, we have to download a particular ASIO driver to reduce latency.
Either way, go to Preferences --> Audio and start tweaking there until you get a comfy latency.
Answer: You shouldn't have any problem running Ableton on a 2015 macbook pro. Most of the latency that you'll deal with has to do with keeping the buffer size as small as possible without overloading the cpu. Ableton has a handy dandy guide to this, available here:
https://www.ableton.com/en/help/article/latency-faqs/
Answer: Sorry for reviving the old thread, but the recommendations of some users might mislead some readers to buy the wrong interface for that laptop. Some here didn't realize that your computer has no Thunderbolt connection, only USB-C.
Get a nice USB-C to USB-A 3.1 hub (if you plan on connecting more devices) with PD (Power Delivery). Avoid Aukey hubs, since they produce glitches. Then find a good Interface with USB3 connection and you won't have any troubles running Live on that laptop.

Using Ableton with a 2015 MacBook