Mongoose nested document update failing?

Question: If I have a nested document, how can I update a field in that nested document in Mongoose?
I carefully researched this problem using everything available I could find, and even changed my test code to match a similar answered question about this here on Stackoverflow, but I am still unable to figure this out.   Here are is my Schema and Models, the code, and the Mongoose debug output.  I am unable to understand what I am doing wrong, here.
var mongoose = require('mongoose')
  , db = mongoose.createConnection('localhost', 'test')
  , assert = require("node-assert-extras");

var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;

db.once('open', function () {
  // yay!
});
mongoose.set('debug', true);

var PDFSchema = new Schema({
      title     : { type: String, required: true, trim: true }
})

var docsSchema = new Schema({
     PDFs           : [PDFSchema]
});

var A = db.model('pdf', PDFSchema);
var B = db.model('docs', docsSchema);

function reset(cb) {
  B.find().remove();
  // create some data with a nested document A
  var newA = new A( { title : "my title" })
  var newB = new B( { PDFs: newA});
  newB.save();
  cb();
}

function test1( ) {
    reset(function() {
        B.findOne({}, 'PDFs', function(e,o)
        {
            console.log(o);
            pdf_id = o.PDFs[0]._id;
            console.log("ID " + pdf_id);
            B.update(
                { 'pdfs.pdf_id': pdf_id },
                { $set: {
                    'pdfs.$.title': 'new title'
                }}, function (err, numAffected) {
                    if(err) throw err;
                    assert.equal(numAffected,1);  //KA Boom!
                }
            );

        });
    });
}

test1();

/*
$ node test2.js
Mongoose: docs.remove({}) {}
Mongoose: docs.findOne({}) { fields: { PDFs: 1 }, safe: true }
Mongoose: docs.insert({ __v: 0, PDFs: [ { _id: ObjectId("50930e3d0a39ad162b000002"), title: 'my title' } ], _id: ObjectId("50930e3d0a39ad162b000003") }) { safe: true }
{ _id: 50930e3d0a39ad162b000003,
  PDFs: [ { _id: 50930e3d0a39ad162b000002, title: 'my title' } ] }
ID 50930e3d0a39ad162b000002

assert.js:102
  throw new assert.AssertionError({
        ^
AssertionError: 0 == 1

*/

Answer: You're not using the correct field names in your B.update call.  It should be this instead:
B.update(
    { 'PDFs._id': pdf_id },           // <== here
    { $set: {
        'PDFs.$.title': 'new title'   // <== and here
    }}, function (err, numAffected) {
        if(err) throw err;
        assert.equal(numAffected,1);
    }
);

You should also fix your reset function to not call its callback until the save completes:
function reset(cb) {
  B.find().remove();
  // create some data with a nested document A
  var newA = new A( { title : "my title" })
  var newB = new B( { PDFs: newA});
  newB.save(cb);  // <== call cb when the document is saved
}


Orthogonal complement of vector spaces

Question: Let $V$ be a vector space. Here I do not restrict $V$ to be finite dimensional. Let $S$ be a vector subspace of $V$. Why is $S\subset (S^{\perp})^{\perp}$ rather than $S= (S^{\perp})^{\perp}$?
Comment: $S$ might not be closed. Take $c_0(\Bbb Z)$ the set of finitely nonzero sequences with the $\ell^2$ norm. Then the completion is all of $\ell^2(\Bbb Z)$, so it's not closed. But perp spaces are always closed.
Comment: There are examples where $S$ is closed in $V$, but $S \subsetneq (S^{\perp})^{\perp}$.
Answer: Well, first off, we actually need to assume $V$ is an inner product space with fixed inner product to make sense of orthogonality. Now, an inner product induces a norm, and from this a topology. With respect to this, the orthogonal complement of any set is a closed vector subspace of $V$. So obviously, if $S$ isn't closed in the topology given by the inner product, it cannot be equal to $(S^\perp)^\perp$.
Example: Let $V = \ell_2(\mathbb{N})$ be the space of all sequences of real numbers (I know...I know, complex) that are square-summable, that is $\{a_n\}_{n\in\mathbb{N}}$ such that
$$\sum_{n=1}^\infty a_n^2 < \infty$$
This has an inner product:
$$\langle \{a_n\},\{b_n\}\rangle = \sum_{n=1}^\infty a_nb_n$$
Now consider the subspace of all sequences with only finitely many non-zero entries as $S$. For all $n$, $S$ contains the sequence with a $1$ in the $n$-th place and no other non-zero entries, call this $e_n$. If a sequence $a \perp e_n$ then $a_n = \langle a,e_n\rangle= 0$. So if $a \perp S$ then $a_n = 0$ for all $n$. So $S^\perp$ is just the zero vector, and $(S^\perp)^\perp = V \neq S$.
A worthwhile exercise is to try and prove that this (failure to be closed) is basically the only thing that can go wrong in the sense that $(S^\perp)^\perp = \overline{S}$ in a complete inner product space (that is, a Hilbert space)
Comment: In a Hilbert space you get $(S^{\perp})^{\perp}=\overline{S}$, but this is not true in an incomplete inner-product space $V$.
Comment: @T.A.E. Ah, of course. I've editted to reflect this.

Orthogonal complement of vector spaces


Incorporating a treatment into a classification scheme

Question: I have about 400 pieces of silver of different geometric dimensions. They were assigned to six groups and each group went through a series of stress tests, such as bending, pulling, putting in fire for a period of time, etc. The treatments that were given to the six groups were not the same, but fairly similar. The sizes of the six groups were not the same. The pieces either broke at some stage and that was recorded as a success or didn't, which was recorded as a failure. The time of each success was also recorded. The number of successes was about 80.
My goal is build a predictive model to determine if a piece of silver breaks based on its physical dimensions and the treatment it goes through.
I have been somewhat successful in building a model using the physical dimensions, but adding various aspects of the treatment (eg. total time spent in fire) didn't improve the performance at all. I have even tried to build features (eg.total stress on the metal in various directions, total strain on the metal, etc.)  based on the physical dimensions and the treatment, for each individual piece, but even these didn't add any predictive performance.
How can I incorporate the treatment information in a way that adds to my predictive power? It is clear that the treatment is a factor in whether a piece breaks or not, and it should somehow show up somewhere.
N.B. I didn't have any control over the design of the treatment, and testing more samples with other treatments is not an option for me.
I'd very much appreciate any suggestions or comments.
Many thanks!
Comment: Hi there, what techniques/models have you used so far for analysing your data? Can you also show the variables you used in each model?
Comment: I'd be interested to hear more about anything you may have found using logistic regression, and whether regression diagnostics could shed any light on your problem.  This is a bit of a long shot, but perhaps incorporating nonlinear terms for one or more treatment predictors would help.
Comment: I would try to go at it differently. Do another round of experiments with just one treatment (e.g. bending) and with enough variation. Make it simple enough that you know there is a rule, and that you actually know what the rule is (e.g. bending force > X => success). You can then pick features you think are reasonable and try them on this new set. You will then be able to debug your algorithm and your features until you get something that works. You know what it should look like on this simple set. You can then use these features on the old set and see how well they work.
Comment: Hi Michelle, I've tried almost every classification scheme that I could get my hands on off the shelf, but Naive Bayes seems to work best. I'm not quite sure what you mean by the list of variables. Are you referring to those coming from the treatment? For the treatment variables, I've tried everything I could think of: number hours being bent, maximum heat, maximum pressure. Anything I could think of.
Comment: Hi rolando2. I got perhaps the poorest results from using logistic regression. I have no idea why. Regularized logistic regression did much better. I didn't use any nonlinear terms though.
Comment: When you say "it is clear the treatment is a factor", what is this based on? Would a human be able to come up with a rule for the success rate based on treatment?
Comment: Hi SheldonCooper. To compare two extremes, if the treatment is to pull the piece of silver with a very large force that exceeds the tolerance of every one of my 600 pieces, then every piece will eventually break, so the success rate is 100% in this case. On the other hand, if I do absolutely nothing to each piece, the success rate is 0%. In these simple cases we can say, by just looking at the treatments, what the success rates are going to be. However, if the treatment is very complicated, I'm not sure how a human can come up with a rule. I hope I understood your question correctly.
Comment: Were these extremes present in the actual experiments? Were they present in a large enough fraction of cases to notice any increase in predictive power of your model? As an analogy, consider how ambient temperature influences human life. If the temeprature is an absolute zero a person would freeze, and if the temperature is 1000K, the person would burn. But if you only collected samples at temperatures between 60F and 80F, you won't see any of these effects. If you collected 400 samples and only two were at extreme temperatures, your prediction rate would improve by only 0.5%.
Comment: No, there wasn't that much variation in the actual experiments. My suspicion is that that is the reason I don't see much improvement in prediction by adding the treatments in the ways I've added them so far. I'm wondering if there is a way to magnify the differences between the various treatments though.
Comment: What seems most reasonable to me is computing the stress the treatment causes and using it as feature. E.g. sample was bent; you compute the max force and duration, then use 3 features: force, duration, and force times duration. You did that already and it didn't work. I suspect this is because there isn't enough variation in the experiments. But it may also be that you didn't try the right set of features. Unfortunately, there aren't many guidelines to design features. I can dream up a bunch of things (you probably can too), but it's a matter of trial and error to pick the right ones.
Comment: I wish I could do another round of experiments, but as I mentioned in the question, that's not possible.
Answer: You might try some tree based models, such as randomForest or GBM in R.  Both models are good at picking up non-linear effects and interactions, and both also produce variable importance measures that will probably be useful in your analysis.
GBM in particular might be useful, as it fits each successive tree to the residuals of the model.  In this way, after the model captures the effects of geometric dimensions, it will explore how the various treatments might be used to explain the "leftover" (or residual) variance. On the other hand, random forests require very little tuning and are harder to screw up than GBM models.
I would make sure each treatment is its set of variables, e.g. total time in fire, min/mean/median/max/cumulative bending and pulling pressure, etc.  Particularly in GBM models, more variables are better, so be thorough!
How are you measuring how "good" your models are?  Are you cross-validating them?
Comment: Thank you Zach. I've tried random forests (though not in R), and it doesn't work that great. In fact, none of the tree-based methods have worked that great. I haven't tried GBM though. I'm not sure what you mean by "in GBM models, more variables are better". Does that mean that overfitting doesn't happen in GBM? I'm using 10 runs of 10-fold CV to validate my models. I'm using AUC and also partial AUC as my measure of performance. I don't really think a particular algorithm is the answer.
Comment: I think you should give GBM a shot.  GBMs will eventually overfit, depending on how many trees you use.  The GBM algorithm in R has built-in cross validation to tune the number of trees to prevent this.  Try using the `bernoulli` and `adaboost` distributions.  If no algorithm is working well, you need to re-examine your research question and see if there's any important variables you are missing.  Did you make sure your random forest was a classification, rather than a regression forest?
Comment: Sure, I'll give it a shot. But I think a more fundamental approach would be to somehow amplify small differences between the treatments so that one can use them more effectively in the classification scheme.
Comment: @user765195: Well, you could code the different treatments as a categorical variable (e.g. treatment 1 is 10 minutes in fire, treatment 2 is 20 minutes in fire, treatment 3 is 10 lbs of pulling pressure, etc.).  If there are significant differences among treatments, this would let your model pick them up.  However, if most of the failures can be explained by geometry rather than treatment, this is going to be very hard.  Could you post some sample data?
Comment: Hi Zach. The treatments are a lot more complicated than what you describe. They're combinations of actions performed for various lengths of time, and each treatment was the same for the a group, but different groups went through different treatments. The problem is that most of the failures can't be explained by geometry (some can). The goal is to add the treatment to the classification features somehow to make the classification more accurate.
Comment: @user765195 How many total treatments are we looking at?  Did any groups receive multiple treatments? Some example data would be really useful in answering this question.
Comment: Zach, here is an example.
Subject ID, Group, Length, Height, Width
1 , 3, 20in, 5in, 4in
2, 4, 18in, 4.5in, 3.7in
....
400, 1, 17in, 3.7in, 4.2in

and for treatments, the following, in the specified order
Group 1
1- Pulling by a force of 10lb, 5 minutes
2- Fire, 500 degrees, 1 hour
Comment: Zach, here is an example.
Subject ID, Group, Length, Height, Width//
1 , 3, 20in, 5in, 4in//
2, 4, 18in, 4.5in, 3.7in//
....//
400, 1, 17in, 3.7in, 4.2in//

/and for treatments, the following, in the specified order://
Group 1//
1- Pulling by a force of 300lb, 5 minutes
2- Fire, 500 degrees, 1 hour
3- Pressed by a force of 500lbs, 1 hour
etc. //

Group 2//
1 - Fire, 550 degrees, 45 minutes
2 - Pressed by a force of 540 lbs, 1 hour 15 minutes
3 - Pulling by a force of 380 lbs, 20 minutes,
etc. //
and you can imagine a similar pattern for the other groups.
Answer: The functional form of the model is going to be very important here. In fact there might be interaction effects between the treatments (sensitivity of breaking to bending might depend on whether it has been put through fire before) and hence you need to use a non-linear functional form
So, instead of a form like: $$y=\beta_{fire}x_{fire}+ \beta_{bending}x_{bending} + .. $$ you might want to use a form: $$y=\beta_{bending-fire}x_{bending}x_{fire} + ..+\beta_{fire}x_{fire}+ \beta_{bending}x_{bending} + .. $$
You should start with this simple linear model and then move on to random forests since they will automatically create these interactions if they are important


Best way to implement keyboard shortcuts in a Windows Forms application?

Question: I'm looking for a best way to implement common Windows keyboard shortcuts (for example Ctrl+F, Ctrl+N) in my Windows Forms application in C#.
The application has a main form which hosts many child forms (one at a time). When a user hits Ctrl+F, I'd like to show a custom search form. The search form would depend on the current open child form in the application.
I was thinking of using something like this in the ChildForm_KeyDown event:
   if (e.KeyCode == Keys.F && Control.ModifierKeys == Keys.Control)
        // Show search form

But this doesn't work. The event doesn't even fire when you press a key. What is the solution?
Comment: It's really strange that Winforms doesn't seem to have specific functionality for this like the native Windows API does.
Answer: You probably forgot to set the form's KeyPreview property to True. Overriding the ProcessCmdKey() method is the generic solution:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
  if (keyData == (Keys.Control | Keys.F)) {
    MessageBox.Show("What the Ctrl+F?");
    return true;
  }
  return base.ProcessCmdKey(ref msg, keyData);
}

Comment: "What the Ctrl+F?"    LOL
Comment: This works well, but only detects it for me if the form is the active window. Anyone know how to bind it so in any window view it is possible?
Comment: Hmm, no, the Form's KeyDown event handler is quite distinct from a menu item's Click event handler.  You still do the exact same way, either call the event handler method directly (no need for it to be exclusively called by an event) or refactor the common logic into a separate method.
Comment: In some situations `KeyPreview` is quite indispensable. For example, when pressing a shortcut is required to suppress input but nevertheless to allow a separate `MenuStrip` event to fire. `ProcessCmdKey` approach would force the duplication of event firing logic.
Answer: On your Main form

Set KeyPreview to True
Add KeyDown event handler with the following code
private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Control && e.KeyCode == Keys.N)
    {
        SearchForm searchForm = new SearchForm();
        searchForm.Show();
    }
}

Comment: + for , Set KeyPreview to True .. was missing that
Answer: The best way is to use menu mnemonics, i.e. to have menu entries in your main form that get assigned the keyboard shortcut you want. Then everything else is handled internally and all you have to do is to implement the appropriate action that gets executed in the Click event handler of that menu entry.
Comment: The problem is that main form doesn't use common windows menus. It uses custom navigation panel that is used to show child forms. The search forms are invoked by click on the ToolStripButton on the child form.
Comment: @Kiquenet https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.menuitem.mnemonic?view=netframework-4.7.2
Comment: Mnemonics are a distinct concept from shortcut keys, and there are important differences in how they operate.  In short, mnemonics are the underlined characters used to access menus, menu commands and dialog controls using the keyboard.  OTOH, shortcut keys are a way to access commands without going through the menus, and moreover they can be arbitrary keystrokes like Ctrl+F or F5, not restricted to character keys.
Comment: @Stewart That is correct! My answer wasn't trying to imply that all keyboard shortcuts are mnemonics, merely that menu mnemonics is the easiest way of getting this functionality. Unfortunately, as Rockcoder's comment clarifies, this solution doesn't seem appropriate here. I still recommend it as the preferable solution, where possible. For a general solution, Hans' accepted answer is the way forward.
Comment: `menu mnemonics` real sample?
Answer: You can even try this example:
public class MDIParent : System.Windows.Forms.Form
{
    public bool NextTab()
    {
         // some code
    }

    public bool PreviousTab()
    {
         // some code
    }

    protected override bool ProcessCmdKey(ref Message message, Keys keys)
    {
        switch (keys)
        {
            case Keys.Control | Keys.Tab:
              {
                NextTab();
                return true;
              }
            case Keys.Control | Keys.Shift | Keys.Tab:
              {
                PreviousTab();
                return true;
              }
        }
        return base.ProcessCmdKey(ref message, keys);
    }
}

public class mySecondForm : System.Windows.Forms.Form
{
    // some code...
}

Answer: If you have a menu then changing ShortcutKeys property of the ToolStripMenuItem should do the trick.
If not, you could create one and set its visible property to false.
Comment: No I do't have a menu. ToolStripButton for search is actually located on the BindingNavigator control, so adding a menu is probably not an option.
Answer: From the main Form, you have to:

Be sure you set KeyPreview to true( TRUE by default)
Add MainForm_KeyDown(..) - by which you can set here any shortcuts you want.

Additionally,I have found this on google and I wanted to share this to those who are still searching for answers. (for global)
I think you have to be using user32.dll
protected override void WndProc(ref Message m)
{
    base.WndProc(ref m);

    if (m.Msg == 0x0312)
    {
        /* Note that the three lines below are not needed if you only want to register one hotkey.
         * The below lines are useful in case you want to register multiple keys, which you can use a switch with the id as argument, or if you want to know which key/modifier was pressed for some particular reason. */

        Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);                  // The key of the hotkey that was pressed.
        KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);       // The modifier of the hotkey that was pressed.
        int id = m.WParam.ToInt32();                                        // The id of the hotkey that was pressed.

        MessageBox.Show("Hotkey has been pressed!");
        // do something
    }
}

Further read this http://www.fluxbytes.com/csharp/how-to-register-a-global-hotkey-for-your-application-in-c/
Answer: Hans's answer could be made a little easier for someone new to this, so here is my version.
You do not need to fool with KeyPreview, leave it set to false. To use the code below, just paste it below your form1_load and run with F5 to see it work:
protected override void OnKeyPress(KeyPressEventArgs ex)
{
    string xo = ex.KeyChar.ToString();

    if (xo == "q") //You pressed "q" key on the keyboard
    {
        Form2 f2 = new Form2();
        f2.Show();
    }
}

Comment: First, overriding ProcessCmdKey is the recommended way of handling a keystroke intended to do some command-like operation, which is what the OP was asking about. Second, you've misunderstood Hans' comment about setting KeyPreview to true; he was just telling the OP why his technique wasn't working. Setting KeyPreview to true is not needed for using ProcessCmdKey.
Answer: In WinForm, we can always get the Control Key status by:
bool IsCtrlPressed = (Control.ModifierKeys & Keys.Control) != 0;

Answer: The VB.NET version of Hans' answer.
(There's a ProcessCmdKey function template in Visual Studio.)
  Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean

    If (keyData = (Keys.Control Or Keys.F)) Then
      ' call your sub here, like
      SearchDialog()
      Return True
    End If

    Return MyBase.ProcessCmdKey(msg, keyData)
  End Function

End Class


How to debug and fix error [fcgid:warn] (OS 109)The pipe has been ended , get overlap result error, [core:error] End of script output before headers

Question: I'm using :

Drupal 8 on Acquia DevDesktop version 2 with php 7.0.15.
php_mode is set to FAST CGI (mod_fcgid).
Info from the phpinfo() Apache/2.4.18 (Win32) OpenSSL/1.0.2j mod_fcgid/2.3.9

The problem is I'm getting 500 internal errors very frequently.
In the apache log this is displayed for each 500 error log as follows
[Thu Nov 09 09:24:36.140248 2017] [fcgid:warn] [pid 17112:tid 1268] (OS 109)The pipe has been ended.  : [client 127.0.0.1:56192] mod_fcgid: get overlap result error, referer: http://inzicht5.dd:8083/

[Thu Nov 09 09:24:36.140750 2017] [core:error] [pid 17112:tid 1268] [client 127.0.0.1:56192] End of script output before headers: index.php, referer: http://inzicht5.dd:8083/

Therefore I added into php.ini
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

And I added in php.ini
error_log = C:\php_errors.log

Activated error.log in php.ini. Checked by  phpinfo(). But still no php error is shown up. Yes, I restarted the server
I already installed MS distribution C++ 2015 version 14.024215
But still I do not get more information. Also I googled a lot of sites for this error but none of them are giving me directions.
How to get more debug information about this error?
How to solve it?
Comment: Looks like it's a known bug in dev desktop: https://forums.acquia.com/acquia-products-and-services/dev-desktop/internal-server-error
Answer: This issue should be fixed in the newest Varbase release. See: https://www.drupal.org/node/2912709
Comment: Yes, this works
Comment: Sorry mistake, it is not working. I tested with drupal only site, It is not related to varbase


Undefined symbol while using Keil IDE

Question: I am using Nordic nRF51-DK SDK_11 and the soft device s130.
I encountered the following error while adding device manager. I'm using Keil compiler.

._build\nrf51422_xxac_s130.axf: Error: L6218E: Undefined symbol
  dm_init (referred from main.o). ._build\nrf51422_xxac_s130.axf: Error:
  L6218E: Undefined symbol dm_register (referred from main.o). Not
  enough information to list image symbols.

I have included device_manager.h in the PATHS. Using Keil, I did it by going to Menu->Flash->Configure Flash Tools ... -> Include Paths -> Add components\ble\device_manager
What else did I miss out?
Comment: The header that you seem to have included and made its path known to the compiler is normally only *declaring* a function. It needs to be *defined* somewhere (the "real code") - That would normally be in an object file or library that **you need to link** your code with.
Answer: Depending on the SDK version you want to use you need to compile and link device_manager_peripheral.c. For NRF5 SDK version 11.0.0 it resides in the folder <path to sdk>/nRF5_SDK_11/components/ble/device_manager.
You can find a tutorial here.

Undefined symbol while using Keil IDE


Weak convergence of normalized random sum

Question: Suppose $X_k$ are independent mean 0 random variables with finite positive variance. Can it be true that $\dfrac{S_n}{\sqrt{\operatorname{Var}(S_n)}}$ does not converge weakly? Here $S_n=\sum_{k=1}^n X_k$.
Almost all the examples I am thinking of, are where the Gaussian limit is not achieved. But is it necessary for the ratio to have a limiting distribution? I guess not, but a hint would be good.
Comment: Just let $X_{n+1}$ have a magnitude that completely dominates the sum of all previous, with a distribution of your choice. So, for example, $\frac{S_n}{\sqrt{Var(S_n)}} \approx \frac{X_n}{\sqrt{Var(X_n)}}$.
Answer: Notice that $\left(\frac{S_{n}}{\sqrt{\operatorname{Var}\left(S_{n}\right)}}\right)_{n\geqslant 1}$ is centered and has variance one, hence this sequence is tight and admits a convergent subsequence. Here the point is that the limit law can be different.
Let $U$ and $V$ be two random variables having variance one and expectation zero; let $\left(Y_i\right)_{i\geqslant 1}$ an independent sequence such that for all $i$, $Y_{2i}$ has the same law as $U$ and $Y_{2i+1}$ the same as $V$. Finally, let $\left(c_i\right)_{i\geqslant 1}$ be a sequence of real numbers such that
$$
\frac{\sum_{i=1}^{n-1}c_i^2}{ c_n^2}\to 0
$$
and $X_{i}=c_iY_i$. Then
$$
\frac{S_{2n}}{\sqrt{\operatorname{Var}\left(S_{2n}\right)}}\to U\mbox{ and }\frac{S_{2n+1}}{\sqrt{\operatorname{Var}\left(S_{2n+1}\right)}}\to V.
$$


yahoo pipes How can i swap title and description

Question: I was creating a RSS feed using yahoo pipes but i want title in description and description in title. I want to swap the title and description.
<item>
<title>"**title**"</title>
<description>"**description**"</description>
<link>http://link</link>
</item>

I want
<item>
<title>"**description**"</title>
<description>"**title**"</description>
<link>http://link</link>
</item>

Answer: Here's one way you can do it - using 3 Pipes modules to swap the title and description fields:

Fetch Feed: Pull in the RSS feed. I'm using a Yahoo Finance feed as a sample.
Rename: Make a copy of item.title as newDesc, and item.description as newTitle
Create RSS: Set title to newTitle, description to newDesc, others as default values

I created a sample pipe you can view and copy from: http://pipes.yahoo.com/pipes/pipe.info?_id=ffc846056c71a4dd3df7b01d16fdd613
Here's a sample from the original Yahoo Finance RSS feed:
<item>
    <title>Samsung Posts $7.4B Profit as Handsets Mask Weak Chip Sales</title>
    <link>http://us.rd.yahoo.com/finance/news/rss/story/SIG=149kpevtc/*http%3A//us.rd.yahoo.com/finance/news/topfinstories/SIG=126hhlj6u/*http%3A//finance.yahoo.com/news/samsung-posts-7-4-bln-234859667.html?l=1</link>
    <description>Samsung Electronics Co., the world's top technology firm by revenue, reported record quarterly profit of $7.4 billion on Friday, with strong sales of its Galaxy range of phones masking sharply lower memory chip sales.</description>
    <guid isPermaLink="false">yahoo_finance/1866191516</guid>
    <pubDate>Fri, 26 Oct 12 00:55:44 GMT</pubDate>
</item>

...and here's the corresponding output from the sample pipe, with title & description swapped:
<item>
     <title>Samsung Electronics Co., the world's top technology firm by revenue, reported record quarterly profit of $7.4 billion on Friday, with strong sales of its Galaxy range of phones masking sharply lower memory chip sales.</title>
     <link>http://us.rd.yahoo.com/finance/news/rss/story/SIG=149kpevtc/*http%3A//us.rd.yahoo.com/finance/news/topfinstories/SIG=126hhlj6u/*http%3A//finance.yahoo.com/news/samsung-posts-7-4-bln-234859667.html?l=1</link>
     <description>Samsung Posts $7.4B Profit as Handsets Mask Weak Chip Sales</description>
     <guid isPermaLink="false">yahoo_finance/1866191516</guid>
     <pubDate>Sat, 30 Mar 1918 19:36:14 +0000</pubDate>
  </item>

Note: in my sample above something happened to the pubDate. I think it might be a Yahoo Pipes caching issue that will clear up the next time the pipe runs.


Writing ARCH process as AR process

Question: How can I show that the ARCH(1) process for $y$:
$$y_t=\varepsilon_t=z_t\sigma_t$$
$$\sigma^2_t=\omega+\alpha y^2_{t-1}$$
is actually AR(1) process for $y$:
$$y^2_t=\omega+\alpha y^2_{t-1}+v_t$$
where, $v_t=\sigma^2_t(z^2_t-1)$
I know it is pretty straightforward, but I don't really understand what is this $v_t$ term we are introducing and how can we interpret it in this context?
My calculations:
$y^2_t=z^2_t \sigma^2_t$
$y^2_t=z^2_t(\omega+\alpha y^2_{t-1})$
$z^2_t\sigma^2_t=z^2_t(\omega+\alpha y^2_{t-1})$
$v_t=y^2_t-E(y^2_t|I_{t-1})=y^2_t-\sigma^2_t$
$y^2_t-v_t=\omega+\alpha y^2_{t-1}$
$y^2_t=\omega+\alpha y^2_{t-1}+y^2_t-\sigma^2_t$
$y^2_t=\omega+\alpha y^2_{t-1}+z^2_t\sigma^2_t-\sigma^2_t$
$y^2_t=\omega+\alpha y^2_{t-1}+\sigma^2_t(z^2_t-1)$
Answer: In an AR(1) model we have the error $\varepsilon_t$ satisfying
$$ \varepsilon_t = y_t - \mu_t, $$
where $\mu_t = \varphi y_{t-1}$ is the expected value of $y_t$ given the information available at time $t-1$.
Similarly, in an ARCH(1) model we have the error $v_t$ satisfying
$$ v_t = y_t^2 - \sigma_t^2, $$
where $\sigma_t^2 = \mathbb{E}(y_t^2-\mathbb{E}(y_t)^2) = \mathbb{E}(y_t^2-0) = \mathbb{E}(y_t^2)$ is the expected value of $y_t^2$ given the information available at time $t-1$. So that is the analogy between $\varepsilon_t$ and $v_t$ in AR(1) and ARCH(1) models, respectively.

but I don't really understand what is this $v_t$ term we are introducing and how can we interpret it in this context?

$v_t$ is the deviation of $y_t^2$ from its conditional mean given the information available at time $t-1$ -- similarly as to how $\varepsilon_t$ is the deviation of $y_t$ from its conditional mean.
Comment: Thank you for the detailed answer, it is not as complicated as I thought
Comment: @lovetimberland, I am glad I could help!

Writing ARCH process as AR process


How to compare equality of the distribution at different quantiles

Question: I have a dataset from which I am taking a set of descriptive statistics as follows:
The value measured is productivity of a firm for each of the group at different quantile (I use Stata command: table group_var, c(p10 p25 p50... ).
The below is repeated for two subsets of the main data (I have two sets of descriptive stats as below).
              p10   p25   p50   p75   p90
group1        50    45    43    34    10
group2         ......

What I want to do is to compare the two descriptive stats for statistical significance:
so there will be:
       p10_1   p10_2
group1  50       52
group2  52      ....
....

I want to determine whether these are different, for p50 I am using a ranksum (median) test in stata. for mean, running a t-test but struggle to find a method for values at different quantiles. Can someone suggest the right approach?
Thanks,
Paul
Comment: "Whether these are different" is ambiguous, so it will help to present a clearer statement of your null hypothesis.  For instance, would it be $$H_0: F_{.10}=G_{.10}\text{ and } F_{.25}=G_{.25}\text{ and }\cdots\text{ and } F_{.90}=G_{.90}$$ where $F$ and $G$ are the two distributions and the subscripts represent their quantiles?  With just your summaries, this will be both difficult to test and not very powerful.  Do you have the original data?
Answer: You can do this using quantile regression.
The code below does the single quantile case. It

estimates the q90 price for foreign and domestic cars with various repair records. Here origin is like your two cities and repair record is like your groups.
calculates the statistics within each origin $\times$ repair cell from the model, which should match the output of the table command.
tests the hypothesis that the q90 prices for each group are the same regardless of manufacturing origin.

Here's the output:
. sysuse auto, clear
(1978 automobile data)

. table rep78 foreign, statistic(p90 price) nototals

----------------------------------------
                   |      Car origin
                   |  Domestic   Foreign
-------------------+--------------------
Repair record 1978 |
  1                |      4934
  2                |     14500
  3                |     13466      6295
  4                |      8814      9735
  5                |      4425     11995
----------------------------------------

. keep if rep78>2 & !missing(rep78)
(15 observations deleted)

. qreg price i.rep78##i.foreign, quantile(0.9) nolog

.9 Quantile regression                              Number of obs =         59
  Raw sum of deviations  39983.8 (about 11385)
  Min sum of deviations  32468.6                    Pseudo R2     =     0.1880

-------------------------------------------------------------------------------
        price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
--------------+----------------------------------------------------------------
        rep78 |
           4  |      -4652   2130.507    -2.18   0.033    -8925.256    -378.744
           5  |      -9041   4056.365    -2.23   0.030    -17177.04   -904.9629
              |
      foreign |
     Foreign  |      -7171   3368.627    -2.13   0.038    -13927.61   -414.3889
              |
rep78#foreign |
   4#Foreign  |       8092   4261.014     1.90   0.063    -454.5121    16638.51
   5#Foreign  |      14741   5483.728     2.69   0.010     3742.034    25739.97
              |
        _cons |      13466   1065.254    12.64   0.000     11329.37    15602.63
-------------------------------------------------------------------------------

. margins foreign#rep78, post // coeflegend
warning: cannot perform check for estimable functions.

Adjusted predictions                                        Number of obs = 59
Model VCE: IID

Expression: Linear prediction, predict()

-------------------------------------------------------------------------------
              |            Delta-method
              |     Margin   std. err.      z    P>|z|     [95% conf. interval]
--------------+----------------------------------------------------------------
foreign#rep78 |
  Domestic#3  |      13466   1065.254    12.64   0.000     11378.14    15553.86
  Domestic#4  |       8814   1845.073     4.78   0.000     5197.723    12430.28
  Domestic#5  |       4425   3913.991     1.13   0.258    -3246.282    12096.28
   Foreign#3  |       6295   3195.761     1.97   0.049     31.42429    12558.58
   Foreign#4  |       9735   1845.073     5.28   0.000     6118.723    13351.28
   Foreign#5  |      11995   1845.073     6.50   0.000     8378.723    15611.28
-------------------------------------------------------------------------------

. test ///
> (_b[0.foreign#3.rep78] = _b[1.foreign#3.rep78]) ///
> (_b[0.foreign#4.rep78] = _b[1.foreign#4.rep78]) ///
> (_b[0.foreign#5.rep78] = _b[1.foreign#5.rep78])

 ( 1)  0bn.foreign#3bn.rep78 - 1.foreign#3bn.rep78 = 0
 ( 2)  0bn.foreign#4.rep78 - 1.foreign#4.rep78 = 0
 ( 3)  0bn.foreign#5.rep78 - 1.foreign#5.rep78 = 0

           chi2(  3) =    7.72
         Prob > chi2 =    0.0522

The p-value on the two-sided null that the q90 foreign and domestic prices are the same for repair record 3, the same for 4, and the same for 5 is .0522. This means that it is fairly unlikely that we would observe differences like this (or larger) if they were the same for each repair record group.
But you want to test more than one quantile at the same time, so you need to use sqreg for simultaneous-quantile regression. It produces the same coefficients as qreg for each quantile.  Reported standard errors will be similar, but sqreg obtains an estimate of the VCE via bootstrapping, and the VCE includes between-quantile blocks. This lets you do tests comparing predictions at different quantiles:
. sysuse auto, clear
(1978 automobile data)

. table rep78 foreign, stat(p50 price) statistic(p90 price)  nototals

-----------------------------------------
                    |      Car origin
                    |  Domestic   Foreign
--------------------+--------------------
Repair record 1978  |
  1                 |
    50th percentile |    4564.5
    90th percentile |      4934
  2                 |
    50th percentile |      4638
    90th percentile |     14500
  3                 |
    50th percentile |      4749      4296
    90th percentile |     13466      6295
  4                 |
    50th percentile |      5705      6229
    90th percentile |      8814      9735
  5                 |
    50th percentile |    4204.5      5719
    90th percentile |      4425     11995
-----------------------------------------

. keep if rep78>2 & !missing(rep78)
(15 observations deleted)

. sqreg price i.rep78##i.foreign, quantile(0.5 0.9) nolog

Simultaneous quantile regression                    Number of obs =         59
  bootstrap(20) SEs                                 .50 Pseudo R2 =     0.0574
                                                    .90 Pseudo R2 =     0.1880

-------------------------------------------------------------------------------
              |              Bootstrap
        price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
--------------+----------------------------------------------------------------
q50           |
        rep78 |
           4  |        956   410.4789     2.33   0.024     132.6835    1779.316
           5  |       -324   358.3828    -0.90   0.370    -1042.825    394.8248
              |
      foreign |
     Foreign  |       -453   1002.362    -0.45   0.653    -2463.483    1557.483
              |
rep78#foreign |
   4#Foreign  |        977   1286.285     0.76   0.451    -1602.962    3556.962
   5#Foreign  |       1747   1127.146     1.55   0.127    -513.7688    4007.769
              |
        _cons |       4749   326.4424    14.55   0.000      4094.24     5403.76
--------------+----------------------------------------------------------------
q90           |
        rep78 |
           4  |      -4652   1808.008    -2.57   0.013    -8278.405   -1025.595
           5  |      -9041   1618.042    -5.59   0.000    -12286.38   -5795.619
              |
      foreign |
     Foreign  |      -7171   2282.641    -3.14   0.003     -11749.4   -2592.601
              |
rep78#foreign |
   4#Foreign  |       8092    2949.62     2.74   0.008     2175.812    14008.19
   5#Foreign  |      14741     2256.1     6.53   0.000     10215.84    19266.16
              |
        _cons |      13466   1601.298     8.41   0.000      10254.2     16677.8
-------------------------------------------------------------------------------

. margins foreign#rep78, predict(equation(q50)) predict(equation(q90)) post // coeflegend

Adjusted predictions                                        Number of obs = 59
Model VCE: Bootstrap

1._predict: Linear prediction, predict(equation(q50))
2._predict: Linear prediction, predict(equation(q90))

----------------------------------------------------------------------------------------
                       |            Delta-method
                       |     Margin   std. err.      z    P>|z|     [95% conf. interval]
-----------------------+----------------------------------------------------------------
_predict#foreign#rep78 |
         1#Domestic#3  |       4749   326.4424    14.55   0.000     4109.185    5388.815
         1#Domestic#4  |       5705   330.9142    17.24   0.000      5056.42     6353.58
         1#Domestic#5  |       4425   221.6575    19.96   0.000     3990.559    4859.441
          1#Foreign#3  |       4296   975.0888     4.41   0.000     2384.861    6207.139
          1#Foreign#4  |       6229   860.8888     7.24   0.000     4541.689    7916.311
          1#Foreign#5  |       5719   990.1683     5.78   0.000     3778.306    7659.694
         2#Domestic#3  |      13466   1601.298     8.41   0.000     10327.51    16604.49
         2#Domestic#4  |       8814   1048.677     8.40   0.000     6758.631    10869.37
         2#Domestic#5  |       4425   221.6575    19.96   0.000     3990.559    4859.441
          2#Foreign#3  |       6295   1123.791     5.60   0.000     4092.411    8497.589
          2#Foreign#4  |       9735   1285.327     7.57   0.000     7215.806    12254.19
          2#Foreign#5  |      11995   1902.861     6.30   0.000     8265.462    15724.54
----------------------------------------------------------------------------------------

. test ///
> (_b[1._predict#0.foreign#3.rep78] = _b[1._predict#1.foreign#3.rep78]) ///
> (_b[1._predict#0.foreign#4.rep78] = _b[1._predict#1.foreign#4.rep78]) ///
> (_b[1._predict#0.foreign#5.rep78] = _b[1._predict#1.foreign#5.rep78]) ///
> (_b[2._predict#0.foreign#3.rep78] = _b[2._predict#1.foreign#3.rep78]) ///
> (_b[2._predict#0.foreign#4.rep78] = _b[2._predict#1.foreign#4.rep78]) ///
> (_b[2._predict#0.foreign#5.rep78] = _b[2._predict#1.foreign#5.rep78])

 ( 1)  1bn._predict#0bn.foreign#3bn.rep78 - 1bn._predict#1.foreign#3bn.rep78 = 0
 ( 2)  1bn._predict#0bn.foreign#4.rep78 - 1bn._predict#1.foreign#4.rep78 = 0
 ( 3)  1bn._predict#0bn.foreign#5.rep78 - 1bn._predict#1.foreign#5.rep78 = 0
 ( 4)  2._predict#0bn.foreign#3bn.rep78 - 2._predict#1.foreign#3bn.rep78 = 0
 ( 5)  2._predict#0bn.foreign#4.rep78 - 2._predict#1.foreign#4.rep78 = 0
 ( 6)  2._predict#0bn.foreign#5.rep78 - 2._predict#1.foreign#5.rep78 = 0

           chi2(  6) =   50.71
         Prob > chi2 =    0.0000

The factor variable notation above is tricky, but it is just quantile $\times$ origin $\times$ repair record level. The coeflegend can be useful here for decoding, but I left it commented out.
Here we reject the two-sided null that the q50 and q90 foreign and domestic prices are the same for repair record 3, the same for 4, and the same for 5: the p-value is effectively zero.
Comment: But this is testing if these groups are different, and this is not what I am after. I want to test if the cities are different for all the given descriptive stats. each city will have a group, let's say size, and there will be multiple sizes and productivity will be different by each size band ( group1 - 20, group 2- 30, group 3 - 28 etc.). What I end up with is a set of descriptive stats of those size bands for each city - and I want to check whether these two are different at different q25 and q75. it sounds like taking your approach require comparing 2 regressions (if 2 cities to compare)
Comment: @dimitry Stata command version 16: table group_var, c(p10 p25 p50... ) generates let's say 15 different groups, so for every p10 I am going to have 15 different values. What I meant there is to compare these 15 values at p10 to another 15 values at p10 from another subset (e.g. city). Your test would be fine if I was comparing just a single value at p10 - but I can have group 1 to group 15 for one city and group 1 - 15 for another city. Then will have these at q5 a10 q25 etc.
Comment: It's straightforward to test the joint hypothesis. You just need to type out all the terms, so something like `test _b[1.group] = _b[2.group] = ... =_b[15.group]`.
Comment: Or equivalently `margins group, post contrast` without `test` after.
Comment: I've made some edits in response to your comments. If I am still not getting what you have in mind, edit your question with more details about the structure of your data and the problem and I can take another look.
Comment: works good. thanks!
Comment: The asymmetry of this procedure makes it suspect: which of the two groups should be selected as the explanatory variable and which as the response?
Comment: @whuber I have all group x city (or repair record x origin) cells as explanatory variables and price as the response/outcome. Could you elaborate on what is suspect in that?
Comment: As far as I can tell, the question asks to test a hypothesis of the form I  articulated in a comment to the question.  I cannot see how this quantile regression correctly addresses that kind of test.  Perhaps the evidence is buried in the details of the Stata output, but frankly I don't want to wade through that in order to understand what you propose.
Comment: @whuber I am doing your comment version in the second part at the bottom, though for two different quantiles. I broke it up for didactic purposes.
Comment: The information is buried in the (arcane) Stata commands.  How, specifically, are you doing the multiple testing?  How are you accounting for the lack of independence among the various quantiles of each distribution?
Comment: @whuber I added that info above. Let me know if it passes muster!
Comment: Got it--thank you! (+1)
Answer: Instead of making quantiles, use the Kolmogorov-Smirnov test.
Comment: I am adding these quantiles as my summary stats to a paper and wanted to assess their equality. The test mentioned doesn't allow me to check the values at different quantiles for given groups but would perform a test on the entire two samples
Comment: For the paper, you could show the K-S graph. See: https://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_test. This is definitely statistically better than quantizing then testing. However, depending on the journal, your readers might not understand this!


Como adicionar uma borda em uma imagem com C#

Question: Gostaria de pegar uma imagem e adicionar uma borda na parte superior da imagem(BMP).
Pelo que eu pesquisei preciso

carregar a imagem em um objecto
criar um objeto retângulo
adicionar o retângulo na imagem

mas eu nunca trabalhei com imagem no C# :(
Exemplo:
Essa imagem

para ficar assim
Comment: Veja se isso pode te ajudar http://stackoverflow.com/a/14593261/2221388
Comment: `WinForms` ou `WPF`?
Comment: Estou fazendo um serviço de windows, este método vou colocar em uma biblioteca.
Comment: @PabloVargas este exemplo a borda sobrepõe  a imagem, eu quero adicionar uma borda.
Comment: @Fellipe Você quer inserir essa borda "dentro" da imagem? Ou seja, editar o próprio arquivo bmp?
Comment: @ismael era uma opção, mas decidi criar um outro arquivo concatenando duas imagens. Deixei uma borda padrão para ser adicionada nas imagens.
Answer: Olá, seria só alterar os tamanhos dos px da border não?!
border-image-width: 10px 10px  10px 10px;
          (cima) (direita) (baixo)  (esquerda)
Answer: Consegui resolver este problema concatenando duas imagens.
<code>            Image principal = Image.FromFile(@"ImagemPrincipal.jpg");
            Image logo = Image.FromFile(@"ImagemHeader.jpg");

            int imagemSaida_Width = principal.Width;
            int imagemSaida_Height = principal.Height + logo.Height;

            var imagemSaida = new Bitmap(imagemSaida_Width, imagemSaida_Height);

            using (principal)
            {
                using (imagemSaida)
                {
                    using (var canvas = Graphics.FromImage(imagemSaida))
                    {

                        canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        // Definir plano de funda do arquivo de saida como Branco
                        canvas.Clear(Color.White);

                        // Adicionar o logo no arquivo de saida
                        canvas.DrawImage(logo, 0, 0);

                        // Adidionar principal no arquivo de saida
                        canvas.DrawImage(exame, 0, logo.Height);
                        canvas.Save();
                    }
                    imagemSaida.Save("ImagePrincipalComLogo.jpg");
                }
            }
</code>


Applying force on box2d body not working

Question: I am trying to move a body by applying force on it. But instead of moving in horizontal direction and making a trajectory, it is just falling down like i have not applied force on it. Here is the code:
<code>public class Box2dTest implements ApplicationListener
{
    private OrthographicCamera camera;
    World box2Dworld;
    Box2DDebugRenderer debugRenderer;
    private Body box2dBody;
    Sprite ball_sprite;
    SpriteBatch spriteBatch;

    @Override
    public void create()
    {
        camera = new OrthographicCamera();
        camera.setToOrtho(false);

        box2Dworld = new com.badlogic.gdx.physics.box2d.World(new Vector2(0.0F, -10.0F), true);
        new BoundryWall(this.box2Dworld, new PointF(0.0F, 0.0F), 800.0F, camera);

        debugRenderer = new Box2DDebugRenderer();

        createDynamicBody(110f, 150f);

        box2dBody.applyForce(new Vector2(30 * 1000, 0), box2dBody.getWorldCenter(), true);

        Texture ball_in_hand_Texture = new Texture(Gdx.files.internal("test/ball_in_hand.png"));
        ball_in_hand_Texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

        ball_sprite = new Sprite(ball_in_hand_Texture);
        ball_sprite.setPosition(110f, 150f);

        spriteBatch = new SpriteBatch();
    }

    @Override
    public void render()
    {
        Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 1f);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

        box2Dworld.step(1.0f/60.0f, 6, 2);
        //box2Dworld.clearForces();

        camera.update();

        debugRenderer.render(box2Dworld, camera.combined);

        spriteBatch.begin();

        spriteBatch.draw(ball_sprite, 30 * box2dBody.getPosition().x, 30 * box2dBody.getPosition().y);

        spriteBatch.end();
    }

    private void createDynamicBody(float x, float y)
    {
        // First we create a body definition
        BodyDef bodyDef = new BodyDef();
        // We set our body to dynamic, for something like ground which doesn't move we would set it to StaticBody
        bodyDef.type = BodyType.DynamicBody;
        bodyDef.bullet = true;
        // Set our body's starting position in the world
//      bodyDef.position.set(x / 60.0f, y / 60.0f);

        //bodyDef.position.set(x / 30.0f, y / 30.0f);

        bodyDef.position.set(x, y);

        // Create our body in the world using our body definition
        box2dBody = this.box2Dworld.createBody(bodyDef);

        // Create a circle shape and set its radius to 6
        CircleShape circle = new CircleShape();
        circle.setRadius(10f);

        // Create a fixture definition to apply our shape to
        FixtureDef fixtureDef = new FixtureDef();
        fixtureDef.shape = circle;
        fixtureDef.density = 0.5f;
        fixtureDef.friction = 0.4f;
        fixtureDef.restitution = 0.6f; // Make it bounce a little bit

        // Create our fixture and attach it to the body
        Fixture fixture = box2dBody.createFixture(fixtureDef);

        // Remember to dispose of any shapes after you're done with them!
        // BodyDef and FixtureDef don't need disposing, but shapes do.
        circle.dispose();
    }
}
</code>
Please help me. I am trying to solve this problem from last 3 days but of no avail. Thanks in advance.
Comment: Force is usually applied continuously over many time steps, not just once like in your code. Maybe you could try ApplyLinearImpulse or SetLinearVelocity instead.
Answer: I think you have created the world of very big size in which applying force of that value will have no effect. In fact applying force of any value will have no effect since the box2d world is limited to lower value.
I have not worked on Box2d for a very long time but i did faced the same issue. Try a small world around 12x20 and render your sprites accordingly. Then try applying the force, it will definately work.
Comment: Can you please tell me how to create a world of small size please?
Comment: Here you are creating circle shaped body of radius 10 ... reduce it to .2f and render your sprite accordingly. Pixel to meter stuff is the line you should search... Please also see this. might help you -> http://stackoverflow.com/questions/14208797/box2d-libgdx-a-bit-confused-about-the-pixels-to-meters-stuff


Using VBO to change users passwords

Question: I need a method of changing users passwords which doesn't require email, as such the best solution I can come up with is providing "manager" roles the ability to reset passwords. However we do not want to provide these users with "administer users" permission.
I am thinking the best way of doing this is a view which displays "my team" (uses a user reference on that managers direct reports.) and uses views bulk operations however I can not find anywhere documentation on how to reset users passwords.
Ideally the VBO action would allow managers to select members on their team and reset passwords to a string, then update the user in person.
Comment: There are no methods for setting user password in Rules, as I can see.You have to write your own action (see [Examples](http://drupal.org/project/examples) module) for this, but this strategy can be dangerous.
Comment: Can I do it programmatically? In VBO php?
Comment: You can create an action _programmatically_. VBO uses actions.
Answer: Userplus has an action which changes a users password, I was able to use the below:
<code>/**
 * Implementation of hook_action_info().
 */
function userplus_actions_action_info() {
  $actions = array(
    'userplus_change_password_action' => array(
      'type' => 'user',
      'description' => t('Change user\'s password'),
      'configurable' => TRUE,
      'hooks' => array(),
    ),
  );
  return $actions;
}

/**
 * Action to change a user's password
 */
function userplus_change_password_action_form($context) {
  _user_password_dynamic_validation();
  $form['pass'] = array(
    '#title' => t('New password'),
    '#type' => 'password_confirm',
    '#description' => t('Provide a password for the selected users in both fields.'),
    '#required' => TRUE,
    '#size' => 25,
  );

  return $form;
}

function userplus_change_password_action_submit($form, $form_state) {
  return array('pass' => $form_state['values']['pass']);
}

function userplus_change_password_action(&$user, $context) {
  user_save($user, array('pass' => $context['pass']));
}
</code>
Answer: Another method, for Drupal 7, is to create a rules action, and save it in the file MODULENAME.rules.inc. Change "MODULENAME" by your module name.
<code>/**
 * Implements hook_rules_action_info().
 */
function MODULENAME_rules_action_info() {
 return array(
   'of_client_change_password' => array(
     'label' => t('Change user\'s password'),
     'parameter' => array(
       'account' => array(
         'type' => 'user',
         'label' => t('User'),
        ),
       'password' => array(
         'type' => 'text',
         'label' => t('Password'),
       ),
     ),
     'group' => t('MODULENAME'),
   ),
 );
}

function MODULENAME_change_password($account, $password) {
  // If we pass the password in the $edit array, it will be properly hashed
  $edit['pass'] = $password;
  user_save($account, $edit);
}
</code>

Using VBO to change users passwords


An unknown syntax mistake in script which changes id of divs itsleft according to parent's title

Question: I wrote a script which changes the class of div in li according to the title of parent page (means there is menu.html which is inside of iframe in home.html). Alas, I tried many things but it doesn't work. How can I find the mistake? Should I take in account that the captions aren't in English but in Hebrew?
The code for menu.html is:
<!DOCTYPE html>

<title> </title>
 <link rel="stylesheet" type="text/css" href="style.css" />

דף פתיחה

על עצמי     ותחביבים

בדיחות

תוכנות     חינמיות

קישורים     שימושים

אם ברצונך להרשם לעדכוני האתר, אנא הכנס את
כתובת המייל שלך     בצירוף שמך באנגלית:
    <form action="sent.php" method="post" >
        <input type="text" name="subscr" />
email
        <input type="text" name="perosnal"/>
שם

        <input type="submit" name="submit" onclick="alert('good job and thanks!');"/>    </form>

And the code for the index is:
<!DOCTYPE html>

<title>העמוד הראשי</title>
<link rel="stylesheet" type="text/css" href="style.css" />

i built it so respect!:)
 לתלונות, מענות,פניות ושאר ירקות ופירות

Answer: You're modifying elements before they exist on the page - move your script block into a window.onload handler and it should work fine:
window.onload = function () {
    switch (window.parent.document.title) {
        // snip ...
    }
};

Comment: i chnaged the head to
      and it still doesn't work. is there another thing?
Comment: @Zetathebeginner if you declare a script block before your HTML elements without an onload handler, the script will execute before the elements exist. `` doesn't really have anything to do with it.
Comment: learned new thing:) even though i changed it into window.onload and still it refuses working....
Comment: @Zetathebeginner you're going to need to give a little more information. does the page load? are there any errors in the console? does the switch in the script block even execute?
Comment: ok. the home.html loads fine, doesn't show any error (both with ie9 and chrome). in the iframe the div of "nada1" dooesn't change its color to orange (as defined in style.css), seems the script doesn't execute(it doesn't pops up the message of defult case...), thanks again :)
Comment: @Zetathebeginner have you put a `debugger;` into the script and step through what it does?
Comment: i tried and it presents as usual the page, again without the script action...(same with 'run with dubbger' of visual studio)


Is it true that $\lvert\alpha+\beta\rvert=\lvert\alpha\rvert+\lvert\beta\rvert$ for ordinals $\alpha$ and $\beta$?

Question: Suppose $\alpha$ and $\beta$ are ordinals. I was asked to prove that $\lvert\alpha+\beta\rvert=\lvert\alpha\rvert+\lvert\beta\rvert$. However, I think to have found a counterexample for this equality, namely if $\alpha=\omega$ and $\beta=1$ then
$$\lvert\alpha+\beta\rvert=\lvert\omega+1\rvert=\lvert\omega\rvert=\omega\neq\omega+1=\lvert\alpha\rvert+\lvert\beta\rvert.$$
Am I doing something wrong or is there a mistake in the exercise?
Comment: You are confusing ordinal numbers and cardinal numbers. These are the dangers of using ordinals to denote both order types and cardinalities.
Answer: As I've mentioned in the comments, you are confusing ordinal and cardinal numbers. This is a very common mistake, and it's important to clarify it.
Let me add the subscript $c$ when we talk of cardinals and subscript $o$ when we talk of ordinals. Then we have $\alpha=\omega_o,\beta=1_o$. Then your argument is
$$|\alpha+\beta|=|\omega_o+1_o|=|\omega_o|=\omega_c\neq\omega_c+1_c=|\omega_o|+|1_o|=|\alpha|+|\beta|$$
Right now it's easy to see where the mistake is - in the world of cardinal numbers, equality $\omega_c=\omega_c+1_c$ does hold. This is why your counterexample is invalid.
Edit: As Noah points out, the alternative way to look at this is to note that the two ways in which you use $+$ are different - once it is an operation of ordinal sum, the other is cardinal sum.
As Asaf mentions, the safest way to go is to represent cardinals using aleph notation (which has become pretty much a standard in set theory), and leave $\omega$ to only denote ordinals.
Comment: I would just be smart about it and use the $\aleph$ notation. $|\omega|=\aleph_0$. Problem solved.
Comment: I would emphasize this differently - put the subscript on the "$+$." Cardinal sums and ordinal sums are different (and this is a really important point once we start talking about exponentiation . . .).
Comment: Thank you all for the hints! I now see what went wrong. A bit silly actually, but cardinals are relatively new to me.
Comment: In your 3rd sentence you are confusing ordinals and ordinals...


How can I get the offset and size of the text section of a binary?

Question: I'd like to know the exact byte locations of the text section of a binary, the better to inspect it algorithmically. I've tried using size, but that only seems to give me the sizes of the sections, not their locations, and I've tried using readelf, but that frankly gives me too much information.
Answer: The output from readelf -S looks like this:
There are 21 section headers, starting at offset 0x1fcdc:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .hash             HASH            000000b4 0000b4 0008e0 04   A  2   0  4
  [ 2] .dynsym           DYNSYM          00000994 000994 0012f0 10   A  3   3  4
  [ 3] .dynstr           STRTAB          00001c84 001c84 0016a4 00   A  0   0  1
  [ 4] .gnu.version      VERSYM          00003328 003328 00025e 02   A  2   0  2
  [ 5] .gnu.version_d    VERDEF          00003588 003588 000118 00   A  3  10  4
  [ 6] .gnu.version_r    VERNEED         000036a0 0036a0 000110 00   A  3   2  4
  [ 7] .rel.dyn          REL             000037b0 0037b0 001428 08   A  2   0  4
  [ 8] .rel.plt          REL             00004bd8 004bd8 0006e0 08   A  2   9  4
  [ 9] .plt              PROGBITS        000052b8 0052b8 000a64 04  AX  0   0  4
  [10] .text             PROGBITS        00005d1c 005d1c 0141d0 00  AX  0   0  4
  [11] .rodata           PROGBITS        00019eec 019eec 004121 00   A  0   0  4
  [12] .data.rel.ro      PROGBITS        0001f010 01e010 00119c 00  WA  0   0  4
  [13] .dynamic          DYNAMIC         000201ac 01f1ac 000110 08  WA  3   0  4
  [14] .got              PROGBITS        000202bc 01f2bc 00045c 04  WA  0   0  4
  [15] .data             PROGBITS        00020718 01f718 0002d0 00  WA  0   0  4
  [16] .bss              NOBITS          000209e8 01f9e8 0005d8 00  WA  0   0  4
  [17] .comment          PROGBITS        00000000 01f9e8 0001f8 00      0   0  1
  [18] .ARM.attributes   ARM_ATTRIBUTES  00000000 01fbe0 00002b 00      0   0  1
  [19] .gnu_debuglink    PROGBITS        00000000 01fc0b 000014 00      0   0  1
  [20] .shstrtab         STRTAB          00000000 01fc1f 0000ba 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

Line [10] is the .text section. The Addr column gives the virtual address at which the section is loaded, the Off column gives the offset within the file to the section, and the Size column gives the size of the section. All numbers are expressed in hex.
Programmatically, you can obtain information about any section by using the structures defined in elf.h to parse the file. Here's an example (with error-checking and cleanup left out for simplicity):
int fd = open(..., O_RDONLY);

/* map ELF file into memory for easier manipulation */
struct stat statbuf;
fstat(fd, &statbuf);
char *fbase = mmap(NULL, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);

Elf32_Ehdr *ehdr = (Elf32_Ehdr *)fbase;
Elf32_Shdr *sects = (Elf32_Shdr *)(fbase + ehdr->e_shoff);
int shsize = ehdr->e_shentsize;
int shnum = ehdr->e_shnum;
int shstrndx = ehdr->e_shstrndx;

/* get string table index */
Elf32_Shdr *shstrsect = &sects[shstrndx];
char *shstrtab = fbase + shstrsect->sh_offset;

int i;
for(i=0; i<shnum; i++) {
    if(!strcmp(shstrtab+sects[i].sh_name, ".text")) {
        /* found the text section: inspect sects[i].sh_offset, sects[i].sh_size */
    }
}

Comment: Is there any way I can find the location of the text section in the executable file? In particular I want to read the file and manipulate its text section without loading the executable itself.
Comment: Was I not clear? The `Off` + `Size` columns give you the location of the text section precisely.


How do I display a view content for a specific user?

Question: There are several views to show the content that is restricted by the page_access module. For now, the view shows all the content. Ideally, it must show the content that the specific user is allowed to see.
How can I achieve this?
Answer: You can set permission for the specific role in view. Check the access in page/block settings
Change the access permission to role, then check the access for the specific roles for view content.

For example, Restrict View for the authenticated user. So, the users who are belonging to the authenticated user roles can able to access the content, other roles cant access it.


Navigation drawer toggle doesn't change state

Question: I begin a new project, just copy/paste code from an old project where everything is ok. In this one toggle button doesn't change states(it is only arrow and is not working when I am pressing it) like:

to

open/close drawer is working fine using swipe touch
Have to notice that I am using only one Activity that have layout:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/base_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<RelativeLayout
    android:id="@+id/base_container_for_fragments"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    //elements for screen

</RelativeLayout>

<ListView
    android:id="@+id/navigationDrawerList"
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:layout_gravity="left|start"
    android:background="@color/color_red_style" />

in my activity:
//declaring vars:
private ListView mDrawerList;
protected DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
CustomDrawerAdapter adapter;
List<DrawerItem> dataList;

in onCreate() :
   dataList = new ArrayList<DrawerItem>();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.base_layout);
    mDrawerList = (ListView) findViewById(R.id.navigationDrawerList);

    addDrawerItems();
    setupDrawer();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

addDrawerItems() is working ok
 protected void setupDrawer() {
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open_drawer, R.string.close_drawer) {

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            getSupportActionBar().setTitle(getResources().getString(R.string.bar_menu));
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            getSupportActionBar().setTitle("produse");

            // creates call to onPrepareOptionsMenu()
            invalidateOptionsMenu();
        }
    };

    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

and of course I put handle toggle in  onOptionsItemSelected(MenuItem item)
 // Activate the navigation drawer toggle
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }

So what's the problem,I just can't realize... Any ideas will be appreciated.
Comment: Check out this : https://developer.android.com/intl/zh-tw/training/implementing-navigation/nav-drawer.html#ActionBarIcon
Comment: I realised my [fault](http://stackoverflow.com/a/32269830/3595288)
Answer: omg I forgot to sync button toggle state :)
I had to add this in my MainActivity() :
@Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }


Aceitar centavos no javascript

Question: Gostaria que esse codigo pegasse os centavos do valor vindo da variável javascript
preco = parseInt(preco);

ja coloquei assim nada
preco = parseFloat(preco);

Codigo completo abaixo
total = 0;

function adiciona(id) {
    calcula(id, "adicao");
}

function remove(id) {
    calcula(id, "subtracao");
}

function calcula(id, operacao) {
    nomeid = "nome" + id;
    precoid = "preco" + id;
    qtdid = "qtd" + id;
    nome = document.getElementById(nomeid).innerHTML;

    preco = document.getElementById(precoid).innerHTML;
    preco = parseInt(preco);

    qtd = document.getElementById(qtdid).innerHTML;
    qtd = parseInt(qtd);

    //Debug
    //alert("Produto: " + nome + "\n Preço: " + preco);

    if (operacao == "adicao") {
        total = total + preco;
        qtd = qtd + 1;
    } else {
        total = total - preco;
        qtd = qtd - 1;
    }

    document.getElementById(qtdid).innerHTML = qtd;
    document.getElementById("total").innerHTML = total;
}

Comment: O que dá `alert(document.getElementById(precoid).innerHTML);`? e queres apanhar só a parte decimal, é isso?
Comment: por exemplo o valor esta 60,80 so aparece 60 entendeu
Answer: Fala Hemerson,
Tenta o seguinte:
// com preco ainda como string converte vírgula para ponto
preco.replace (", ", ". ");

// depois converte para float
preco = parseFloat(preco);

E no php vai precisar usar number_format para formatar quando quiser exibir float com vírgula como casa decimal.
http://php.net/manual/en/function.number-format.php
Comment: isso e no php ou javascript ?
Comment: O código q escrevi acima é de javascript.  Não tenho como ver aqui seu código de ontem pra te orientar melhor levando ele em conta pq tô na casa da minha noiva escrevendo no cel...  :-]
Comment: Vamos pro chat  ?
Comment: Vou colocar o código completo abaixo
Answer:

Comment: Então,  vc precisa converter de string pra float pra fazer cálculo e depois de float pra string de novo pra mudar ponto pra vírgula.
Comment: Como tinha falado antes hj tô na casa da minha noiva e minha ajuda pelo cel é bem limitada,  mas tem muita gente boa nesse site pra ajudar tb.
Comment: Alguem esta por ai ? ainda não resolvi a questão
Comment: Fala Hemerson, você deu uma olhada nessa minha resposta?
http://pt.stackoverflow.com/questions/11018/como-representar-dinheiro-em-javascript/175800#175800
Não te serve? Se quiser pode comentar nela como poderia ser melhorada.
Comment: Mano nao consegui vc lembra que agente estava conversando no skype vc me lembrou de colocar o código para aceitar os centavos desde la mano nao consegui ainda naquele codigo que vc fez tem como agente ir para o chat
Comment: Vou entrar no Skype
Comment: Liga seu Skype.

Aceitar centavos no javascript


Show that $a^{25} \pmod{88}$ is congruent with $ a^{5} \pmod {88}.$

Question:
Show that $a^{25} \pmod{88}$ is congruent with $ a^{5} \pmod {88}.$

I have proved it in the case that $\gcd(88,a)=1$, but in the other case , I don't know it. Any ideas?
Comment: I think you'll have to look at the prime factors of $88$, luckily there's not that many.
Answer: As $(ab)^{25}\equiv (a^{25}b^{25})\pmod{88}$, and you have the result for numbers that are relatively prime to $88$, you only need to look at the prime factors of $88=2^3\cdot 11$. $11^{25}$ is a number some calculators might find too big, but apart from that technicality it should be really easy.
Comment: I don't understand this, can you explain it a bit more?
Comment: What does modular multiplication have to do with the original question?
Comment: $a^{25} = (a^5)^5$, so it is also easy to do the exponentiation even with a regular calculator, by reducing modulo $88$ in the middle.
Answer: Note that $88=11 \cdot 8$, so $\Bbb Z _{88} \simeq \Bbb Z _8 \times \Bbb Z _{11}$. Therefore, you must show that $a^{25} = a^5$ in both $\Bbb Z _8$ and $\Bbb Z _{11}$. We shall use Euler's theorem: in $\Bbb Z _n$, we have $a^{\varphi (n)} = 1$, where $\varphi$ is Euler's function. Note that $\varphi(8)=4$ and $\varphi (11)=10$.
In $\Bbb Z _{11}$, every $a \ne 0$ is coprime to $11$, so $a^{10} = a^{\varphi (11)} = 1$, so $a^{25} = a^{20+5} = (a^{10})^2 a^5 = a^5$.
In $\Bbb Z _8$, if $\gcd (a, 8) = 1$, then $a^4 = a^{\varphi (8)} = 1$, so $a^{25} = a^{24+1} = (a^4)^6 a = a$; on the other hand, $a^5 = a^{4+1} = a^4 a=a$, so $a^{25}=a^5 \mod 8$.
If $\gcd(a, 8) >1$ then $2|a$, say $a=2b$. Then $a^{25} = 2^{25} b^{25} =0$, because $8 | 2^{25}$. Similarly, $a^5 = 2^5 b^5 = 0$, so again $a^{25} = a^5$.
The last case to examine is $a=0$, but this is trivial.
Comment: But I think that gcd(a,8) en gcd(a,11) must also be 1, to do this method, no?
Comment: @jens: Corrected, thank you.
Comment: Ok thank you very much, very clearly written. Now, I understand it, thanks!
Comment: In de second part $a$ could also be 22,33 ... But in that case , it's trivial  because you can written $a=k*11$ for some k and this gives $a^{25}\mod 11 = a^5 \mod 11 = 0$.
Comment: @jens: No, it cannot be: the elements of $\Bbb Z _8$ stop at $7$, while the elements of $\Bbb Z _{11}$ stop at $10$. This is the whole point of the decomposition, to reduce the problem to smaller spaces which are easier to study (with the added advantage that $\Bbb Z _{11}$ is a field, not only a ring, which makes some things simpler).
Comment: Yes of course, I was wrong, I'm sorry.
Answer: Since $\phi(8)=4$, if $(2,a)=1$, then
$$
a^5\equiv a^{25}\pmod8\tag{1}
$$
However, if $2\mid a$, then $a^5\equiv0\pmod8$ and $a^{25}\equiv0\pmod8$, so $(1)$ still holds.

Since $\phi(11)=10$, if $(11,a)=1$, then
$$
a^5\equiv a^{25}\pmod{11}\tag{2}
$$
However, if $11\mid a$, then $a^5\equiv0\pmod{11}$ and $a^{25}\equiv0\pmod{11}$, so $(2)$ still holds.

Putting together $(1)$ and $(2)$ gives
$$
a^5\equiv a^{25}\pmod{88}\tag{3}
$$
Answer: As $88=8\cdot11$
Using Fermat's Little Theorem, $11|(a^{11}-a)=a(a^{10}-1)\forall a\in  \Bbb Z$
Again if $2|a,8|a^n$  for integer $n\ge3$
Else using $2\nmid a\iff(a,2)=1\implies a$  is odd $=2b+1$(say)
$(2b+1)^2=8\dfrac{n(n+1)}2+1\equiv1\pmod8\implies a^2\equiv1$
So, $8|a^3(a^2-1)\forall a\in  \Bbb Z$
$\implies88|a^{\text{max}(1,3)}(a^{\text{lcm}(2,10)}-1)=a^3(a^{10}-1)$
Now $$a^{25}-a^5=a^5(a^{20}-1)$$ is divisible by $a^3(a^{10}-1)$
Answer: Apply the Theorem below, which is a generalization of Fermat and Euler's theorem $\rm\color{blue}{(E)}.$
From below $\ n^{20+5}\equiv n^{5}\!\pmod{2^3 11}\,$ by $\,2\neq 11\,$ are prime, $\ \color{#0a0}{4,10\mid 20},\ $ and $\ 3,1<5$
Theorem $\ \ \, n^{\large \varphi+k}\equiv n^{\large k}\pmod{p^i q^j}\ \ $ if $\ p\ne q\,$ are prime, $ \ \color{#0a0}{\varphi(p^i),\varphi(q^j)\mid \varphi},\ $  $\, i,j \le k $
${\bf Proof}\,\ \ p\nmid n\,\Rightarrow\, {\rm mod\ }p^i\!:\  n^{ \varphi}\equiv 1\,\Rightarrow\, n^{\varphi+k}\equiv n^k,\ $ by $\,\  n^{\large \color{#0a0}\varphi} = (n^{\color{#0a0}{\large \varphi(p^{\Large i})}})^{\large \color{#0a0}\ell}\overset{\color{blue}{\rm (E)}}\equiv 1^{\large \ell}\equiv 1$
$\qquad\quad\ \ \color{#c00}{p\mid n}\,\Rightarrow\, {\rm mod\ }p^i\!:\  n^k\equiv 0\,\equiv\, n^{\varphi+k}\ $ by $\ n^k = n^{k-i} \color{#c00}n^i = n^{k-i} (\color{#c00}{mp})^i$ and $\,k\ge i$
So $\ p^i\!\mid n^{\varphi+k}\!-n^k.\,$ By symmetry $\,q^j$ divides it too, so their lcm $ = p^iq^j\,$ divides it too. $\ $ QED
See also Carmichael's Lambda function, a generalization of Euler's phi function.


How to disable subquery flattening in sqlite

Question: If I define SQLITE_OMIT_SUBQUERY I cannot run a subquery clause. How can I revise the source code to disable the optimization and run as:

When a subquery occurs in the FROM clause of a SELECT, the simplest behavior is to evaluate the subquery into a transient table, then run the outer SELECT against the transient table.
Answer: Just break one of the rules listed in the documentation.
The easiest would be to add an OFFSET clause that has no effect:
SELECT ...
FROM (SELECT ...
      FROM ...
      LIMIT -1 OFFSET 0)
WHERE ...

If you really want to change the source code: just return from the flattenSubquery function in select.c without doing anything.
It already has the following line at the beginning:
if( OptimizationDisabled(db, SQLITE_QueryFlattener) ) return 0;


.load into DIV with PHP content

Question: I am trying to .load a script called 'refreshImages.php'. Inside that script is a while loop pulling from the database. I have got it to load a single echo function but it wont load anything inside the while loop I have on the script... this is what the php file has...
<?php
include 'includes/config.php';

$pimages = mysql_query("SELECT * FROM property_images WHERE pid='$pid'");

//Cant Post Images So Leaving The Echo Content Out//
while($img = mysql_fetch_array($pimages)){
    $image = $img['image'];
    $image_alt = $img['image_alt'];
    echo "
$img
";
}?>

I am using .load('refreshImages.php') on the page I need it to show up on.
Any explanation I am not seeing?
Comment: you mean echo does work, but image and image_alt are not assigned?
Comment: echo will work outside the while loop, but anything i try to echo inside the while loop will not work, it will only work outside the while loop. Any help?
Comment: `echo "$img";` , Is this what you want or `echo "$image";`?
Answer: Your $img is an array, not a string. You will get output like
Array
, if you have stuff coming from the database. Is that what you mean? Or are you getting an empty result?
If empty - what does your mysql_num_rows tell you when ran against the result resource?
Comment: Sorry had to make it like that for StackOverflow to post the question. This is what my echo is...

echo "";

When it loads, nothing is shown, at all, no empty results or anything, I have no clue why it wont show.
Comment: Can you edit your original post, and add what exact HTML you're getting when accessing the URL you're trying to load directly?
Answer: try changing this:
echo "
$img
";

to
echo "

";

Comment: Sorry, I had to make it like that for StackOverflow, because of posting images.

This is what it looks like...

echo "";

Anything?
Answer: You may not be getting any results from the database.  Try using this code which will display a message if there is something wrong with your sql query.
<?php
include 'includes/config.php';

$pimages = mysql_query("SELECT * FROM property_images WHERE pid=" . $pid );

if (mysql_num_rows($pimages) > 0) {  // checks to see if you are getting results from db
  while($img = mysql_fetch_array($pimages)){
    $image = $img['image'];
    $image_alt = $img['image_alt'];
    echo '

';
  }
} else {
  echo "no results returned from database";
} // end of mysql_num_rows check
?>

Answer: You might be better off concatenating all the images and then echo-ing it out rather than echo-ing each one e.g
$htmlOutput = '';

while($img = mysql_fetch_array($pimages)){
    $image = $img['image'];
    $image_alt = $img['image_alt'];
    $htmlOutput .= "

";
}
 echo $htmlOutput ;

.load into DIV with PHP content


Using a framework like Backbone

Question: I currently have a page http://proctors.org/tv that is driven by several views and attachments with tons of jQuery and hacked-together JavaScript spaghetti, and I would like to clean it up. I understand that newer Javascript "MVC" frameworks make use of templates, and don't strictly store all the data in the DOM as you might do with jQuery.
I believe you would use something like Services and/or Views as the backend, with Backbone on the front.
There is a D.o project for Backbone, and I remember there being a BoF or Session at DrupalCon Denver about it...
I am hoping to discover if it is worth my time to try and rewrite this in a new framework or just clean up what I have here.
Comment: What is the question, exactly? If the question is "Is anyone using Javascript frameworks like Backbone or Ember with Drupal?" then it is a poll, and as such is not welcome on Stack Exchange sites. If you have a specific question about using one of those JavaScript frameworks, then ask that question.
Comment: I think he's asking if there exist any MVC javascript frameworks that can work sufficiently well with Drupal's own javascript framework that they would result in less work than simply rolling his own. Seems fair to me - for some things, intigrating with Drupal goes beautifully smoothly, for others, it needs so much hacking you'd be better to just rewrite it from scratch - and it seems fair to ask people who've already tried.
Comment: If you want a quick tutorial to get backbone + drupal up an running you can check out my blog post http://www.pixelite.co.nz/article/drupal-7-backbone-js-part-1-setting-upinstallation
Comment: Another example using Backbone and Drupal is the "Mobile Friendly Navigation Toolbar" from Spark/Drupal 8 https://www.drupal.org/project/navbar
Comment: This guy has a good starting point for backbone and Drupal http://www.pixelite.co.nz/article/drupal-7-backbone-js-part-1-setting-upinstallation
Comment: Ha that guy is @masterchief from one of the answers above
Comment: Yeah perhaps he should take the answer.
Answer: I have used both Ember and Backbone along with Drupal - but not in the way you would think.
Ember and Backbone are both fine tools to create a web application - but Drupal is not really a good tool to be used along with them. What you desire when you built a web app is something light and fast. You want it to be fast to be able to give your users the feeling if immediate  response times. You want it to be light to make it scale better. Drupal is not fast - the full Drupal bootstrap takes a long time (compared to a lot of other options) if all you want to do is provide a REST API for your web app. Drupal is PHP, which also makes it quite RAM hungry limiting the number of concurrent users.
So if Drupal is so bad for this why use it?
You should really use Drupal for what Drupal excels at - a CMS. What I've done in the past with projects that needed a web app is to use Drupal to create the CMS around the web app. To build stuff like blogs, content lists and the likes. I also created modules to define some backend stuff - like schema definitions, and other stuff where it made sense to use Drupal - because it made my development much easier.
Instead of using Drupal to create the REST API that the webapp needed - I used Node.js to create the actual REST API and other checks AJAX calls that the webapp needed to make. Node.js excels in doing just this. It's blazing fast (response times as low as 30ms for a list of objects). It's also very lightweight, since JavaScript on the server uses asynchronous actions, a Node.js server can usually handle thousands of concurrent users where PHP can handle maybe 100. In addition to that - since Node.js is JavaScript, you can reuse a lot of the code server and client side. You can literally write the same validation code, instead of having to implement both client side in JavaScript and server side in PHP. If you are going to Drupal con in Münich in a few weeks - you should consider watching the node.js presentation.
So if you are a developer, I would strongly recommend doing a similar setup, and only use Drupal for what it is really good at. If you want to make a simple webapp and you don't expect a lot of user, using Drupal as a backend could be an option if it helps your development time.

Update Drupal 8
So with the release of Drupal 8 some of the above still holds true but not in the same extend as earlier. Drupal 8 is like Drupal 7 not a light weight tool, like Node.js, Rails, Django etc. Since JavaScript apps mainly consume various services, you still should consider if Drupal is the best tool for this.
With Drupal 8 a lot of things have been improved. Services is a lot more native, with Symphony driving the request/response. Drupal 8 has a lot of interesting possibilities with with the advanced caching and all of the great features. But even with all of the greatness of Drupal 8, it still is a lot heavier than light weight applications. It's hard to tell how successful Drupal 8 can be used as a fast webservice provider.
So still, with all being said and done, my general recommendation stays the same. Being a Drupal developer, it's easy to use Drupal for everything, since we're familiar with it. It feels safe and Drupal can be used for just about anything. Remember while it's possible to use Drupal for anything, it doesn't mean that it's the best tool for everything. Doing a sound analysis and understanding the strengths and weaknesses of the tools you want to use on an IT project, will always be a great help and can help you avoid ending in a deadlocked position with a result that doesn't live up to your expectations.
Comment: Interesting approach.  Are you using http://drupal.org/project/nodejs or are you rolling your own interface to the Drupal DB?
Comment: @googletorp, I worked with phusion passenger and even she cannot perform better without caching and server optimization and all server side scripting languages (except js) have fair amount of blocking issue. Infact I myself switched from ruby to php because of some dedicated performance support in open source community and extreme ease of use. Nodejs will always remain faster compared to other languages.
Comment: Anyways the point is, since Drupal provides awesome services module framework, I thought you could share some knowledge on handling data at client side, especially handing session and stuff.
Comment: @Minty There is a helper package for integration to Drupal in Nodejs : https://github.com/mikl/node-drupal The actual session handling depends a lot on how/what you do. CORS etc, but I usually send the Drupal session_id either a cookie or in the request header.
Comment: I just read through this awesome Backbone documentation https://github.com/kjbekkelund/writings/blob/master/published/understanding-backbone.md/ and thought, man backbone is a great way to organize your JavaScript and use it with AJAX callbacks via the routing system. Why not combine it with Drupal since Drupal relies on the same routing characteristics?
Answer: I have recently begun developing my first backbone + drupal application and am really enjoying it. Using the Backbone module along with Services, Services Views, and the required libraries. The project is quite simple: To create a content manageable carousel of 6 pages that display various data, along with an additional News slider that displays different content. This page sits on various screens without user interaction so required the ability to update the front end content without refreshing the browser. I thought this fit perfectly into a Drupal + Backbone app with Drupal managing the content and backbone controlling and syncing with the db. I integrated in jquery.cycle 2 which has an awesome API and fits well into the MVC style of coding.
I can see why people might stick their nose up at using Drupal as the backend framework but for a small application like this Drupal is light and fast. I achieved this by starting with a minimal install and carefully picking contrib and core modules. I'm now at around 50 modules with just under 150 lines of custom JS code for the backbone stuff and I'm pretty much done.
Eventually I will try to commit this back as an example to the backbone module as there is currently no example which shows how to use Views as collections etc.
In conclusion:
It is worth your time to look into this if your project matches well. In my opinion, performance issues derived from the heaviness of Drupal can be easily combated by using caching mechanisms like Varnish, or even boost or core page caching. The flexibility and speed of development from using Drupal completely outweighs the negatives for me.
Answer: The basic answer is yes, some people are using it.  I have not used it myself (haven't found a good project match yet), but there is currently a Drupal group for it, and it would also fit in with the Web Services and Context Core Initiative which is one of the Drupal 8 Initiatives.  There is also a session at DrupalCon Munich 2012, Backbone.js in the Frontend.
I don't know if it is ready for prime time yet, but in my opinion it is worth creating a proof of concept for if you have something that could benefit from it, and can design the JS side to an interface and not an implementation.  That would help isolate any backend changes should you decide to bail on Drupal, for whatever reason.
Comment: Essentially: Stackexchange is the wrong place to ask about this, since it's such a special case at this point. Wander on over to the group discussion on g.d.o.
Comment: MPD thanks for the link to the group. I will probably follow up there. I had done some asking around at user groups, which really depends on who is there. Still trying to figure out when I should start a question on Stack Exchange. I figured this would have more than one right answer, so it seemed like a fit.
Answer: You might find this useful : it shows an example of converting a JQuery based script into a backbone script. Obviously you will need to pull in backbone.js, either as a library using drupal_add_js or using the module.
https://github.com/kjbekkelund/writings/blob/master/published/understanding-backbone.md/
Comment: Hi Craig, thanks for the link, do you have any resource where this is used with Drupal in specific? Thanks

Using a framework like Backbone


Split a file with headers

Question: I can split a large file into 3 or 4 parts. But is there any way to repeat the headers of csv file?
# split -b 10G user_logs.csv

This will create xaa, xab and xac. The original headers are now part of xaa. How do I copy this line to xab and xac?
# head user_logs.csv
msno,date,num_25,num_50,num_75,num_985,num_100,num_unq,total_secs
rxIP2f2aN0rYNp+toI0Obt/N/FYQX8hcO1fTmmy2h34=,20150513,0,0,0,0,1,1,280.3350
rxIP2f2aN0rYNp+toI0Obt/N/FYQX8hcO1fTmmy2h34=,20150709,9,1,0,0,7,11,1658.9480

Will I have to repeat these 3 lines for each file?
head -1 user_logs.csv > xab_temp
cat xab >> xab_temp
mv xab_temp xab

Answer: You could try with the --filter. Something like the following:
split -b 10G \
 --filter='if [ ! "$FILE" = "xaa" ]; then echo "$header" > "$FILE";fi;cat >> "$FILE"' file

Example:
$ cat file
this is the header
1
2
3
4
5
6
7
8
9
10
$ export header=$(head -n 1 file)
$ split -l 3 --filter='if [ ! "$FILE" = "xaa" ] ; then echo "$header" > "$FILE" ; fi ; cat >> "$FILE"' file
$ for x in x* ; do echo "== $x" ; cat $x ; done
== xaa
this is the header
1
2
== xab
this is the header
3
4
5
== xac
this is the header
6
7
8
== xad
this is the header
9
10

Split a file with headers


Source not found : SQLiteCursor.class

Question: Running in Debug and pressing F8 to continue will get this 'Class File Editor - Source not found error'
<code>// Compiled from SQLiteCursor.java (version 1.5 : 49.0, super bit)
public class android.database.sqlite.SQLiteCursor extends     android.database.AbstractWindowedCursor {

// Method descriptor #8 (Landroid/database/sqlite/SQLiteDatabase;Landroid/database/sqlite    /SQLiteCursorDriver;Ljava/lang/String;Landroid/database/sqlite/SQLiteQuery;)V
// Stack: 3, Locals: 5
  public SQLiteCursor(android.database.sqlite.SQLiteDatabase db,     android.database.sqlite.SQLiteCursorDriver driver, java.lang.String editTable, android.database.sqlite.SQLiteQuery query);
     0  aload_0 [this]
 1  invokespecial android.database.AbstractWindowedCursor() [1]
 4  new java.lang.RuntimeException [2]
 7  dup
 8  ldc <String "Stub!"> [3]
10  invokespecial java.lang.RuntimeException(java.lang.String) [4]
13  athrow
  Line numbers:
    [pc: 0, line: 5]
  Local variable table:
    [pc: 0, pc: 14] local: this index: 0 type: android.database.sqlite.SQLiteCursor
    [pc: 0, pc: 14] local: db index: 1 type: android.database.sqlite.SQLiteDatabase
    [pc: 0, pc: 14] local: driver index: 2 type: android.database.sqlite.SQLiteCursorDriver
    [pc: 0, pc: 14] local: editTable index: 3 type: java.lang.String
    [pc: 0, pc: 14] local: query index: 4 type: android.database.sqlite.SQLiteQuery

// Method descriptor #23 (Landroid/database/DataSetObserver;)V
// Stack: 3, Locals: 2
public void registerDataSetObserver(android.database.DataSetObserver observer);
 0  new java.lang.RuntimeException [2]
 3  dup
 4  ldc <String "Stub!"> [3]
 6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
 9  athrow
  Line numbers:
    [pc: 0, line: 6]
  Local variable table:
    [pc: 0, pc: 10] local: this index: 0 type: android.database.sqlite.SQLiteCursor
    [pc: 0, pc: 10] local: observer index: 1 type: android.database.DataSetObserver

// Method descriptor #27 ()Landroid/database/sqlite/SQLiteDatabase;
// Stack: 3, Locals: 1
public android.database.sqlite.SQLiteDatabase getDatabase();
 0  new java.lang.RuntimeException [2]
 3  dup
 4  ldc <String "Stub!"> [3]
 6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
 9  athrow
  Line numbers:
    [pc: 0, line: 7]
  Local variable table:
    [pc: 0, pc: 10] local: this index: 0 type: android.database.sqlite.SQLiteCursor

// Method descriptor #29 (II)Z
// Stack: 3, Locals: 3
public boolean onMove(int oldPosition, int newPosition);
 0  new java.lang.RuntimeException [2]
 3  dup
 4  ldc <String "Stub!"> [3]
 6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
 9  athrow
  Line numbers:
    [pc: 0, line: 8]
  Local variable table:
    [pc: 0, pc: 10] local: this index: 0 type: android.database.sqlite.SQLiteCursor
    [pc: 0, pc: 10] local: oldPosition index: 1 type: int
    [pc: 0, pc: 10] local: newPosition index: 2 type: int

// Method descriptor #34 ()I
// Stack: 3, Locals: 1
public int getCount();
 0  new java.lang.RuntimeException [2]
 3  dup
 4  ldc <String "Stub!"> [3]
 6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
 9  athrow
  Line numbers:
    [pc: 0, line: 9]
  Local variable table:
    [pc: 0, pc: 10] local: this index: 0 type: android.database.sqlite.SQLiteCursor

// Method descriptor #36 (Ljava/lang/String;)I
// Stack: 3, Locals: 2
public int getColumnIndex(java.lang.String columnName);
 0  new java.lang.RuntimeException [2]
 3  dup
 4  ldc <String "Stub!"> [3]
 6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
 9  athrow
  Line numbers:
    [pc: 0, line: 10]
  Local variable table:
    [pc: 0, pc: 10] local: this index: 0 type: android.database.sqlite.SQLiteCursor
    [pc: 0, pc: 10] local: columnName index: 1 type: java.lang.String

// Method descriptor #39 ()[Ljava/lang/String;
// Stack: 3, Locals: 1
public java.lang.String[] getColumnNames();
 0  new java.lang.RuntimeException [2]
 3  dup
 4  ldc <String "Stub!"> [3]
 6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
 9  athrow
  Line numbers:
    [pc: 0, line: 11]
  Local variable table:
    [pc: 0, pc: 10] local: this index: 0 type: android.database.sqlite.SQLiteCursor

// Method descriptor #41 ()V
// Stack: 3, Locals: 1
public void deactivate();
 0  new java.lang.RuntimeException [2]
 3  dup
 4  ldc <String "Stub!"> [3]
 6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
 9  athrow
  Line numbers:
    [pc: 0, line: 12]
  Local variable table:
    [pc: 0, pc: 10] local: this index: 0 type: android.database.sqlite.SQLiteCursor

// Method descriptor #41 ()V
// Stack: 3, Locals: 1
public void close();
 0  new java.lang.RuntimeException [2]
 3  dup
 4  ldc <String "Stub!"> [3]
 6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
 9  athrow
  Line numbers:
    [pc: 0, line: 13]
  Local variable table:
    [pc: 0, pc: 10] local: this index: 0 type: android.database.sqlite.SQLiteCursor

// Method descriptor #44 ()Z
// Stack: 3, Locals: 1
public boolean requery();
 0  new java.lang.RuntimeException [2]
 3  dup
 4  ldc <String "Stub!"> [3]
 6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
 9  athrow
  Line numbers:
    [pc: 0, line: 14]
  Local variable table:
    [pc: 0, pc: 10] local: this index: 0 type: android.database.sqlite.SQLiteCursor

// Method descriptor #46 (Landroid/database/CursorWindow;)V
// Stack: 3, Locals: 2
public void setWindow(android.database.CursorWindow window);
 0  new java.lang.RuntimeException [2]
 3  dup
 4  ldc <String "Stub!"> [3]
 6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
 9  athrow
  Line numbers:
    [pc: 0, line: 15]
  Local variable table:
    [pc: 0, pc: 10] local: this index: 0 type: android.database.sqlite.SQLiteCursor
    [pc: 0, pc: 10] local: window index: 1 type: android.database.CursorWindow

// Method descriptor #50 ([Ljava/lang/String;)V
// Stack: 3, Locals: 2
public void setSelectionArguments(java.lang.String[] selectionArgs);
 0  new java.lang.RuntimeException [2]
 3  dup
 4  ldc <String "Stub!"> [3]
 6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
 9  athrow
  Line numbers:
    [pc: 0, line: 16]
  Local variable table:
    [pc: 0, pc: 10] local: this index: 0 type: android.database.sqlite.SQLiteCursor
    [pc: 0, pc: 10] local: selectionArgs index: 1 type: java.lang.String[]

// Method descriptor #41 ()V
// Stack: 3, Locals: 1
protected void finalize();
 0  new java.lang.RuntimeException [2]
 3  dup
 4  ldc <String "Stub!"> [3]
 6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
 9  athrow
  Line numbers:
    [pc: 0, line: 17]
  Local variable table:
    [pc: 0, pc: 10] local: this index: 0 type: android.database.sqlite.SQLiteCursor
</code>
}
I don't understand what this is telling me.
If I press F8 a few more times, the program continues along as normal and displays data and results as I would expect.
How do I read this error so that I can make effective fixes to my code?
Thanks
Comment: Is it asking for `Attach source`? It looks like you are going to debug  some `.class` file whose source is not attached to your jar.
Answer: Using the solution found here got rid of the impenetrable message and attached the class file.
Which then helped me identify a cursor not closed error.

Source not found : SQLiteCursor.class