Charset issue in a webform

Question: We have got a multisite structure with several sites. One of the sites has got a webform, from which client needs to download submissions from time to time. However, when we choose to export to Excel using the default values (delimited text and \t as delimiter format), Turkish characters get corrupted on a Windows. I have got no trouble on Linux, but client uses Windows. I must also mention that this behaviour doesn't occur on another site in the same multisite structure. What could I be missing?
EDIT: We are running Drupal 7.34, Webform 7.x-3.21, PHP 5.2.17, and we are using MS Office 2007. I export to Excel using /node/%nid/webform-results/download. I have also tried exporting the Webform to another site on the same multisite structure (hence the same PHP version) and verified it works fine there.
Regards,
Comment: In windows opening the file in notepad the values getting corrupted rite? and if you can provide what is the file extension you use it will be more easy to track your issue.
Comment: I opened them both in notepad++, one of them (the working one) looks correct while the other one is filled with NULs. Their file extension is .xls (I've tried with .csv too)
Comment: How do you export to Excel? What version of Drupal? What version of MS Windows?  What version of PHP? There a too little information here to make this answerable (I am not going to waste my time on a shot in the dark).  If you want value for your bounty, you need to make the question better.
Comment: @FreeRadical you're right, I improved my question.
Answer: This might be a fix for your problem, perhaps you should try this on your test environment: https://www.drupal.org/node/2060519
Comment: Hi, thanks for replying but I forgot to mention that we are running 3.x
Comment: you might have to consider updating then to fix your issue.
Comment: That is not possible as we are running PHP 5.2.17 and sysadmins will unlikely agree to upgrade.
Comment: I think this is the file that you should alter (this is where the conversion occurs), maybe you can play around with it on your test environment: http://drupalapi.attiks.com/api/webform/includes!webform.export.inc/function/webform_exporter_delimited%3A%3Aadd_row/7.x-3.x
Comment: I think it's worth mentioning again that this is a multisite structure.
Answer: After 3 months of dabbling, I managed to solve this by adding some PHP to includes/webform.export.inc:
<code><?php

 if (function_exists('mb_convert_encoding')) {
      $user_agent = strstr($_SERVER['HTTP_USER_AGENT'], 'Windows');
      if ($user_agent) {
        $row = mb_convert_encoding($row, 'UTF-16LE', 'ISO-8859-9');
      }
      else {
        $row = mb_convert_encoding($row, 'UTF-16LE', 'UTF-8');
      }
    }
?>
</code>
Not sure how to do it for Mac.

Charset issue in a webform


How to conduct joint significance test in seemingly unrelated regression

Question: I'm trying to conduct a joint test of significance in a seemingly unrelated regression setup with robust standard errors. I have three outcomes Y1, Y2, and Y3 and I want to conduct a joint hypothesis test against the null that the average effect of the treatment Z is zero on all three outcomes.
I think that I have the model set up correctly, but I don't think that I have the hypothesis.matrix set correctly in car::linearHypothesis.
Here's some data:
library(tibble)
library(car)
library(systemfit)

set.seed(343)
N = 800
dat <-
  tibble(
    U = rnorm(N),
    Z = rbinom(N, 1, 0.5),
    Y = 0.2 * Z + U,
    Y1 = Y + rnorm(N, sd = 0.3),
    Y2 = Y + rnorm(N, sd = 0.5),
    Y3 = Y + rnorm(N, sd = 0.5)
  )

Here's the seemingly unrelated regression fit:
sur <- systemfit(list(Y1 ~ Z, Y2 ~ Z, Y3 ~ Z), method = "SUR", data = dat)
summary(sur)

Which is identical to the ols fit in this case:
ols <- lm(cbind(Y1, Y2, Y3) ~ Z, data = dat)
summary(ols)

Which is useful, because I need to estimate robust standard errors for this test:
linearHypothesis(ols, hypothesis.matrix = "Z = 0", white.adjust = "hc2")

This last line is the one that I think is incorrect. I think it's incorrect because the individual coefficients all have lower p-values than the joint test, but I could be wrong?
Answer: Looks right to me.  You'd get the same result by estimating the null model (ols0 below) and using anova() to test the difference between the estimated and null models.
library(tibble)
library(car)
#> Loading required package: carData

set.seed(343)
N = 800
dat <-
  tibble(
    U = rnorm(N),
    Z = rbinom(N, 1, 0.5),
    Y = 0.2 * Z + U,
    Y1 = Y + rnorm(N, sd = 0.3),
    Y2 = Y + rnorm(N, sd = 0.5),
    Y3 = Y + rnorm(N, sd = 0.5)
  )

ols <- lm(cbind(Y1, Y2, Y3) ~ Z, data = dat)

linearHypothesis(ols, hypothesis.matrix = "Z = 0")
#>
#> Sum of squares and products for the hypothesis:
#>          Y1       Y2       Y3
#> Y1 3.201796 4.693391 3.359617
#> Y2 4.693391 6.879863 4.924734
#> Y3 3.359617 4.924734 3.525216
#>
#> Sum of squares and products for error:
#>          Y1       Y2       Y3
#> Y1 829.5535 756.1586 770.0808
#> Y2 756.1586 965.5959 770.4636
#> Y3 770.0808 770.4636 980.0664
#>
#> Multivariate Tests:
#>                  Df test stat approx F num Df den Df  Pr(>F)
#> Pillai            1 0.0073689  1.96972      3    796 0.11703
#> Wilks             1 0.9926311  1.96972      3    796 0.11703
#> Hotelling-Lawley  1 0.0074236  1.96972      3    796 0.11703
#> Roy               1 0.0074236  1.96972      3    796 0.11703

ols0 <- lm(cbind(Y1, Y2, Y3) ~ 1, data = dat)
anova(ols, ols0, test="Pillai")
#> Analysis of Variance Table
#>
#> Model 1: cbind(Y1, Y2, Y3) ~ Z
#> Model 2: cbind(Y1, Y2, Y3) ~ 1
#>   Res.Df Df Gen.var.    Pillai approx F num Df den Df Pr(>F)
#> 1    798     0.48198
#> 2    799  1  0.48257 0.0073689   1.9697      3    796  0.117

Created on 2022-07-08 by the reprex package (v2.0.1)


Is it correct to say that the statement $x\in \emptyset$ is false?

Question: Usually, whether a statement $P(x)$ about a free variable $x$ is true or false depends on the value or meaning of $x.$
For example, if $P(x)$ means $x\in \{ 1, -9, 15 \},$ we can neither say that $P(x)$ is true nor that it is false if we don't know what $x$ is.
But can we say that the statement $$x\in\emptyset$$ is false? After all, it does not have any quantifier.
On the other hand, these five examples all have quantifiers (either $\forall x$ or $\exists x$), and

$\forall x(x\in \emptyset \Rightarrow P(x))$
is vacuously true.

$\forall x(x \in U \Rightarrow x \in \emptyset)$
is false.

$\exists x(x \in U \land x\in \emptyset)$
is false.

$\exists x(x \in \emptyset)$
is false.

$\forall x(x \in \emptyset)$
is false.
Comment: Yes we can. Usually we read formulas with free variables as implicitly universally quantified.
Comment: But in this case, also every assignment of a value to the free variable x will produce a false sentence.
Comment: @MauroALLEGRANZA: I think what Stats Cruncher is asking is whether we can regard $x\in\emptyset$ as a false statement, even when $x$ is not considered to be universally quantified, either implicitly or explicitly.
Comment: I think every time $x\in \emptyset$ has a meaning, it is false. But a logician's answer is needed.
Comment: @Joe - answered in my second comment above. But we may compare it with e.g. $x=0$.
Comment: @Joe Indeed, What Joe says is what I intended to ask about or what this question was intended for. Appreciate it, Joe.
Answer: As usual, we are not admitting an empty domain of discourse. Then
$$x\in \emptyset$$ is an unsatisfiable open formula:

open formula
it is technically not a statement (closed formula), as it has a free variable;

unsatisfiable
it has a definite truth value False regardless of interpretation.
Comment: Thanks, @StatsCruncher! -)
Comment: The reason there are so many terminologies is so that questions like yours can be answered clearly!
Comment: Why are there so many terminologies? Wow, how come people on this site are so knowledgeable?
Comment: Sorry, is there any part that you require clarification of? Honestly, outside of formal logic, nobody will bat an eyelid if I  call $x\in\emptyset$ a statement. P.S. Remember to take a look at the Answer that I linked to.
Comment: Just pay people who provide answers compliments!
Answer:
Is it correct to say that the statement  x∈∅  is false?

Yes. We usually define $\emptyset$ as follows: $~~\forall a:a\notin \emptyset$.
Postulating $x\in \emptyset$ leads to the obvious contradiction, so $x\in \emptyset$ must be false.


An irreducible polynomial question

Question:
Let $\mathbb F$ be a field and $f(x)$ an irreducible polynomial in $\mathbb F[x]$. Let $c$ be an element of $\mathbb F[x]/(f)$. Show that there exists $g \in \mathbb F[x]$, $g\neq 0$, such that $g(c)=0$.

We have to prove that $c$ is algebraic. I don't have any idea how to proceed.
Comment: You want to assume $g \neq 0$ (otherwise it's trivial). Finite field (ring) extensions are always algebraic (integral). We don't even need that $f$ is irreducible.
Answer: Hint What can you say about the degree $$\left\lvert \frac{\mathbb F[x]}{\langle f(x) \rangle} : \mathbb F \right\rvert$$
Comment: I think it is $\big| F\big| ^{n-1}$. So $\frac{\mathbb F[x]}{}$ is a finite extension of $\mathbb F$ and thus it is algebraic.
Comment: Is this logic correct?
Comment: @math89, the degree of the extension is $n =$ the degree of $f(x)$. Then your argument is correct.

An irreducible polynomial question


Can two equations simultaneously cancel each other out in a linear system

Question: I am trying to write a system of equations in parametric form (which requires all rows but one to be zero'd out). I have managed to manipulate the matrix into:
$\begin{bmatrix}
1 & -1 & 2 & -4\\
2 & -1 & 2 & -4\\
-2 & 1 & -2 & 4\\
\end{bmatrix}$
Now operation wise adding row 3 to row 2 would zero it out (or the other way around).
I am wondering if it's permitted to do simultaneous operations to cancel both row 2 and 3 out at the same time to get:
$\begin{bmatrix}
1 & -1 & 2 & -4\\
0 & 0 & 0 & 0\\
0 & 0 & 0 & 0\\
\end{bmatrix}$
or would I have to cancel one out and then do more operations to cancel out the other like:
$\begin{bmatrix}
1 & -1 & 2 & -4\\
0 & 0 & 0 & 0\\
-2 & 1 & -2 & 4\\
\end{bmatrix}$
and then go from there.
Answer: When you are row reducing, there are three operations you can perform: adding a multiple of one row to another, multiplying a row by a non-zero scalar, and swapping two rows. Adding row 3 to row 2 will eliminate row 2, but you cannot simultaneously "zero out" both rows.
In general, when you are trying to get a parametric form for a system, you want to start with an augmented matrix corresponding to the equations, and get the left side of the augmented matrix to reduced row-echelon form. You might find the examples linked here to be helpful.


SPSS Statistics

Question: The variance measures how far each number in the set is from the mean
I have 151190 records of a table. and i have to analyze the data on SPSS. after the analysis i have some results. Mean=74617.92 with standard error=871.744, Median=94118, variance= 1393725134, Standard Deviation= 37332.628, Minimum= 1353, Maximum= 95085, Skewness= -.007, Kurtosis= -1.31. I cannot understand the relation why there is a huge gape between mean and variance.
Comment: The variance is in squared units, which sometimes makes variances very large (or very small) numerically.  However, you can have data with a small mean and a large standard deviation. Standard deviation is a measure of dispersion that has the same units as the mean. // Example: Maybe stock values are the same now as several months ago, but they have fluctuated widely + and - from day to day over the same period. // When I took a sample of size 100,000 from NORM($\mu$=0,$\sigma$=100) then I got sample mean $\bar X = -0.061,$ SD $S = 99.78$ and variance $S^2 = 9955.29.$ I guess all is OK.
Answer: When looking at how the data is spread, you should look at the standard deviation which has the same unit as the mean. The variance is the standard deviation squared, it thus doesn't give you a clear idea of the distribution of the data. If you have a big standard deviation means that your data has a big range, and in your case is skewed to the left since your means lies far to the left of the median
Comment: In real i don't have the clear understanding of variance and standard deviation. and how these will help me to analyze the data.
Answer: Perhaps somewhere you learned about the Coefficient of Variation (CV). You can look that up on the internet and see if that is what you are thinking of and why you might want to look at it.
In general, people look at measures of center (like the mean, mode, and.or median) and spread (the standard deviation, range, etc.) to help understand more about the distribution of a variable. When we measure something we want to describe and perhaps even make inferences about using some method of analysis, the shape of the distribution helps us figure out what statistical methods might be useful and which less useful.
For example, see https://www.quora.com/What-does-it-mean-when-the-standard-deviation-is-higher-than-the-mean-What-does-that-tell-you-about-the-data

SPSS Statistics


Rsync from CIFS mounted Windows shares is slow. Why is this?  Are there alternatives for file copy with checksum support?

Question: I have found that using Rsync to transfer files from CIFS mounted shares resident on a Widnows client is extremly slow.
I have read a few threads here on SF, and several other forum posts on the web, that point to the  issue being related to rsync verifying the data to be transferred.  Is anyone able to explain this to me?
Also, if this isn't going to work at the speeds I would like, what are my options if I want support for checksumming to ensure data integrity?
Currently when rsyncing files from a CIFS mounted share to a physically connected drive I net ~25 MB/s over a Gigabit LAN.  Conversely, when using Robocopy on the Windows client I realize transfer speeds of ~85 MB/s which is approaching the practical cap of the 5,900 RPM drive.  Why such a signifcant difference?
Answer: Rsync, for convenience, supports a mode where both files are local. This is the mode you are getting, because Rsync is not talking to a remote machine using the rsync protocol. None of rsync's optimizations are possible in this mode, because there is no program on the remote side to perform the optimized operations.
Rsync, in local mode, will not make any attempt to send only differences, because it has no way to tell what the differences are. It defaults to a standard copy, followed by a standard read to verify the data. If you want checksumming to verify data integrity, you need some software on the other end to do the checksumming locally. You could use an rsync server for this purpose, since you're using rsync anyway.
Comment: Is there a simpler way to transfer the files quickly and with checksumming?  Or am I forced to go the rsync route?  Are there rsync servers for windows clients?
Answer: Yes, I have noticed the same thing.
I have found that using unison is faster than using rsync when the source (a local hard drive) and the destination (a CIFS share) are both mounted on the same machine and so there is only one instance of the synchronization program.
Yes, unison is designed to copy files in both directions on the same invocation, but I have found that even just using it for one-way pushing (because I never edit anything at the destination) is faster than rsync.


displaying data result from mysql in php

Question: i need displaying the company name from the database but this code does not work for me. Please help. Thanks
<?php

// connect to the database
include('php/db.php');

   $result = mysql_query("select name from company where company_id = 1");

 echo $result['name'];
 ?>

Comment: Yes, let me do some magic to find out what's in your database. Well, where is your `mysql_fetch_array()` by the way?
Comment: my code now seems like this, but without any result:
";
}
?>
Answer: Try this code:
 while($row = mysql_fetch_array($result))
  {
   echo ""+$row['name'];
   echo "
";
  }

Answer: Try This One
// connect to the database
include('php/db.php');
$result = mysql_query("select name from company where company_id='1'");
while($row = mysql_fetch_array($result))
{
      echo $row['name']."
";
}

Comment: i tried the code, without any results. you can see the result at www.bigbossfood.com/companyname.php
any other idea?
Comment: another you can use mysql_fetch_assoc returns the proper object after that you can store data in to array() after try to display using foreach loop.
Answer: mysql_query returns an object, you first need to turn the object into an associative array using mysql_fetch_assoc();
You can then access elements of that array using the method you have used.
You may want to look at using the mysqli functions, as mysql functions are depreciated.


Rolling difference dependent on another categorical column changing?

Question: I have a df with the following structure where A is a categorical variable, t is the number of seconds and X is the desired output:

A
t
X

1
0.0
0

1
3.2
3.2

1
3.9
3.9

1
18.0
18

1
27.4
27.4

3
47.4
0

3
50.2
2.9

3
57.2
9.8

3
64.8
17.4

3
76.4
29.1

2
80.5
0

1
85.3
0

1
87.4
2.1

I would like X to be the number of seconds since column A has changed value.
I can do this in a big for loop but it it is too slow / computationally expensive.
I was trying to get the number of rows since the change by doing the following but not quite right and not sure how to index for the change from there regardless:
g = df[A].transform(lambda x: x.diff().ne(0).cumsum())
df[X] = df[A].cumcount() + 1

Answer: Use groupby.transform('first') to get the first value per group and subtract this from t:
# group consecutive values
group = df['A'].ne(df['A'].shift()).cumsum()

df['X'] = df['t'].sub(df.groupby(group)['t'].transform('first'))

Output:
    A     t     X
0   1   0.0   0.0
1   1   3.2   3.2
2   1   3.9   3.9
3   1  18.0  18.0
4   1  27.4  27.4
5   3  47.4   0.0
6   3  50.2   2.8
7   3  57.2   9.8
8   3  64.8  17.4
9   3  76.4  29.0
10  2  80.5   0.0
11  1  85.3   0.0
12  1  87.4   2.1


Access to disposed closure in C#?

Question: I'm investigating Microsoft enterprise library  (data application block)  -- The  samples sln.
They have a sample of reading data asynchronously ( IAsync , although the new ver (6) also support async).
But Resharper(or visual studio- nevermind) shows me  : "Access to disposed closure" : (first i will show the image , so it will be clearer  , then i'll paste the code )

code :
/*1*/    [Description("Execute a command that retrieves data asynchronously")]
/*2*/    static void ReadDataAsynchronously()
/*3*/    {
/*4*/        if (!SupportsAsync(asyncDB)) return;
/*5*/
/*6*/        using(var doneWaitingEvent = new ManualResetEvent(false))
/*7*/        using(var readCompleteEvent = new ManualResetEvent(false))
/*8*/        {
/*9*/            try
/*10*/            {
/*11*/                // Create command to execute stored procedure and add parameters
/*12*/                DbCommand cmd = asyncDB.GetStoredProcCommand("ListOrdersSlowly");
/*13*/                asyncDB.AddInParameter(cmd, "state", DbType.String, "Colorado");
/*14*/                asyncDB.AddInParameter(cmd, "status", DbType.String, "DRAFT");
/*15*/                // Execute the query asynchronously specifying the command and the
/*16*/                // expression to execute when the data access process completes.
/*17*/                asyncDB.BeginExecuteReader(cmd,
/*18*/                    asyncResult = >
/*19*/                    {
/*20*/                        // Lambda expression executed when the data access completes.
/*21*/                        doneWaitingEvent.Set();
/*22*/                        try
/*23*/                        {
/*24*/                            using(IDataReader reader = asyncDB.EndExecuteReader(asyncResult))
/*25*/                            {
/*26*/                                Console.WriteLine();
/*27*/                                Console.WriteLine();
/*28*/                                DisplayRowValues(reader);
/*29*/                            }
/*30*/                        }
/*31*/                        catch (Exception ex)
/*32*/                        {
/*33*/                            Console.WriteLine("Error after data access completed: {0}", ex.Message);
/*34*/                        }
/*35*/                        finally
/*36*/                        {
/*37*/                            readCompleteEvent.Set();
/*38*/                        }
/*39*/                    }, null);
/*40*/
/*41*/                // Display waiting messages to indicate executing asynchronouly
/*42*/                while (!doneWaitingEvent.WaitOne(1000))
/*43*/                {
/*44*/                    Console.Write("Waiting... ");
/*45*/                }
/*46*/
/*47*/                // Allow async thread to write results before displaying "continue" prompt
/*48*/                readCompleteEvent.WaitOne();
/*49*/            }
/*50*/            catch (Exception ex)
/*51*/            {
/*52*/                Console.WriteLine("Error while starting data access: {0}", ex.Message);
/*53*/            }
/*54*/        }
/*55*/    }

Question :
Why is it giving this warning ? there is a manualreset-checked-signal (which runs in a loop) which prevents the using clause to be reached - which means  - no dispose will call .
So why does it yell (warning) ?
Comment: @RoyiNamir The sample might well be correct. It probably is. R# is trying to prevent you `event.Set()` being called after the `using` block finishes. With async calls or **any** use of that object in a lambda, this is theorethically possible. The warning doesn't mean "this is a bug", but "this might be a bug and you should take a look at this code more closely"
Comment: Aside: Why are you using async calls when you're waiting for the result? Seems like using `Task`s would be more straightforward here.
Comment: **SAMPLES** SLN. this SLN contains 15 more examples which also uses TASK( async). that's not my question though.
Comment: I'm curious - are there simpler variants of this situation that R# is smart enough to recognize as "safe"? I would be surprised if so.
Comment: My guess is simply that R# isn't perfect. It can't know (i.e. its static analysis isn't advanced enough to know about how the event interacts with an async call) that the lambda is never called after the `using` goes out of scope, so it warns you this might happen.
Comment: @millimoose well you said that. me -- I thought this is something I should learn from :-)
Comment: I don't understand your statement *"there is a manualreset (which runs in a loop) which prevents the using clause to be reached."*  Even if that were true, R# isn't smart enough to know that.
Comment: @RobertHarvey I meant Waitone which yield a result which is checked under a while loop.
Comment: @default.kramer: a simple repro, which I believe is guaranteed to never actually trigger the issue warned about:  using (var foo = new Foo()) { await Task.Run(()=>foo.Method()) }
Answer: You pass doneWaitingEvent to a lambda that may extend beyond the scope of the using block. I.e. there's a risk that Dispose will have been called when the lambda executes.
Answer: It yells warning because the engine is not smart enough to figure out that the using block will never be exited before the delegate code completes. That is why this is a warning not a error.
You can safely ignore this warning, you can have resharper suppress the warning by wrapping the lines with special comments
asyncDB.BeginExecuteReader(cmd, asyncResult =>
{
    // Lambda expression executed when the data access completes.
    // ReSharper disable AccessToDisposedClosure
    doneWaitingEvent.Set();
    // ReSharper restore AccessToDisposedClosure
    try
    {
        using (IDataReader reader = asyncDB.EndExecuteReader(asyncResult))
        {
            Console.WriteLine();
            Console.WriteLine();
            DisplayRowValues(reader);
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("Error after data access completed: {0}", ex.Message);
    }
    finally
    {
        // ReSharper disable AccessToDisposedClosure
        readCompleteEvent.Set();
        // ReSharper restore AccessToDisposedClosure
    }
}, null);

Comment: Or if you control the function being called you can use JetBrains' `[InstantHandle]` annotation to mark it safe for all the different invocations. [See this question](http://stackoverflow.com/questions/21159776/access-to-disposed-closure-mark-methods-as-safe)
Comment: You may also use "ReSharper disable once AccessToDisposedClosure" to avoid the second comment
Comment: @jtb That is new to resharper in one of the more recent releases I believe. Feel free to post an answer with the annotation. I would upvote it
Answer: The reason you see ReSharper's warnings is that ReSharper's code flow analysis engine is not strong enough to see what is going on: they assume that your code could get to the end of the using clause without doneWaitingEvent being set, which is not possible due to a while loop:
while (!doneWaitingEvent.WaitOne(1000)) {
    Console.Write("Waiting... ");
}

The loop will keep printing the "Waiting... " line until doneWaitingEvent.Set(); gets called, preventing your code from reaching the end of the using block. Same goes for the other warning.
Long story short, this warning can be safely ignored. Add ReSharper's "ignore this warning" comments, and optionally file a bug report with them.
Comment: To future readers, on the "Optionally file a bug report with them", don't dismiss this idea thinking "Oh they are a big company and won't listen to me". I had a similar "not necessary warning" suggesting I should use a different overload of `CreateLinkedCancelationTokenSource`, I reported it and [they fixed it right away](https://youtrack.jetbrains.com/issue/RSRP-425219).
Comment: @ScottChamberlain I'd say it depends... I've created two very serious bugs a _long_ time ago and they still have not fixed them. [First](https://youtrack.jetbrains.com/issue/RSRP-416709#tab=History), and [second](https://youtrack.jetbrains.com/issue/RSRP-349986).
Comment: Looks like they fixed the second, and the first is assigned (to the same person who fixed the second). They aren't just ignoring them :)
Comment: @ScottChamberlain. I too filled a bug and Resharper team fixed it in less than 2 weeks.

Access to disposed closure in C#?


Views pager when view is running on Node Id

Question: I have a view with a contextual filter of Nid running to display the current node.
Does anyone know of a way to set up pagers within a view that can handle paging to  next/prev nodes? So a 'next' link for the subsequent node and a 'prev' link to show previous node.
I would normally use custom pagers for this but this module does not work properly with views 3 that I have installed.
Any help or an alternative to custom pagers would be much appreciated.
Answer: I've used Previous/Next API for this kind of situation (it's only dev, but it worked for me, YMMV).
Comment: Thanks a lot. The module is not as easy to implement as custom pages for different content types but still a great solution.


Formula for finite power series

Question: Are there any formula for result of following power series?
$$0\leq q\leq 1$$
$$
\sum_{n=a}^b  q^n
$$
Answer: Yes, consider the following manipulation:
$$
S = \sum_{n=a}^b q^n = q^a + q^{a+1} + \cdots + q^b = q^a + q(q^a + a^{a+1} + \cdots + q^{b-1}) = q^a + q(S-q^b).
$$
Solving this we find that ....
$$
S = \frac{q^a-q^{b+1}}{1-q}
$$
Answer: Yes.
$$
\sum_{n = a}^{b} q^{n} = \sum_{n = 0}^{b} q^{n} - \sum_{n = 0}^{a-1} q^{n}.
$$
Now, if $M$ is either $a-1$ or $b$, and if $q<1$ then
$$
\sum_{n=0}^{M} q^{n} = {1 - q^{M+1} \over 1 - q}
$$
The last formula is explained here: https://en.wikipedia.org/wiki/Geometric_series#Formula
And if $q=1$, then $q^{n} = 1$ for all $n$.
Comment: $q$ cannot be 1.
Comment: The OP says, $0 \leq q \leq 1$.  And, I hope your nickname is commensurate with your actual publication record.
Comment: The OP ignores the existence of the Geometric Series, hence it ignores the radius of convergence of the same. Which means that you shall have told him that the series diverge for $q = 1$.
Answer: First we assume $a \le b$ (otherwise we swap). With
$$
S = \sum_{k=a}^b q^k
$$
If $q=1$ we have $S=b - a + 1$. For $q < 1$
we have
$$
q S
= \sum_{k=a}^b q^{k+1}
= \sum_{k=a+1}^{b+1} q^k
= S + q^{b+1} - q^a \iff \\
q^a - q^{b+1} = (1-q) S
$$
This gives
$$
S =
\begin{cases}
b - a + 1 & \text{ for } q = 1 \\
(q^a-q^{b+1})/(1-q) & \text{ for }  q < 1
\end{cases}
$$

Formula for finite power series


amplify.js pub/sub Synchronous or Asynchronous?

Question: Are amplify.js's pub/sub events implemented as Synchronous or Asynchronous?
http://amplifyjs.com/api/pubsub/
The documentation does mention priorities...
Answer: Publishing is synchronous; prioritization and synchronicity aren't really related.
Answer: It's synchronous.
The subscription callbacks are called from within the .publish() method's implementation.  There is no setTimeout() code.
As far as priorities go, priority determines where to inject the callback in the callback stack.  This logic is handled in .subscribe().  The .publish() method just executes the callbacks in stack order as previously determined by the .subscribe() method.


how to my receiver is typing a message and show on my browser

Question: i want to check the user is typing a message and want to display it in my chat box, i know setting database flag and checking it by timeinterval function, but i think it should be slow method, is there any way to check it? by the users's machine ip/id .
Comment: use websocket it will be way more efficient.
Comment: how to use that? can u suggest me any better one?
Answer: Hi Use Websocket for this
use this link this will help you
https://www.sanwebe.com/2013/05/chat-using-websocket-php-socket
Answer: You can implement web sockets on your server, so you can pass events between your clients and server.
you can check Ratchet: http://socketo.me/ for php or Socket.io for Nodejs.
Than you can bind on "keyup" an event to notify server of typing, i suggest to throttle the events so you wont end with too many request :)
Comment: Yes, of course if you must to. since you only want to show when user is typing you can receive this typing event on the server and broadcast it back to online users, without the need to store in the db. But if you want to, you cant of course store it in the DB and retrieve it later.
Comment: you can also use websocket for your entire chat app , so you want have to refresh the data on the client on every message sent, just publish socket event from server of new message.
Answer: i think socket.io is what you looking for  http://socket.io/get-started/chat/
Answer: I have found that using sockets is the only good solution for achieving that. https://wisembly.github.io/elephant.io/ .
PHP server side:
use ElephantIO\Client as Elephant;

$elephant = new Elephant('http://localhost:8000', 'socket.io', 1, false, true, true);

$elephant->init();
$elephant->send(
    ElephantIOClient::TYPE_EVENT,
    null,
    null,
    json_encode(array('name' => 'foo', 'args' => 'bar'))
);
$elephant->close();

echo 'tryin to send `bar` to the event `foo`';

Socket.io server side:
var io = require('socket.io').listen(8000);

io.sockets.on('connection', function (socket) {
  console.log('user connected!');

   socket.on('foo', function (data) {
     console.log('here we are in action event and data is: ' + data);
   });
});


Custom Page routing

Question: I created a custom page type called 'Angular page' and a custom twig template for it which loads my angular scripts and prints the <app-root> tag.
I set the page URL to /angularpage and the page will display the data correctly.
The issue is - my angular app supports routing so I want all the angular routes also to load the same node:
For example:
/angularpage/route1
/angularpage/route2
/angularpage/route2/step2

Does anyone know of a way in which I can take the URL alias the user filled and use it as a base for my page so that all routes that start with it lead me to the same node?
(Drupal 8)
Thanks
Yaron
Answer: You should be able to accomplish this with use of a custom route and controller.
Let's assume you have a custom module angular_router. You'll want to create a controller file, which should be located at angular_router/src/Controller/AngularPageController.php:
<?php

namespace Drupal\angular_router\Controller;

use Symfony\Component\HttpFoundation\Request;

/**
 * AngularPageController class.
 */

class AngularPageController {

  /**
   * Creates the response for the angular page.
   *
   * @param string $user
   * @param Request $request
   * @return array
   */
  public function content($param, Request $request) {
    // This is a hardcoded node ID, you'll probably want to load
    // this from config, or something.
    $nid = 3;
    $entity_type = 'node';
    $view_mode = 'default';

    $view_builder = \Drupal::entityTypeManager()->getViewBuilder($entity_type);
    $storage = \Drupal::entityTypeManager()->getStorage($entity_type);
    $node = $storage->load($nid);
    $build = $view_builder->view($node, $view_mode);
    return $build;
  }

}

As noted, this example is hardcoding node ID of '3'. You could create a Form that could store a configurable value, and load this up here. But the point is, this will render the given node ID in the specified view mode, "default" in this case, but again, this could be configurable.
Now that you have a controller, you'll just have to wire it up to your path. So create a routing yml file - the path should be angular_router/angular_router.routing.yml. You can wire up the route by adding this to the file:
angular_router_page:
  path: '/angularpage/{param}'
  defaults:
    _controller: '\Drupal\angular_router\Controller\AngularPageController::content'
  requirements:
    _permission: 'access content'

Note the _controller points to the controller created above. The {param} is just an arbitrary placeholder for an expected user provided parameter. This should serve as the "wildcard", so that going to /angularpage/foo, /angularpage/bar, etc. should all point at this controller, which you have now setup to only ever serve the specified node output.
Hopefully, I've understood what you're wanting to do, and this will work out for your implementation. I can't say that I've verified it against Angular or anything, but I think this answers your question.
Comment: Tyler, thanks for answering. In your answer you defined the URL for the page hardcoded, and I wanted it to be used from the URL alias of a Content Type: Angular Page.  I found a way to do it by creating routes dynamically.  My problem now is how to override/erase the path that Drupal sets from the URL alias so that my configured route works. (if the URL alias is /angularpage then i want my dynamic route to work instead of the Drupal route system.. i there must be some hook that disables it.. I'll try to find it. Thanks !
Comment: You need a route to kick off the Controller

Custom Page routing


Significance testing of three or more correlations using Fisher's transformation

Question: Following on from my earlier posts, as far as I can understand, if I have three correlation coefficients, I will have to test them in pairs to see if there is a significant difference among them.
This means that I would have to use Fishers transformation to work out the z score of r and then the p value of z (which the recommended calculators in the earlier posts do, thankfully) and then ascertain if the p value is higher or lower than my alpha value (0.05) for each pair.
i.e. If 21 to 30 years olds is Age Group 1, 31 to 40 years is Age Group 2, and 41 to 50 years is Age Group 2, my comparison of the correlations between their shopping habits and weight loss would be:

Group 1 vs. Group 2
Group 1 vs. Group 3
Group 2 vs. Group 3

Instead of doing three separate calculations, is there a way to do all these calculations in a single step?
Comment: Could you please be a bit more detailed? As in -- what is your response, your explanatory variables, and what correlations are you interested in? You might not Fisher's transform for testing correlation, a simple t-test may be sufficient.
Comment: @suncoolsu I am testing the correlation between shopping habit and weight gain for these three groups. My results are as follows: Group 1: r=.8978, n=105; Group 2: r=.5678, n=95; and Group 3: r=.7865, n=120.
Comment: I think your data passes the IOTT. That's the interocular trauma test - it hits you between the eyes.  If correlations of .9, .6 and .8 aren't different from each other, what is?
But if you're really interested
Answer: Your question is a perfect example of regression models with quantitative and qualitative predictors. Specifically, the three age groups -- $1,2, \& \,3$  -- are the qualitative variables and the quantitative variables are shopping habits and weight loss (I am guessing this because you are calculating correlations).
I must stress that this is much better way of modeling than calculating separate group-wise correlations because you have more data to model, hence your error estimates (p-values, etc) will be more reliable. A more technical reason is the resulting higher degrees of freedom in the t-test statistic for testing the significance of the regression coefficients.
Operating by the rule that $c$ qualitative predictors can be handled by $c-1$ indicator variables, only two indicator variables, $X_1, X_2$, are needed here that are defined as follows:
$$
X_1 = 1 \text{ if person belongs to group 1}; 0 \text{ otherwise} .
$$
$$
X_2 = 1 \text{ if person belongs to group 2}; 0 \text{ otherwise}.
$$
This implies that group $3$ is represented by $X_1=0, X_2=0$; represent your response -- shopping habit as $Y$ and the quantitative explanatory variable weight loss as $W$. You are now fit this linear model
$$
E[Y]=\beta_0 + \beta_1X_1 + \beta_2X_2 + \beta_3W.
$$
The obvious question is does it matter if we change $W$ and $Y$ (because I randomly chose shopping habits as the response variable). The answer is, yes -- the estimates of the regression coefficients will change, but the test for "association" between conditioned on groups (here t-test, but it is same as testing for correlation for a single predictor variable) won't change. Specficially,
$$
E[Y]= \beta_0 + \beta_3W \text{ -- for third group},
$$
$$
E[Y]= (\beta_0 + \beta_2)+\beta_3W \text{ -- for second group},
$$
$$
E[Y]= (\beta_0 + \beta_1)+\beta_3W \text{ -- for first group},
$$
This is equivalent to having 3 separate lines, depending on the groups, if you plot $Y$ vs $W$. This is a good way to visualize what you are testing for makes sense (basically a form of EDA and model checking, but you need to distinguish between grouped observations properly). Three parallel lines indicate no interaction between the three groups and $W$, and a lot of interaction implies these lines will be intersecting each other.
How do the tests that you ask. Basically, once you fit the model and have the estimates, you need to test some contrasts. Specifically for your comparisons:
$$
\text{Group 2 vs Group 3: } \beta_2 + \beta_0 - \beta_0 = 0,
$$
$$
\text{Group 1 vs Group 3: } \beta_1 + \beta_0 - \beta_0 = 0,
$$
$$
\text{Group 2 vs Group 1: } \beta_2 + \beta_0 - (\beta_0+\beta_1) = 0.
$$
Comment: Testing for the equivalence of slopes is different than testing for the equivalence of correlations. See, for example: http://www.jessicagrahn.com/uploads/6/0/8/5/6085172/comparecorrcoeff.doc
Comment: I agree, but for a single predictor variable, they should be identical because of this relationship $t^* = \frac{\rho\sqrt{n-2}}{\sqrt{1-\rho^2}} \sim t_{n-2}$.
Comment: Also, your document talks about comparing different populations, which is not the case of single predictor.
Comment: The point is that $H_0: \beta_1 = \beta_2 = \beta_3$ could be true, while $H_0: \rho_1 = \rho_2 = \rho_3$ could be false (and vice-versa). The correlation between X and Y depends not only on $\beta$, but also the variance in X and the variance in the errors. If the variance in X and/or the errors differs across the 3 groups, then you are testing different hypotheses.
Comment: Yes you are right (as I said before), but my response assumes that the OP was interested in determining the relationship between wt.loss and shopping habits based on groups (not necessarily correlation). I guess I was wrong because the OP accepted the other answer. Nonetheless, this answer serves as an useful alternative (I hope).
Comment: In general, I totally agree that a regression based approach is usually the most appropriate approach to compare whether the relationship between two variables differs across groups.
Answer: Pairwise testing in this situation is not (yet) justified by the data description. You should be using multi-variable regression methods. An R call might be:
<code>lm( weight_end ~ shop_habit + age_grp + weight_begin)
</code>
Constructing 3 categories is not the best method of controlling for age (or analyzing its contribution if that is the primary question) since categorization can distort continuous relationships, and spline terms remove the need to pick arbitrary split-points. Once there os sufficient evidence of an association of weight change after a proper analysis, then there will be ad-hoc test options that can deployed.
(I did agree with most of what @whuber expressed in a comment, and I generally find his commentary authoritative, but do not understand his stance regarding regression approaches.)


Disable Gyroscope/Device Orientation reading in VRView for web

Question: I have a web application used for virtual house tours. Currently I am using VRView for these tours and it has worked pretty good, however I've ran in to an issue with the gyroscope that I need fixed as soon as possible.
VRView will automatically rotate the camera based on a users device orientation. As a user turns their phone, the virtual house tour will also turn, so the user is able to "look around" the house. This is great for most use cases, however lower end devices have issues when processing this sort of change. I need a way for users to disable the automatic rotation, and simply swipe on their phones to look around.
I've tried the permissions api and trying to revoke access to gyroscope, but due to browser compatibility with that api, it doesn't work. I also can't find any documentation on this in the VRView library. Any help is much appreciated.
Answer: tldr;
You're right, this doesn't seem to be available via their API.  It looks like you may have to fork the library and make some adjustments.  If you want to go down this path, I'd suggest forking the repo, seeing if you can successfully disable the motion emitter, and then see if you can use the webvr-polyfill to initiate drag controls.  It may also be possible to just disable the gyro-based rotation via webvr-polyfill directly.
More in-depth explanation:
The motion information is being published to the VR View iframes (which I believe then feed them to the webvr-polyfill controls) in two locations:
https://github.com/googlearchive/vrview/blob/bd12336b97eccd4adc9e877971c1a7da56df7d69/scripts/js/device-motion-sender.js#L35
https://github.com/googlearchive/vrview/blob/bd12336b97eccd4adc9e877971c1a7da56df7d69/src/api/iframe-message-sender.js#L45
When a browser's UA (user agent) flag indicates it can't use gyro controls, you would need to include a flag in that disables this functionality (or disables the listener in the iframe).
Normally, to enable drag rotation, I think you would then need to write a listener for the start and end of drag events that would translate those events into camera rotation. (Something similar to what this person is suggesting: https://github.com/googlearchive/vrview/issues/131#issuecomment-289522607)
However, it appears that the controls are imported via web-vr-polyfill. The 'window.WebVRConfig' object is coming from web-vr-polyfill, if I'm following this correctly.
See here: https://github.com/googlearchive/vrview/blob/bd12336b97eccd4adc9e877971c1a7da56df7d69/src/embed/main.js#L77
The code above looks like VR View is adjusting the WebVRConfig when it detects a certain flag (in this case the 'YAW_ONLY' attribute).  I believe you would have to do something similar.
https://github.com/immersive-web/webvr-polyfill
See here for the YAW_ONLY attribute: https://github.com/immersive-web/webvr-polyfill/blob/e2958490653bfcda4df83881d554bcdb641cf45b/src/webvr-polyfill.js#L68
See here for an example adjusting controls in webvr-polyfill:
https://github.com/immersive-web/webvr-polyfill#using
Comment: That's some great info! I'll take a look in to some of these and see if I can find some sort of work around. Thank you for these. I was hoping to not have to fork it and just do a drop in JavaScript script, but it looks like it may not be that simple.
Comment: Awesome, let me know how it goes!


Maximum no of trains that k platform can hold

Question: Given arrival and departure times of N trains that reach a railway station, for a given k platforms, return the maximum number of trains that we can house on the k platforms.
k <<< N

Arrival and departure time Array
Input:  arr[]  = {9:00,  9:40, 9:50,  11:00, 15:00, 18:00}
        dep[]  = {9:10, 12:00, 11:20, 11:30, 19:00, 20:00}

This question was asked of me in some interview, so what is best algorithm for that? This question is slightly modified from this question.
I tried greedy algorithm for this question but it is not working for all test cases.
For eg:for k=2
We are given time intervals
arr[]={1:00,1:30,2:00}
dept[]={1:40,2:10,3:30}

'
be removing the {1:30 and 2:10 interval we can do the task for k=2
{1:00-1:40} and {2:00-3:30} as no other train occurs between this time
Comment: you mean minimum number of platform? What's limiting you from having infinity platforms?
Comment: You mean "select the largest possible subset of the given trains such that at any given moment, there are no more than `k` trains at the station"? Please clarify the question.
Comment: I'm voting to close this question as off-topic because it is a mathematical homework question, not a programming question.
Comment: I know how to find minimum no of platform from these given timings, link above also explains this solution. now if we have only k platform then maximum no of trains that can occupies these platform.
Comment: suppose i have 15 trains and these trains requires 7 platform to run smoothly (without any problem ) now let say we can only afford 4 platform ,so some trains from these trains have to take out.
Answer: I think I previously misunderstood the question.
If we have a limited number of platforms I now think we're being asked to cancel a minimum number of trains so that the schedule never overwhelms the platforms.
Brute force:

Merge & Sort the Arrivals and Departures (but keeping track of which is which and identifying which train arrives/departs).
Walk through the array adding one to a counter for each arrival and subtracting one for each departure.
If the counter is k and a train arrives cancel a train which is at the station with the longest time left on the platform at the time of the 'overflowing' arrival. NB: This may be the arriving train or a train already on a platform.
The answer is the total number of trains minus the number of cancelled trains.

Notice that by cancelling a train at the station with the longest time left on the platform we cancel the minimum number of trains. We have to cancel a train at the station to release a platform and the ones with the most time left have maximal potential to free space for future arrivals.
This will be O(N*K) complexity in the worst case if the arrivals and departures are given sorted and can be quickly riffled together. I notice the given example is nearly so.
The complexity is the worst case of the sort and O(N*K) tallying.
Comment: You don't seem to use the value `k`. When you can no longer add a train on a platform, your algorithm will count it anyway.
Comment: It will fail on this test case: `[a1,a2,a3,d3,a4,d4,a5,d5,...,d1,d2]` with `k=2`
Comment: @amit: I thought we were being asked to find the required number of platforms. I now think we're cancelling trains. I've amended the algorithm accordingly. It's the same core idea. In your example we cancel train 2 having the longest time left on the platform.
Answer: It seems to me(I do not have a rigorous proof for it) that a greedy algorithm should work:

Sort the trains by their departure time.
Let's maintain an array lastDeparture of size k, where the lastDeparture[i] is the time when the last train leaves the i platform(initially filled with zeros).
Let's iterate over the trains array and do the following:

Find all such platforms that lastDeparture[i] <= currentTrain.arrival.
If there are no such platforms, continue.
Otherwise, choose the one with the largest lastDeparture value(if there are several such platforms, we can pick any of them).
increase the answer by one and add the current train to this platform(that is, assign lastDeparture[i] = currentTrain.departure.

A sketch of a proof:
Let's assume that our solution is not optimal. Let's find the first train that is in our answer but not in the optimal one. There should be some other train instead of it. But it's departure time is greater. Thus, the total cannot increase when we exchange these two trains.
Time complexity: O(n log n)(step 3 can be handled efficiently using a balanced binary search tree that keeps platforms sorted by the last departure time).
Answer: If I understand the problem correctly, I believe this can be done by using a stack of size k that will contain the trains currently on a platform. For each train (in sorted order by departure times):
while current.ArrivalTime > stack.Last.DepartureTime:
  remove the top element (train) from the stack
push the current train IF there is room, else ignore it
answer = max(answer, stack.Size)

The maximum size that your stack reaches would be the answer to the problem.
This should be O(n log n) because of the sort, since each train enters / leaves the stack at most once.
Comment: I am pretty sure stack structure doesn't help. Eg. (0,2), (1,3).... (arrivalTime, departureTime)
Comment: @ElKamina - I don't understand that example: my algorithm will return 2 for it (or 1 if k = 1), which is the correct answer: when (1, 3) arrives, you'll have to put it on a separate platform than (0, 2). If you don't have enough platforms, you'll have to cancel a train.


Is there a common name for this common chord progression

Question: I've started listening to a specific genre of music which has its roots in Japanese Future Funk. In a lot of these songs I'm listening to, there seems to be a very common chord progression during the break in the middle of the song. I personally think this progression sounds very good, and as a music creator of sorts myself, I want to learn to construct these chords. The problem arises in when I can't seem to figure out the chords or even the notes that make them up. I can get the top and bottom notes, but I can't hear out the middle notes.
My question is does someone know this chord progression? Could you explain how these chords are constructed, and is there a common name for it?
I've provided examples below, but in case a link goes dead, the progression seems to be some sort of 7th progression with the bass and top note stepping down in half steps.
Examples:

Learn to Fly - FKJ

Porter Robinson - Sad Machine

 at 1:16

There are more examples, but these are what I can remember!
Comment: In the FJK track, you mean at about 1:28?
Comment: Yep! @topo morto
Answer: We call this technique planing.
Typically in tonal music, chords move fourths, fifths, and other skips. Only in a few instances do chords move by step, and very rarely do chords move by minor second. Furthermore, these chords are often different qualities.
But around the turn of the twentieth century, composers starting moving a single chord quality up and down by step, and we call this technique planing.
As far as I can hear, in the top example, the composer just planes minor seventh chords:

It begins with a Cm7, then progresses through a C♭m7 (=Bm7), B♭m7, and then a D♭/E♭ to briefly switch to the subdominant A♭.
The second example is similar.
We could also explain this in tonal ways: the C♭m7 is really similar to an augmented sixth chord that then proceeds to a dominant (the B♭m7), but typically a blatant move by semitone using the same quality chord is just understood as planing.


Sorting using comparator on string with numbers and special character

Question: I am facing issue in sorting string with numbers using Comparator where my data is like:
{7.5 mg/5 ml, 5 mg, 5 mg/5 ml, 10 mg, 5 mg/15 ml, 5 mg/5 ml, sample, section}
I tried the below code
Collections.sort(List<Record> records, new Comparator<Record>(){
    @Override
     public int compare(Record o1, Record o2) {
            return o1.compareTo(o2);
        }
}

Am getting the following output when I sort in ascending order
{10 mg, 5 mg, 5 mg/5 ml, 5 mg/15 ml, 5 mg/5 ml, 7.5 mg/5 ml, sample, section}
In the above output the denominator is not sorted properly for 5 mg series and also the sorting is done as like string sort where 10 mg is getting displayed before 5 mg which is wrong. The required output is:
{5 mg, 5 mg/5 ml, 5 mg/5 ml, 5 mg/15 ml, 7.5 mg/5 ml, 10 mg, sample, section}
Please help me to resolve this issue.
Comment: No, we can't - we dont do your work for you. You start by writing your own code; and then when you have specific problems, you write a question with your code and all the details required to help you. Simply see the [help] to understand how this community works; and how/what to ask.
Comment: I  think if you want to have output in the order you mentioned you should use lexicographical order in comparator.
Comment: Please provide us the code.
Answer: If you just want to sort the strings as if they didn't have the accents, you could use the following:
Collections.sort(strs, new Comparator<String>() {
    @Override
    public int compare(String o1, String o2) {
        o1 = Normalizer.normalize(o1, Normalizer.Form.NFD);
        o2 = Normalizer.normalize(o2, Normalizer.Form.NFD);
        return o1.compareTo(o2);
    }
});

For more sophisticated use cases you will want to read up on java.text.Collator.
Here's an example:
Collections.sort(strs, new Comparator<String>() {
    @Override
    public int compare(String o1, String o2) {
        Collator usCollator = Collator.getInstance(Locale.US);
        return usCollator.compare(o1, o2);
    }
});

Custom ordering:
final String ORDER= "qazwsxedcvfrtgbnhyujmkiolp";
Arrays.sort(str, new Comparator() {
@Override
public int compare(String o1, String o2) {
   return ORDER.indexOf(o1) -  ORDER.indexOf(o2) ;
}

});
Comment: Thanks for your response Jay.  But using Normalizer I get the output like {10 mg, 5 mg, 5 mg/5 ml, 5 mg/15 ml, 5 mg/5 ml, 7.5 mg/5 ml, sample, section}.  Instead 10 mg should be displayed after 7.5 mg/5 ml. Also the denominator part (i.e) after "/" is not displayed in order.


Surface integral for a scalar function defined on a discrete surface

Question: Imagine a polyhedral, discrete surface embedded in $\mathbb{R}^3$. Its faces are all triangles. For each vertex, one can compute the discrete mean and Gaussian curvatures and evaluate the sum of square principal curvatures, $k_1^2 + k_2^2$.
The goal is to evaluate the bending energy at a vertex $v_0$ by computing this integral over all incident triangles at the $v_0$ vertex:
$$ \int_{S}{k_1^2+k_2^2 dS} $$
The problem is that there's no analytical expression for the $k_i$ curvatures, they're just scalars associated to each $v_k$ vertex of the mesh.
Is there a way to evaluate this particular surface integral? Or, more clearly, given a random triangle in 3D with scalars attached to its vertices, can a notion of surface integral for a function that just interpolates the scalar values over this triangle be established in a consistent way? (then I can just sum the integrals over all triangles and get a numerical estimate).
NOTE
The purpose of computing that surface integral is to assess the importance of a vertex as a salient feature in a local context for a polyhedral surface. The entire concept should be implementable using a computer programming language (hence the more abstract mathematical quirks and impediments may be overlooked up to an acceptable limit).
For a "quick" reference, a good survey of how some continuous differential geometry concepts are adapted in the discrete context, you can consult CalTech's Graphics Group tech report on the issue: http://multires.caltech.edu/pubs/diffGeoOps.pdf
Solution proposition
Let $f(v) = (k_1^2 + k_2^2)(v)$ be a positive scalar function defined on the polyhedral surface. Evaluating $\int_S{f dS}$ can be done by summing all $\int_{\Delta{ijk}}{f dS}$ over all $(v_i,v_j,v_k)$ triangular faces of the surface. Then the problem is reduced to evaluating:
$$ \int_{\Delta{ijk}}{f dS} = \int_s \int_t { f(v(s,t)) \left| \frac{\partial v}{\partial s} \times \frac{\partial v}{\partial t}\right| ds dt },$$
where $v(s,t)$ is a parameterization for the $\Delta_{ijk}$ triangle. For example,
$v(s,t) = (1-t)((1-s)v_1 + sv_2) + tv_3$, where $(s,t) \in [0,1]^2$.
Now, we require that $f(v(0,0))=f(v_1)=K_1$, $f(v(1,0))=f(v_2)=K_2$ and $f(v(0,1))=f(v_3)=K_3$, i.e. $f(v_i)=K_i$. Hence $f$ can also be a convex combination of $K_1$, $K_2$ and $K_3$, but this time over a triangular domain that is isometric to $\Delta_{v_1v_2v_3}$.

There should exist a parameterization $v^*(s,t)$ of the $\Delta_{v_1v_2v_3}$ triangle such that $\left| \frac{\partial v}{\partial s} \times \frac{\partial v}{\partial t}\right| = 1$ (is this affirmation valid?).
Since the image of $f(\Delta_{v_1v_2v_3})$ is also a triangle (it is a convex combination of $K_i$s), and since there must be a "canonical" parameterization $v^*(s,t)$ of $\Delta$, then we can compute the resulting double integral as the volume under the $K_1K_2K_3$ triangle over the triangular domain that is isometric to $\Delta_{v_1v_2v_3}$. This solid object is a generalized triangular prism (its base planes are not necessarily parallel anymore).
Is there any obvious flaw in the above solution?
Comment: I'm voting to close this question because this looks like an open ended discussion that started more than ten years ago and ended eight years ago.
Comment: @teodron Assumptions and idea in this setting seems legit for me
Comment: This is just a simple impression after reading your question. If you use very simple approximations of curvature you can always achieve an $o(d)$-precision, where $d$ is the maximum diameter of your triangles. But if you want to achieve higher precision, you'll need to do tricky approximations, involving more information of surface geometry. Simple approximations are any from instruments that are usually used for that: linear approximations, splines, etc.
Comment: Actually, any kind of approximation would be good for starters as precision isn't the biggest problem. I wonder if I could consider each triangle to lie in the XOY plane and define a function $f$ over this triangle. $f$ should interpolate the curvature values at the triangle's vertices. Then computing the area under the triangle $(x,y, f(x,y))$ could be the answer, but I have a feeling this is alchemy.
Comment: Are you sure that principal curvatures are associated only to vertices? Defining them on edges would make a lot of sense, one of them would be zero of course (for each edge).
Comment: You can associate them to any point on the polyhedral surface, but if you want to qualitatively asses the importance of a vertex, then you must see what happens in the vicinity of that vertex, i.e. all neighbouring 1-ring incident triangles to it.
Comment: @studiosus One thing that confuses me here is that set of non-zero values of $k_1^2 + k_2^2$ for true polyhedra has zero measure (edges and vertices). Am I missing something?
Comment: @Evgeny: That's not a problem, think of curvature as a signed measure singular with respect to Lebesgue. This works nicely for the intrinsic geometry and Gaussian curvature.
Comment: @studiosus But doesn't it yield that integral will be zero?
Comment: Teodron: Ok, so what do you assign to the edges?
Comment: @studiosus: for an edge, you could always LERP the $k_1^2+k_2^2$ values of its endpoints. The same goes for a point on a triangular face: interpolate its value from the vertices.
Comment: @Evgeny, if you compute the surface integral of a function over something that lacks the dimension of a surface element, I guess common sense (not only measure theory) tells us that the integral is zero.. but this is discrete differential geometry, and the issue is adapting a continuous concept as faithfully to the discrete context. I'm not looking for abstract caveats coming from Measure Theory because, well, I will have to use a computer to perform practical calculations and measurements. I can't just "measure" abstract sets using digital tools :(..
Comment: I'll edit the question to reflect the need of adapting a continuous concept to a discrete context
Comment: @teodron I understand your needs since I'm close enough to programming :) my questions about zero measure set were intended to establish the fact (in first order for myself) that approximating surface with planar triangular patches isn't suitable for bending energy computation — it's always zero w.r.t. to Lebesgue integration (and it's reasonable, since piecewise-linear surface is almost nowhere bended).
Comment: @Evgeny, I agree with your observation, my bad for not clarifying. the scenario. you should consider each point to have a convex combination of the energies stored. at the vertices of the triangle it lies in.
Comment: @Evgeny: No, just think of a measure concentrated in a finite number if atoms. The integral reduces to a finite sum over the atoms: Just forget the Lebesgue measure, it becomes irrelevant!
Comment: I think the treatment is in *finite difference equations* and their numerical approximations.
Answer: The flaw is not that obvious but if you expand one term of the cross operation you will find that the the cross product is independent of the parameter s. The reason for this is that $(1-t)((1-s)v_1+sv_2)+tv_3$ is a good way to describe scalar function on the triangle but a wrong way to describe the area. In other words, the parameters $s$ and $t$ are not orthogonal.
Comment: The $\frac{\partial v}{\partial s} \times \frac{\partial v}{\partial t}$ is an expression involving both $s$ and $t$. Are you certain about the $s$ terms being null? I did not understand what you meant when described the scalar parameters $s$ and $t$ as "not orthogonal". Could you also expand on what you meant by "a good way to describe a scalar function" (actually that is a vector valued function) and "a wrong way to describe area" (the area is usually proportional to the norm of the cross product of the sides of a triangle).


Decomposition of an integral

Question: I came across an integral operator defined with
$$
I_{\alpha} f(x)=\int_{ {\mathbb{R}^n}} \frac{f(y)}{|x-y|^{n-\alpha}}dy,\qquad 0<\alpha<n
$$
with the following property is valid:
There is $t > 0$ so that
$$
I_{\alpha} f(x) = 2 \int_{B(x,t)} \frac{f(y)}{|x-y|^{n-\alpha}}dy =
2 \int_{ {\mathbb{R}^n\setminus B(x,t)}} \frac{f(y)}{|x-y|^{n-\alpha}}dy.
$$
How can we prove this property is true? I try for one dimension but i can not do anything. Because it seems that very surprising property for me. I even thought that maybe the author meant to say
$$
I_{\alpha} f(x) = \int_{B(x,t)} \frac{f(y)}{|x-y|^{n-\alpha}}dy +
 \int_{ {\mathbb{R}^n\setminus B(x,t)}} \frac{f(y)}{|x-y|^{n-\alpha}}dy.
$$
Could the mentioned claim be a typo?
Answer: Let $x \in \mathbb{R}^n$. Then, indeed, for every $t > 0$,
$$
I_\alpha f(x) = \int_{B(x,t)} \cdots + \int_{\mathbb{R}^n \setminus B(x,t)} \cdots
$$
Now, the first quantity is an increasing function of $t$, which is $0$ when $t = 0$. Conversely, the second term is a decreasing function of $t$, which is $0$ when $t = +\infty$.
Both terms are continuous functions of $t$.
From the intermediate value principle, you deduce that there exists $t$ (depending on $x$) such that both terms are equal.
And, for this $t_x$,
$$
I_\alpha f(x) = 2 \int_{B(x,t_x)} \cdots = 2 \int_{\mathbb{R}^n \setminus B(x,t_x)} \cdots
$$

Decomposition of an integral


Dell r710 idrac6 is not visible/reachable on network

Question: I got a (new) r710 server, and tried setting up idrac6, i reset to default and changed the ipv4 settings to an ip in my network, i also tried dhcp, i set up a root password, and still there will be no idrac on my network, no web interface, and even pinging the ip does not work, does anybody know something i could have missed?
Comment: contact the vendor support that you hopefully bought. it's faster special while using nbd support from dell
Comment: If there's a dedicated iDRAC port make sure it's connected to the network.
Answer: Required note: I work for Dell
Regarding @djdomi's comment; there is no vendor support for the R710 and there's no way this was bought new… at least not from Dell. The R710 was released in 2009 . Suffice it to say it's more than a little EOL.
@Zac67 is right, this is more than likely some sort of network issue.
There should be a dedicated iDRAC port - make sure it is plugged in and then give it a ping.
Comment: Thanks for your help,
I know that the server isn't new, but it's a new device for me. The dedicated IDrac port is connected to the same switch as many other ports, and all other devices work on that switch. So there should be no network issue, I set the IDrac networking mode to dedicated and set up static ip v4 and it won't work. I also tried DHCP
Comment: tbh, that's really the only possibility aside from you have a bad iDRAC card. That server is older than dirt so that's not impossible, but if you're seeing link lights it's not my first thought. Try plugging the server directly into something else, put that something else on the same subnet, and see if it works when they're directly connected. That narrows down the problem set for you pretty fast, but with this problem it can really only be one of two things. Bad card, bad network config. If there are link lights, my money is on network config problem.


How to model a recursive probabilistic experiment?

Question: I have a theoretical experiment as follows:
We have two boxes A and B, and N unfair coins (each has different probability for showing Heads).
At the beginning, box A contains all N coins and box B is empty.
the experiment includes following ordered steps:

Step 1: move M coins from box A to box B. The chosen coins must be Heads and have the biggest probabilities for showing Heads.
Step 2: shake both boxes.
Step 3: check box B and return all Tails back to box A.
Step 4: go to (Step 1).

Now the question is, How to measure coins count in box B?
Can we provide a probabilistic measurement that tells how would we be close to (or far from) a specific desired count D?
and how many repeats do need for that?
Comment: any suggestions!!?
Answer: 1) It's unclear why do we need to shake both boxes as Step 2. Based on the description, we move coins from A to B based on their probabilities of showing Heads, while we move coins from B to A based on the experimental result from Step 2. Thus, it's sufficient to shake B only. Is this correct?
2) Nevertheless, assuming I understand the setting correctly, the answer depends on the distribution of "unfairness" in your N coins. Can we assume they can be unfair to any extent, i.e. the probability for showing Heads can be any number in $(0;1)$? If yes, we could model this probability itself as a $(0;1)$-uniformly distributed variable and move forward with order statistics analysis. If no, there should be some additional condition on how unfair a coin could be, say, $0.4<=p<=0.6$ or something.
UPD
Based on your comment, the iterative process is "skewed": at each experimental iteration we move not more than M Heads coins form A to B and all Tail coins from B to A. Based on how the known probabilities $0<p_{(1)}<=p_{(2)}<=...<=p_{(N)}<1$ were initially obtained, this iterative process can either converge or not.
Here we are with a little simulation code for uniformly drawn $p_j$ (which are assumed to be known in your setting, of course):
<code>N = 100
M = 20

p = sort(runif(N)) # uniformly distributed unfairness in coins

p.A = p[1:(N-M)] # box A contains all but M coins with largest Heads probability
p.B = p[(N-M+1):N]

BernoulliExperiment = function(prob){runif(1)<prob}

n.iter = 10000

n.A = integer(n.iter) # number of coins in box A
n.B = integer(n.iter) # number of coins in box B

for(iter in 1:n.iter){
    A2B = apply(as.data.frame(p.A),1,BernoulliExperiment)
    if(sum(A2B)>M)
        A2B[which(A2B)[1:(sum(A2B)-M)]] = FALSE

    B2A = !apply(as.data.frame(p.B),1,BernoulliExperiment)

    temp = p.A[A2B]
    p.A = sort(c(p.A[!A2B],p.B[B2A]))
    p.B = sort(c(p.B[!B2A],temp))
    rm(temp)

    n.A[iter] = length(p.A)
    n.B[iter] = length(p.B)
}

plot(n.A, type='l')
plot(n.B, type='l')
</code>
The process is balanced on average but no specific count is the limit for the number of coins in B. Thus, any number of repeats is insufficient for coming closer to the desired count.
On the other hand, a bimodal distribution of $p_j$ (say, all $p_j$ equal either to 0.1 or 0.9 as an extreme discrete case) could lead to a convergent process of separation into two subsets of coins. This idea comes from Order Statistics by David & Nagaraya, Chapter 8 (https://onlinelibrary.wiley.com/doi/book/10.1002/0471722162)
Comment: 1) Shaking A and B only means that all coins' statuses keep changing based on their probabilities, inside both A and B.
2) I started by assuming that the N probabilities are known, 0 <= p0 <= p1  <= ... <= pN <= 1
Comment: Thank you very much, (and sorry no sufficient reputation to top up the answer). I'm very interested about the conclusion **any number of repeats is insufficient for coming closer to the desired count**, can we derive a proof or a probability inequality to describe such statement?


How do I check what minions a command will target, without running it?

Question: Consider this command line: salt -C 'G@some:grain:value and G@other:grain:value' state.highstate
I want to check that the targeting string will hit the minions I expect it to hit. Highstate is quite slow even in test mode. The obvious alternative is to run test.ping instead, but even that can take a very long time if some minions are down. Salt must have some way to get this information (otherwise it wouldn't know to stop when all targeted minions have returned), but I can't figure out how to get it myself.
Answer: We can get the list of minions using the Salt runner manage module.
Since we are targeting the minions by grains, the master would have to send the command to minions to know which of them match.
Using the up function for example:
salt-run manage.up tgt="G@somegrain:value and G@othergrain:value" tgt_type=compound

Then there are some functions that don't send command to minion, and hence they'll be faster to respond. Though they allow filtering only by IP address. One such example is alived.
List all minions that are considered to be up:
salt-run manage.alived

Answer: Apparently there is an option that does this, it's just not documented in the man page: salt $target --preview-target will show you the minions expected to match $target, without running anything against them or otherwise blocking. Also works fine in conjunction with the target-mode options (e.g. -N, -G, or -C).
Credit to this answer for enlightening me.


MySQL: delete parent records with no children

Question: How do I write a query that deletes records from a parent table for which no children exist?
I have a table resume and a table personal_skill that has a resume_id field to refer the resume table. I need to delete all the records in the resume table for which there is no personal_skill record with such resume_id.
I tried to do it like this:
    DELETE
    FROM
      resume
    WHERE
      version = 0
      AND NOT EXISTS (SELECT NULL
                      FROM
                        personal_skill x
                      WHERE
                        x.resume_id = id)

but this query fails cause I can't use the table I'm deleting from in SELECT part.
Answer: Your try plainly works here:
 DELETE
 FROM resume
 WHERE version = 0
   AND NOT EXISTS (
     SELECT id
     FROM personal_skill x
     WHERE x.resume_id = resume.id
  );

If it doesn't, perhaps the plain id was the problem (does personal_skill have an personal_skill.id column?).
An alternative is:
 DELETE resume
 FROM resume
 LEFT JOIN personal_skill
    ON personal_skill.resume_id=resume.id
 WHERE personal_skill.id IS NULL; -- or any non-NULLable column from personal_skill

Answer: Do this:
DELETE FROM  resume
WHERE version = 0
AND (SELECT COUNT(*) FROM personal_skill x WHERE x.resume_id = id)=0

Answer: Try this:
DELETE resume FROM
resume LEFT OUTER JOIN personal_skill
ON resume.resume_id = personal_skill.resume_id
WHERE personal_skill.resume_id IS NULL

Answer: Try LEFT JOIN syntax:
DELETE R
FROM resume R
LEFT JOIN personal_skill PS ON PS.resume_id = R.id
WHERE PS.id IS NULL AND R.version = 0


What does it mean for a prime ideal to divide a natural number m?

Question: In Cassels and Frohlich (Algebraic Number Theory) Exercise 1, one is asked to derive some properties of the power residue symbol. It begins by stating the following:

Let $m$ be a fixed natural number and $k$ a fixed global field containing group $\mu_m$ of $m$th roots of unity. Let $S$ denote the set of primes of $k$ consisting of the archimedean ones and those dividing $m$.

If a prime ideal $\frak p$ in $\mathcal{O}_k$ does note divide $m$ is that equivalent to saying it is prime to $m$? (where I mean that $\frak p$ is prime to $m$ if $\frak p$ does not divide $m\mathcal{O}_k$)
Answer: Given a number field $K$, its ring of integers $\mathcal{O}_K$ is a Dedekind domain, which means that every ideal has a unique factorization into prime ideals.  Given $m \in \mathbb{Z}$, then $m \mathcal{O}_K$ is an ideal of $\mathcal{O}_K$, hence has a prime factorization:
$$
m \mathcal{O}_K = \mathfrak{p_1}^{e_1} \cdots \mathfrak{p_t}^{e_t}
$$
for some prime ideals $\mathfrak{p_1}, \ldots, \mathfrak{p_t}$ of $\mathcal{O}_K$ and some positive integers $e_1, \ldots, e_t$.  These prime ideals are said to divide $m$.
Another way to think about divisibility is by containment.  Given ideals $\mathfrak{a}$ and $\mathfrak{b}$ of a Dedekind domain, $\mathfrak{a}$ divides $\mathfrak{b}$ iff $\mathfrak{a} \supseteq \mathfrak{b}$, i.e., to contain is to divide.  Note that
$$
m \mathcal{O}_K = \mathfrak{p_1}^{e_1} \cdots \mathfrak{p_t}^{e_t} \subseteq \mathfrak{p}_i
$$
for $i = 1, \ldots, t$, so this agrees with the previous notion of divisibility.
This allows us to answer your second question.  Suppose $\mathfrak{p}$ does not divide $m \mathcal{O}_K$, so $\mathfrak{p} \not \supseteq m \mathcal{O}_K$.  Then $\mathfrak{p} + m \mathcal{O}_K \supsetneq \mathfrak{p}$ is strictly larger than $\mathfrak{p}$.  But prime ideals are maximal in a Dedekind domain, so this means that $\mathfrak{p} + m \mathcal{O}_K = \mathcal{O}_K$.  Then $\mathfrak{p}$ and $m \mathcal{O}_K$ are comaximal, which is a generalization of being relatively prime.  (See Bézout's Lemma.)


$f(x_1,y_1)>f(x_2,y_2)$ and $g(x_1,y_1)>g(x_2,y_2)$ $\implies$ $x_1>x_2$ and $y_1>y_2$: what other conditions are needed?

Question: in order to make the derivation in the title, what other conditions are needed, besides:
$\frac{\partial f}{\partial x} > 0$ and $\frac{\partial f}{\partial y} > 0$ and $\frac{\partial g}{\partial x} > 0$ and $\frac{\partial g}{\partial y} > 0$?
In single variable calculus, one only needs the monotonicity to make such derivations, but haven't seen anything analogous for multivariate functions.
thank you.
Comment: I don't understand the edit. How is the question different now? $f$ and $g$ seem totally unrelated.
Comment: @Marktmeister I understand what you mean. In the case I am facing, f and g both have concrete forms. So supposedly one more condition involving one more function may provide nonredundant information.
Comment: So do you require the partial derivatives to be positive or not? Else, one could do something silly like $f(x,y) := x$ and $g(x,y) := y$...
Answer: Assume that your propierty holds for $f$. Then, the converse is also true: If $x_1\leq x_2$ or $y_1\leq y_2$ then $f(x_1,y_1)\leq f(x_2,y_2)$. So, for every couple $(x_1,y_1),(x_2,y_2)\in\mathbb{R}^2$ we have $f(x_1,y_1)\leq f(x_1,y_2)$ and $f(x_1,y_2)\leq f(x_2,y_2)$ (as $x_1\leq x_1$ and $y_2\leq y_2$).
We show that the inequalities above can't be strict: if  $f(x_1,y_1)<f(x_1,y_2)$ then $x_1<x_1$, which is a contradiction; if $f(x_1,y_2)<f(x_2,y_2)$ then $y_2<y_2$, which is also a contradiction. Then it must be $f(x_1,y_1)=f(x_1,y_2)$ and $f(x_1,y_2)=f(x_2,y_2)$, hence $f(x_1,y_1)=f(x_2,y_2)$. As this is true for every couple $(x_1,y_1),(x_2,y_2)\in\mathbb{R}^2$, $f$ is constant. Then the only functions verifying your property are, vacuously, the constant ones.
Comment: Thank you. I gather that you mean with the conditions I originally allow, it's not possible to show that the results hold for all possible (x_1, y_1) and (x_2, y_2) in their domain. In this case, is there any way to 1, derive a weaker result (in terms of any types of inequalities between (x_1, y_1) and (x_2, y_2)) with the original conditions; or: 2, add extra conditions so as to arrive at the result? (I edited the original post and added a similar but different condition as a starter) I guess I am trying to learn any general methodology for this type of problems, potentially non-elementary.
Comment: PS, for those of you confused by the seeming disconnect between R.V.N.'s answer and my question: I have edited my Q after his/her answer was made.
Comment: I don't understand the meaning of your new hypothesis. Anyways, note that my proof is true whenever it's true that if $(x_1,y_1),(x_2,y_2)\in\operatorname{Dom} f$, then $(x_1,y_2)\in\operatorname{Dom} f$ (you could do an analogous proof with $(x_2,y_1)\in\operatorname{Dom} f$). This is independente of $f$ being continuous, differentiable, or whatever. Then, the only restriction you could put to $f$ for that property holding, is restricting its domain so that if $(x_1,y_1),(x_2,y_2)\in\operatorname{Dom} f$, then $(x_1,y_2),(x_2,y_1)\not\in\operatorname{Dom} f$.
Comment: This could be done by setting $\operatorname{Dom} f:=\{(t,\varphi(t))\in\mathbb{R}^2 : t\in\mathbb{R}\}$ where $\varphi$ is any real function.


Emitted IL NullReferenceException on call to method on Int32

Question: I'm new to IL in .NET, and am messing around trying to autogenerate a method that is pure boilerplate.
My test app generates the below IL, but it is throwing a NullReferenceException at IL_002f, after retrieving the value of an int property on an instance which is known not to be NULL (both via the IL (IL_0001) and from the test case I generated). The instance is passed in the first argument (arg.0) to the emitted method.
I expect the value of BasicClass.IntProperty to be the first item on the stack before calling System.Int32.ToString(), so what is possibly going wrong here? Any help to get my head out of my ahem on this would be appreciated.
IL_0000: ldarg.0
IL_0001: brfalse    IL_0045
IL_0006: ldarg.0
IL_0007: call       System.String get_StringProperty()/QuickSearchTests.Entities.BasicClass
IL_000c: dup
IL_000d: brfalse    IL_0022
IL_0012: ldarg.1
IL_0013: call       Boolean ContainsIgnoreNull(System.String, System.String)/MyCompany.MyProduct.Common.Extensions.StringExtensions
IL_0018: brtrue     IL_0047
IL_001d: br         IL_0023
IL_0022: pop
IL_0023: ldarg.2
IL_0024: brfalse    IL_0045
IL_0029: ldarg.0
IL_002a: call       Int32 get_IntProperty()/QuickSearchTests.Entities.BasicClass
IL_002f: call       System.String ToString()/System.Int32
IL_0034: ldarg.1
IL_0035: call       Boolean ContainsIgnoreNull(System.String, System.String)/MyCompany.MyProduct.Common.Extensions.StringExtensions
IL_003a: brtrue     IL_0047
IL_003f: br         IL_0045
IL_0044: pop
IL_0045: ldc.i4.0
IL_0046: ret
IL_0047: ldc.i4.1
IL_0048: ret

For reference, here is the definition of BasicClass
public class BasicClass
{
    public string StringProperty { get; set; }
    public int IntProperty { get; set; }
    internal string InternalStringProperty { get; set; }
}

Comment: I recommend to write your code in c# (or f#, vb.net), compile it, decompile it and take the resulting IL. Maybe tweak or change it from there, but thats far easier than fiddling with IL from zero. Actually you can do that online here: https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBLANgHwAEBmAAkICZSBhUgbwFgAoU18swlUgWQAoBKeszYjSARgB0AFQgBlDFGwA7AOYCA3MLYBfZtqA=== As you can see there you have to get a reference to your integer to call ToString() on it.
Comment: Yes i am pretty sure you need to get a reference to structs in general to call methods on them.
Comment: I noticed that lodloca in the decompiled version of what I'm replacing. Are you suggesting that I need the reference, and not the actual value, on the stack? Might be time to dig in to the EMCA
Answer: You are calling a method on a non object: the integer value needs to be boxed in order to have the method invocation work. I would patch your code this way (Z is your choice):
.locals
[Z] int32 temp

    callvirt instance int32 QuickSearchTests.Entities.BasicClass/BasicClass::get_IntProperty()
    stloc.Z
    ldloca.s temp
    call instance string [System.Runtime]System.Int32::ToString()

A word of warning: writing IL directly is something particularly challenging. You must be aware that once your IL code works as you expect, you have not finished yet, as you should verify it with peverify. Valid IL is not automatically verifiable.
For this reason, as suggested in the comment, the best approach is to study the documentation and learn from a very special teacher: the compiler. Start by writing your code in a supported language and learn how the compiler turns into IL.


Module similar to module filter to filter content and users?

Question: I use Module filter module to filter the long list of modules. It comes very handy to find a module rather than using CTRL+F always. I was wondering if there is a module which can filter the content (at admin/content) and/or users (at admin/people) as well.
Comment: This is the one I am using and find it good enough http://drupal.org/project/cmf/
Comment: @kantu it only has version for D6.. I'm using Drupal 7
Answer: Contentment (along with VBO) looks like a winning combination.


How to determine if Standard Deviation is high/low

Question: I have derived the following response time data for a performance test I am running:
Min - 8sec
Max - 284sec
Average - 28sec
Standard Deviation - 27sec
What does the standard deviation say about the response time data distribution? When you say low/high standard deviation, what does this actually mean? Is this in comparison to the Average/Min/Max?
I know what standard deviation is and how it's computed. I'm just not sure how to tell if it is high or low.
Comment: Aren't terms like "high" or "low" just a matter of subjective judgement? The data you have seem to suggest that time is very roughly speaking 28sec +/- 27 sec, so in a very naive sense you expect the results to usually fall between 1sec and 60sec. I'd say it's rather high deviation, but I suppose it depends on the characteristic of a problem.
Comment: Yes, what confuses me is how to tell if a standard deviation is high or low. The examples I've read so far have not said what makes it high or low.
Comment: "I know what standard deviation is". Hmm ... if you do know what [standard deviation](http://en.wikipedia.org/wiki/Standard_deviation) is, you should know that it is a measure of dispersion of data ...
Answer: If you take your cues from the financial industry, you can use the coefficient of variation (CV), which is the standard deviation / mean.  This formula is used to normalize the standard deviation so that it can be compared across various mean scales.
As a rule of thumb, a CV >= 1 indicates a relatively high variation, while a CV < 1 can be considered low.
Some references to usage as "rule of thumb"
http://www.readyratios.com/reference/analysis/coefficient_of_variation.html
http://www.mhnocc.org/forum/index.php?t=msg&goto=234&
Comment: It seems dubious to me to extend this outside of the financial industry (if that's where its used). Logically the CV can only be greater than 1 if the Std deviation is higher than the mean. Which in most data sets seems unlikely.
Comment: @Morvael the CV was invented by Karl Pearson more than a century ago, who is deemed as the founder of mathematical statistics. The fact that is used by the financial industry is a sign of how widely is used, not of a lack of "mathematical seriousness" if you will.
Comment: Could you please share your source of information for this?
Comment: I have listed a couple of references above.
Answer: When trying to figure this out myself I opted for using the Std deviation as a percentage of the range. Looking at this graph:

from that image I would I would say that the SD of 5 was clustered, and the SD of 20 was definitionally not, the SD of 10 is borderline.
More mathematically,

The SD of 5 has 68% of the values within 10% of the range
The SD of 10 has 68% of the values within 20% of the range
The SD of 20 has 68% of the values within 40% of the range

So as a purely internal measure of High / Low Std deviation I chose to say if the SD was less than 10% of the range then its low, greater than 10% of the range then high.
But you could of course choose different percentages based on your own data sets.
https://www.scribbr.com/statistics/standard-deviation/


How to perform x = x + y in Rules

Question: How can I add this action in Rules? This is my pseudocode:
1 total=0;
2 //loop through each line item {
3 //get quantity of each product
4 total = total + line_item_quantity;}
5 if total =< 2 then total = 0;
6 total_cost = total * $1.50

I think I can get everything working with the Conditional Rules module. but I cannot get
x = x + y

to work on Rules because they say that the variable already exists.
Also, how do I use conditions on entities like calculated shipping cost? What's the variable name?
Comment: I don't remember now, but wouldn't `x += y` work?
Comment: Actually I was referring to adding an action (so that I don't need to do it programatically). Is it possible?
Answer: Have a look at my answer to the question about "How to add up all items of a field collection field using Rules?". Your question is, IMO, a minor variation of it. Just replace article-details-item:field-price by line_item_quantity (as in your pseudocode) and it is close to identical.
The custom rule to do the calculation, looks like so:
{ "rules_calculate_sum_of_prices_in_all_field_collection_items" : {
    "LABEL" : "Calculate sum of prices in all field collection items",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_view--article" : { "bundle" : "article" } },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_article_details" } }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "\u003Cstrong\u003EDrupal calculator\u003C\/strong\u003E started ..." } },
      { "variable_add" : {
          "USING" : { "type" : "decimal", "value" : "0" },
          "PROVIDE" : { "variable_added" : { "total_price" : "Price total" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "node:field-article-details" ] },
          "ITEM" : { "article_details_item" : "Article details item" },
          "DO" : [
            { "data_calc" : {
                "USING" : {
                  "input_1" : [ "total-price" ],
                  "op" : "+",
                  "input_2" : [ "article-details-item:field-price" ]
                },
                "PROVIDE" : { "result" : { "calculation_result" : "Calculation result" } }
              }
            },
            { "data_set" : { "data" : [ "total-price" ], "value" : [ "calculation-result" ] } },
            { "drupal_message" : { "message" : "After adding a price of \u003Cstrong\u003E[article-details-item:field-price]\u003C\/strong\u003E for field collection item with id \u003Cstrong\u003E[article-details-item:item-id]\u003C\/strong\u003E, subtotal is \u003Cstrong\u003E[calculation-result:value]\u003C\/strong\u003E." } }
          ]
        }
      },
      { "drupal_message" : { "message" : "The \u003Cstrong\u003ETotal price\u003C\/strong\u003E for all prices included as field collection items is \u003Cstrong\u003E[total-price:value]\u003C\/strong\u003E." } },
      { "drupal_message" : { "message" : "\u003Cstrong\u003EDrupal calculator\u003C\/strong\u003E ended ..." } }
    ]
  }
}

Enough to get you going and get it to work (or should I say "How good are you in reading/digesting the Rules-export-language)?

How to perform x = x + y in Rules


SQL SELECT query for multiple tables

Question: I have these tables:
USERS:
user_ID
username
password
email
data_registered

POSTS:
post_ID
user_ID
post_title
post_content
post_data

CATEGORY:
cat_ID
post_ID
cat_title

Now I used this situation:
in USERS table I have:
(1, 'admin, '5hj63jhn120011', 'firstname.lastname@example.com', '15.02.2012')

in POSTS table:
(1, 1, 'Hello', 'Content goes here', '15.02.2012')

in CATEGORY table:
(1, 1, 'web developing'),
(2, 1, 'software programming'),
(3, 1, 'web design')

So I have only 1 user, 1 post, and 3 categories. How to select them in one statement? I used this statement:
SELECT
  p.post_title,
  p.post_content,
  u.username,
  c.cat_title
FROM
  posts p
  LEFT JOIN users u
     ON p.user_ID = u.user_ID
  LEFT JOIN category c
     ON c.post_ID = p.post_ID

but this select 3 rows with 3 different categories. I'm still learning to make this JOIN queries properly so I would appreciate any help.
And after that, for example, I will have situation to select data from COMMENTS table as well, so this is going to be complicated. Just to mention this is comment table:
COMMENTS:
comment_ID
user_ID
post_ID
c_username
c_email
c_content

It's gonna be tough to select this comments with user , post and category altogether. So one more question would be can I split this select queries and is this a good practice generaly (when developing with PHP) ?
Comment: can you provide the sample result set you need?
Comment: It has nothing to do with your question bu are you sure that there should be only one post corresponding to a category?
Comment: @C.Champagne you mean one post - one category?
Comment: @BojanSavic I mean n posts - n Categories. A category should not be limited to one post I think. There should be several posts related to mysql for example. The best comparison I can make in StackOverflow is the association of tags (=categories) to questions (posts)
Answer: Try:
SELECT p.post_title,
       p.post_content,
       u.username,
       group_concat(c.cat_title) categories
FROM posts p
LEFT JOIN users u ON p.user_ID = u.user_ID
LEFT JOIN category c ON c.post_ID = p.post_ID
group by p.post_id

- if you want to see all the categories for a single post in the same row.
Answer: Use something like that:
SELECT
  p.post_title,
  p.post_content,
  u.username,
  GROUP_CONCAT(c.cat_title + ',') cat_titles
FROM posts p
LEFT JOIN users u
  ON p.user_ID = u.user_ID
LEFT JOIN category c
  ON c.post_ID = p.post_ID
GROUP BY
  p.post_title,
  p.post_content,
  u.username

I'm not sure in proper usage of GROUP_CONCAT, but looks like if will work
Answer: I think it should be like this instead:
POSTS:
post_ID
user_ID
cat_ID
post_title
post_content
post_data

CATEGORY:
cat_ID
cat_title

As categories don't need posts to relate to but each post will need a category to relate to.
Update:
If many-to-many is the intention then it should be like this:
POSTS:
post_ID
user_ID
post_title
post_content
post_data

CATEGORY:
cat_ID
cat_title

POST_CATEGORY:
post_ID
cat_ID

Comment: So a post can only have one category. A better design would probably be Posts, PostCategory, Category.
Comment: This would be a different relationship - in the original question, a post could belong to many categories simultaneously, but in this answer a post could only ever belong to a single category.
Comment: thanks for the tip, I'm still not good with making good database tables, I know the basic stuff, so when making few tables I put some additional complications with no need at all ;)
Comment: @Mark Well in the design it's still not correct if many-to-many was the intention as each category will be redundant with its title on each post using it, so I assumed that this is what was intended.
Answer: without have tried it, I think the solution is:
SELECT p.post_title, p.post_content, u.username, c.cat_title
FROM users u LEFT JOIN posts p ON u.user_ID = p.user_ID
LEFT JOIN category c ON p.post_ID = c.post_ID

if you change the order of the ID columns, the meaning of LEFT JOIN changes. So you get three result rows....
Comment: hmm given the data the results are going to be the same.

SQL SELECT query for multiple tables


How does std::vector::reserve actually work?

Question: I understand that .reserve() reserves memory for the vector without actually modifying its size. But how is this implemented? How can you just reserve memory without allocating it?
EDIT: I'm asking specifically about how to reserve memory without allocating it, not about how std::vector works in general
Comment: Does this answer your question? [How does c++ std::vector work?](https://stackoverflow.com/questions/3167272/how-does-c-stdvector-work)
Comment: @OrangeDog I'm asking specifically about how to reserve memory, since I know how dynamic memory allocation works. Thanks for the suggestion though
Comment: @OrangeDog Actually, I found this response (https://stackoverflow.com/a/3167551/13647419) to the question you linked, which touches a bit on the subject of reserving memory, but it still doesn't make too much sense. Is that memory used, or not?
Comment: It does describe how `reserve` works. It allocates memory.
Comment: Yeah, I was explained that `reserve` actually allocates memory, so I'll take a closer look at the answers that you sent as well, since I misunderstood
Answer: vector::reserve does allocate memory, so your question about reserving memory without allocating is incorrect. The point is that reserving memory can be done without changing the vectors size. Basically a vector has two sizes, it's size and it's capacity. reserve allocates memory and changes the capacity, but not the size.
At any given time the following is true 0 <= size <= capacity. The capacity reflects the amount of memory allocated, the size reflects the number of constructed elements in that memory.
Comment: @H-005 No, that's not true (at least not true of vector).
Comment: Oh... But from what I understand, the memory that is reserved can still be used in a different way, right?
Comment: @H-005 New elements can be constructed in the reserved memory but the vector still "owns" all the memory. There's no way to reuse or borrow the extra capacity.
Answer: You misunderstood one main thing: std::vector::reserve actually allocates memory.
Let's say we create a custom Allocator like:
template <typename T>
struct Allocator
{
    using value_type = T;

    Allocator() = default;

    T* allocate( std::size_t N )
    {
        N *= sizeof( T );
        std::cout << "Allocation " << N << " bytes" << std::endl;
        return static_cast< T* >( ::operator new( N ) );
    }

    void deallocate( T *ptr, std::size_t N )
    {
        std::cout << "Deallocation " << (N * sizeof * ptr) << " bytes" << std::endl;
        ::operator delete( ptr );
    }
};

If you use it like:
int main()
{
    std::vector< int, Allocator< int > > v;
    v.reserve( 100 );
}

The output would be:
Allocation 400 bytes
Deallocation 400 bytes

You can play with it here.
Answer: The size of a vector is the number of elements that it holds. The capacity of a vector is the number of elements that it could hold without allocating additional memory. reserve can increase the capacity by reallocating and copying the elements. That increases the capacity but doesn't change the size.


Find specific string in subdirectories and order top directories by modification date

Question: I have a directory structure containing some files. I'm trying to find the names of top directories that do contain a file with specific string in it.
I've got this:
grep -r abcdefg . | grep commit_id | sed -r 's/\.\/(.+)\/.*/\1/';

Which returns something like:
topDir1
topDir2
topDir3

I would like to be able to take this output and somehow feed it into this command:
ls -t | grep -e topDir1 -e topDir2 -e topDir3

which would returned the output filtered by the first command and ordered by modification date.
I'm hoping for a one liner. Or maybe there is a better way of doing it?
Comment: Since you mention commit ids, it seems like it is git related. Can you explain in plain English what do you really want to get?
Answer: This should work as long as none of the directory names contain whitespace or wildcard characters:
ls -td $(grep -r abcdefg . | grep commit_id | dirname)

Comment: Your solution of ls -td $(...) solves my problem. The "dirname" part does not do what I wanted, but after replacing dirname with sed, everything falls back into place.
Comment: Isn't your `sed` command just getting the directory part of the filenames?