text:
Q: Wondering if I could use APPLY here instead of using FOR LOOP for optimization in this case? I'm setting up an equation of getting the netvalues of the stock combinations.
The original equation:
net values of stock * weight.stock/ number of stock types + bond * weight.bond/ number of bond types + cash * weight.cash/ number of cash types
for a sequence of dates.
The method of matching: For instance, any rows in BackTest.table with date before 2008-7-15 will match the first row in Weight.table (which covers the dates from 2008-5-01 to 2008-7-15.)
Here is a chunk of the BackTest.table for easier imagination. Headers of this table are: Date, stock type1, stock type2, ..., bond type 1, bond type2, ..., cash type 4. (Which is just an example of type numbers) It actually matches the type numbers in Weight.table.
         Date s1         s2           s3 s4 s5 b1 b2 b3 b4 b5 b6 b7 c1 c2 c3 c4
2  2008-07-01  0 -3.0158124 -0.055652040  1  0  0  0  0  0  0  0  0  0  0  0  0
3  2008-07-02  0  0.3838345 -0.119046476  1  0  0  0  0  0  0  0  0  0  0  0  0
4  2008-07-03  0  2.7602604  0.009611965  1  0  0  0  0  0  0  0  0  0  0  0  0
5  2008-07-04  0 -0.5370067 -0.009611041  1  0  0  0  0  0  0  0  0  0  0  0  0
6  2008-07-05  0  0.0000000  0.000000000  1  0  0  0  0  0  0  0  0  0  0  0  0
7  2008-07-06  0  0.0000000  0.000000000  1  0  0  0  0  0  0  0  0  0  0  0  0
8  2008-07-07  0  5.1583803  0.032680681  1  0  0  0  0  0  0  0  0  0  0  0  0
9  2008-07-08  0  0.8500539  0.048044124  1  0  0  0  0  0  0  0  0  0  0  0  0
10 2008-07-09  0  3.6352579  0.048981473  1  0  0  0  0  0  0  0  0  0  0  0  0
11 2008-07-10  0 -1.5689846  0.052797297  1  0  0  0  0  0  0  0  0  0  0  0  0
12 2008-07-11  0 -0.6688334  0.045093882  1  0  0  0  0  0  0  0  0  0  0  0  0
13 2008-07-12  0  0.0000000  0.000000000  1  0  0  0  0  0  0  0  0  0  0  0  0
14 2008-07-13  0  0.0000000  0.000000000  1  0  0  0  0  0  0  0  0  0  0  0  0
15 2008-07-14  0  1.0436299  0.033565414  1  0  0  0  0  0  0  0  0  0  0  0  0
16 2008-07-15  0 -3.8589001  0.004793450  1  0  0  0  0  0  0  0  0  0  0  0  0
17 2008-07-16  0 -4.0513392  0.034511187  1  0  0  0  0  0  0  0  0  0  0  0  0
18 2008-07-17  0 -1.0070062  0.009583134  1  0  0  0  0  0  0  0  0  0  0  0  0
19 2008-07-18  0  3.5303394  0.014373323  1  0  0  0  0  0  0  0  0  0  0  0  0
20 2008-07-19  0  0.0000000  0.000000000  1  0  0  0  0  0  0  0  0  0  0  0  0
21 2008-07-20  0  0.0000000  0.000000000  1  0  0  0  0  0  0  0  0  0  0  0  0

Here's another chunk of the Weight.table for easier imagination.
Date          Stock  Numbers1 Bond  Number2 Cash     Number3
1 2008-04-30 0.0642        5 0.7858       2 0.1500       2
2 2008-07-15 0.0801        5 0.7699       2 0.1500       2
3 2008-07-31 0.0727        6 0.7773       2 0.1500       1
4 2008-10-31 0.1373        4 0.7127       2 0.1500       1
5 2008-11-30 0.1457        3 0.7144       2 0.1399       2
6 2009-01-31 0.1791        5 0.7242       2 0.0967       1

Here are the dputs of header of Weight.table and BackTest.table
dput(head(Weight.table))
structure(list(Date = structure(c(13999, 14075, 14091, 14183,
14213, 14275), class = "Date"), Stock = c(0.0642, 0.0801, 0.0727,
0.1373, 0.1457, 0.1791), Numbers1 = c(5L, 5L, 6L, 4L, 3L, 5L),
    Bond = c(0.7858, 0.7699, 0.7773, 0.7127, 0.7144, 0.7242),
    Number2 = c(2L, 2L, 2L, 2L, 2L, 2L), 现金 = c(0.15, 0.15,
    0.15, 0.15, 0.1399, 0.0967), Number3 = c(2L, 2L, 1L, 1L,
    2L, 1L)), row.names = c(NA, 6L), class = "data.frame")

dput(head(BackTest.table))
structure(list(Date = structure(c(14061, 14062, 14063, 14064,
14065, 14066), class = "Date"), s1 = c(0, 0, 0, 0, 0, 0), s2 = c(-3.01581241943634,
0.383834486785705, 2.76026041158503, -0.537006711952127, 0, 0
), s3 = c(-0.0556520404148886, -0.119046476128297, 0.00961196497399089,
-0.00961104116408056, 0, 0), s4 = c(1, 1, 1, 1, 1, 1), s5 = c(0,
0, 0, 0, 0, 0), b1 = c(0, 0, 0, 0, 0, 0), b2 = c(0, 0, 0, 0,
0, 0), b3 = c(0, 0, 0, 0, 0, 0), b4 = c(0, 0, 0, 0, 0, 0), b5 = c(0,
0, 0, 0, 0, 0), b6 = c(0, 0, 0, 0, 0, 0), b7 = c(0, 0, 0, 0,
0, 0), c1 = c(0, 0, 0, 0, 0, 0), c2 = c(0, 0, 0, 0, 0, 0), c3 = c(0,
0, 0, 0, 0, 0), c4 = c(0, 0, 0, 0, 0, 0)), row.names = 2:7, class = "data.frame")

However, it takes a bit long to get what I want. So I was trying to use sapply, but the results are different. It seems like the sapply didnt go through the IFELSE process?
To get the values, I have set a constant k, whenever the dates in Backtest.table matches the dates in Weight.table, k = k+1, so it moves to the next row and uses the new weights to calculate the netvalues.
The original code that worked:
k <- 1

for (t in 1:nrow(BackTest.table)) {
if (BackTest.table[t, 1] %in% Weight.table[, 1] == FALSE) {
    NetReturnPt.table[t, 2] <- sum(BackTest.table[t, 2: ncol(BackTest.table)]*
    c(rep(Weight.table[k, 2]/ Weight.table[k, 3], Weight.table[k, 3]),
      rep(Weight.table[k, 4]/ Weight.table[k, 5], Weight.table[k, 5]),
      rep(Weight.table[k, 6]/ Weight.table[k, 7], Weight.table[k, 7])
      ), na.rm = TRUE)
  }
  else {NetReturnPt.table[t, 2] <- sum(BackTest.table[t, 2: ncol(BackTest.table)]*
        c(rep(Weight.table[k, 2]/ Weight.table[k, 3], Weight.table[k, 3]),
          rep(Weight.table[k, 4]/ Weight.table[k, 5], Weight.table[k, 5]),
          rep(Weight.table[k, 6]/ Weight.table[k, 7], Weight.table[k, 7])
          ), na.rm = TRUE)
k <- k + 1
  }
}

dput(head(NetReturnPt.table[, 2]))
[1] -0.026597604  0.016239878  0.048405161  0.005821428  0.012840000  0.012840000
dput(NetReturnPt.table[20:25, 2])
[1]  0.016020000  0.073282388  0.014539880  0.003858773  0.065490672 -0.003378064

The APPLY function that doesn't give the right values after the first few data:
k <- 1

TestApply <- function(t) {
if (BackTest.table[t, 1] %in% Weight.table[, 1] == FALSE) {
    NetReturnPt.table[t, 2] <- sum(BackTest.table[t, 2: ncol(BackTest.table)] *
    c(rep(Weight.table[k, 2]/ Weight.table[k, 3], Weight.table[k, 3]),
      rep(Weight.table[k, 4]/ Weight.table[k, 5], Weight.table[k, 5]),
      rep(Weight.table[k, 6]/ Weight.table[k, 7], Weight.table[k, 7])
      ), na.rm = TRUE)
  }
  else { NetReturnPt.table[t, 2] <- sum(BackTest.table[t, 2:ncol(BackTest.table)] *
       c(rep(Weight.table[k, 2]/ Weight.table[k, 3], Weight.table[k, 3]),
         rep(Weight.table[k, 4]/ Weight.table[k, 5], Weight.table[k, 5]),
         rep(Weight.table[k, 6]/ Weight.table[k, 7], Weight.table[k, 7])
         ), na.rm = TRUE)
k <- k + 1
  }
}

test.result <- sapply(1: nrow(BackTest.table), function(t) TestApply(t))
dput(head(test.result))
[1] -0.026597604  0.016239878  0.048405161  0.005821428  0.012840000  0.012840000
dput(test.result[20:25])
[1]  0.012840000  0.058735697  0.011653687  0.003092799  0.052490651 -0.002707512

You can see that the first few values are same as the one using FORLOOP. Therefore, I am wondering if it didnt go through the IFELSE process.
Thank you for your precious time, and I would like to thank Steven Lee for telling me the better way to show my codes.

A: OMG, this is confusing. It appears that if you get your data structures right, you won't have to loop at all, but simply divide or multiply the columns of a suitable data frame.
The reason why your code does not work is that k is now an internal variable to the function argument of sapply. sapply calls TestApply repeatedly for each of the rows of your BackTest.table, but each time TestApply is called, k remains 1, since k <- k + 1 has no effect outside of TestApply.
One way of dealing with that would be to use k <<- k + 1, which makes the assignment in the parent environments (specifically, the first parent environment that has a k variable defined). While I suppose this will work, this is neither an elegant nor a safe solution. In general, functions should only influence their environment by returning a value (changing k is called a "side effect" and is generally not encouraged).
Far much better would be to think how to clean up, match and extract the data frames into one which you could then use for calculations in a simple and straightforward way. Here I cannot help you: you would need to tell us way more about your tables (perhaps in another question).
Another approach would be to start with the following code:
sum(BackTest.table[t, 2: ncol(BackTest.table)] *
   c(rep(Weight.table[k, 2]/ Weight.table[k, 3], Weight.table[k, 3]),
     rep(Weight.table[k, 4]/ Weight.table[k, 5], Weight.table[k, 5]),
     rep(Weight.table[k, 6]/ Weight.table[k, 7], Weight.table[k, 7])

This code is evil. It is confusing, you don't know what it does (it appears to make a weird attempt at getting a weighted mean, but there are much faster ways of doing that, for example weighted.mean), and it depends on the number of columns in the BackTest.table. I would strive to first clean this mess up.
Also note that the vector with the replicates needs to be calculated t times, but in fact could just replicate the columns of the Weight.table once up front, since this procedure is identical for each row.
EDIT: ok, so now with the data I could take a closer look at what this evil code does. Basically, the columns are grouped, and for each group you have one weight by which you should divide the values from the columns in that group. So the author of the code, to save space, used a kind of run length encoding (0.0642 repeated 5 times, 0.7858 repeated 2 times etc.).
However, the rows of Weight.table have different numbers of repeats. This is a mess, and I would really, really encourage you to think what and how is being done to end up with optimally one data frame for use in your calculations.

A: Here's a suggested approach. As January suggested, this should be straightforward if you restructure your data.
Here, I reshape Weight.table so each row shows the weight and number for each class and date. Note, I altered the first two dates in your example data so that they'd match with the other table.
library(tidyverse)
Weight.table.tidy <- Weight.table %>%
  # Renaming here so the first character represents the class, and the second
  #  character represents (w)eight or (n)number.
  rename(s_w = "Stock", s_n = "Numbers1",
         b_w = "Bond",  b_n = "Number2",
         c_w = "现金",  c_n = "Number3") %>%
  gather(col, val, -Date) %>%
  separate("col", c("class", "stat")) %>%
  spread(stat, val)

head(Weight.table.tidy)
#         Date class n      w
#1  2008-07-01     b 2 0.7858
#2  2008-07-01     c 2 0.1500
#3  2008-07-01     s 5 0.0642
#4  2008-07-04     b 2 0.7699
#5  2008-07-04     c 2 0.1500
#6  2008-07-04     s 5 0.0801

Now I do something similar for BackTest.table, reshaping into long form so that each row holds one Date, class, and num, with the corresponding value from the original table. Then we can join this to Weight.table.tidy and fill down to all the NA dates based on prior dates within each class+num group. Now we have a long list of values, along with the variables we'll be using to weight each one.
BackTest.table.tidy <- BackTest.table %>%
  gather(type, val, -Date) %>%
  separate("type", c("class", "num"), sep = 1) %>%
  left_join(Weight.table.tidy) %>%
  group_by(class, num) %>%
  fill(n, w) %>% ungroup()

head(BackTest.table.tidy)
## A tibble: 6 x 6
#  Date       class num     val     n     w
#  <date>     <chr> <chr> <dbl> <dbl> <dbl>
#1 2008-07-01 b     1         0     2 0.786
#2 2008-07-02 b     1         0     2 0.786
#3 2008-07-03 b     1         0     2 0.786
#4 2008-07-04 b     1         0     2 0.770
#5 2008-07-05 b     1         0     2 0.770
#6 2008-07-06 b     1         0     2 0.770

One reshaped, we can use one line to weight the value, and another to sum for each Date. As a vectorized solution, I expect it will be much faster than the original solution.
BackTest.table.tidy %>%
  mutate(val_wtd = val * w / n) %>%
  count(Date, wt = val_wtd)


text:
Q: Insert values into variables from SQL drop down list I'm trying to take in data from a MySQL database and put it into a drop down list, then take that data and put it into a variable.
But the variable ends up having a null value

<form name="booking" method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
    <select name="class">
        <?php
        // fetches all classes from db
        $sql = "SELECT class_name FROM class";
        $result = mysqli_query($con, $sql);

        while($row = mysqli_fetch_array($result)) {
            //Take in all the classes from the database
            echo '<option value=' . $row["class_ID"] . '>' . $row["class_name"] . '</option>';
        }
        ?>
    </select>

    <button type="submit" name="submit_button" class="btn btn-primary">Select Class</button>

    <?php
    if(isset($_POST["submit_button"])) {
        //Input the value from the while loop into the $class variable
        $class_name = $row['class_ID'];
        $sql = "SELECT * FROM class where class_name =$class_name";
    }
    ?>
</form>

At the moment all the $class_name variable is NULL but I want it to take the value class_ID from the database.

A: In 5. row you use select query and only take 1 field from db  'class_name'
In 9. row you wanna call 2 field from db 1:'class_ID' and 2:'class_name'
In 20. row you define the $class_name = $row['class_ID']; but it will return null because you call 1 field in 5. row
please look at code below.
<form name="booking" method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
    <select name="class">
        <?php
        // fetches all classes from db
        $sql = "SELECT class_name,class_ID FROM class";
        $result = mysqli_query($con, $sql);

        while($row = mysqli_fetch_array($result)) {
            //Take in all the classes from the database
            echo '<option value=' . $row["class_ID"] . '>' . $row["class_name"] . '</option>';
        }
        ?>
    </select>

    <button type="submit" name="submit_button" class="btn btn-primary">Select Class</button>

    <?php
    if(isset($_POST["submit_button"])) {
        //Input the value from the while loop into the $class variable
        $class_name = $_POST['class'];
        $sql = "SELECT * FROM class where class_name =$class_name";
    }
    ?>
</form>

redpajama_set_name: RedPajamaStackExchange


text:
Q: Finding current page number in google search image api Is there any way to find out current page number in search complete callback function of google image search api?
I have defined a function for search complete callback and set it using this setSearchCompleteCallback and found that it is called for each page click also, so is there any way to know what is the current page number?

A: Found a workaround, the div for current page has css class
gsc-cursor-current-page
This is not what exactly what I asked in the question but it helped me!


text:
Q: AssertionError: INTERNAL: No default project is specified New to airflow. Trying to run the sql and store the result in a BigQuery table.
Getting following error. Not sure where to setup the default_rpoject_id.
Please help me.
Error:
Traceback (most recent call last):
  File "/usr/local/bin/airflow", line 28, in <module>
    args.func(args)
  File "/usr/local/lib/python2.7/dist-packages/airflow/bin/cli.py", line 585, in test
    ti.run(ignore_task_deps=True, ignore_ti_state=True, test_mode=True)
  File "/usr/local/lib/python2.7/dist-packages/airflow/utils/db.py", line 53, in wrapper
    result = func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/airflow/models.py", line 1374, in run
    result = task_copy.execute(context=context)
  File "/usr/local/lib/python2.7/dist-packages/airflow/contrib/operators/bigquery_operator.py", line 82, in execute
    self.allow_large_results, self.udf_config, self.use_legacy_sql)
  File "/usr/local/lib/python2.7/dist-packages/airflow/contrib/hooks/bigquery_hook.py", line 228, in run_query
    default_project_id=self.project_id)
  File "/usr/local/lib/python2.7/dist-packages/airflow/contrib/hooks/bigquery_hook.py", line 917, in _split_tablename
    assert default_project_id is not None, "INTERNAL: No default project is specified"
AssertionError: INTERNAL: No default project is specified

Code:
sql_bigquery = BigQueryOperator(
        task_id='sql_bigquery',
        use_legacy_sql=False,
        write_disposition='WRITE_TRUNCATE',
        allow_large_results=True,
        bql='''
            #standardSQL
                SELECT ID, Name, Group, Mark, RATIO_TO_REPORT(Mark) OVER(PARTITION BY Group) AS percent FROM `tensile-site-168620.temp.marks`
                ''',
        destination_dataset_table='temp.percentage',
        dag=dag
        )

A: EDIT: I finally fixed this problem by simply adding the bigquery_conn_id='bigquery' parameter in the BigQueryOperator task, after running the code below in a separate python script.
Apparently you need to specify your project ID in Admin -> Connection in the Airflow UI. You must do this as a JSON object such as "project" : "".
Personally I can't get the webserver working on GCP so this is unfeasible. There is a programmatic solution here:
from airflow.models import Connection
from airflow.settings import Session

session = Session()
gcp_conn = Connection(
    conn_id='bigquery',
    conn_type='google_cloud_platform',
    extra='{"extra__google_cloud_platform__project":"<YOUR PROJECT HERE>"}')
if not session.query(Connection).filter(
        Connection.conn_id == gcp_conn.conn_id).first():
    session.add(gcp_conn)
    session.commit()

These suggestions are from a similar question here.

A: I get the same error when running airflow locally. My solution is to add a the following connection string as a environment variable:
AIRFLOW_CONN_BIGQUERY_DEFAULT="google-cloud-platform://?extra__google_cloud_platform__project=<YOUR PROJECT HERE>"

BigQueryOperator uses the "bigquery_default" connection. When not specified, local airflow uses an internal version of the connection which misses the property project_id. As you can see the connection string above provides the project_id property.
On startup Airflow loads environment variables that start with "AIRFLOW_" into memory. This mechanism can be used to override airflow properties and providing connections when running locally, as explained in the airflow documentation here. Note this also works when running airflow directly without starting the web server.
So I have set up environments variables for all my connections, for example AIRFLOW_CONN_MYSQL_DEFAULT. I have put them into a .ENV file that get sourced from my IDE, but putting them into your .bash_profile would work fine too.
When you look inside your airflow instance on Cloud Composer, you see that the at the "bigquery_default" connection there has the project_idproperty set. That's why BigQueryOperator works when running through Cloud Composer.
(I am on airflow 1.10.2 and BigQuery 1.10.2)


text:
Q: Show product category under each product I'm trying to show each products category, right under the product image on the shop page.
Here's the current page
Here's where I want to display the category name
I have tried with the following code, but it doesn't seem like it can get the current product category from the functions.php file.
And here it comes...
function sv_add_text_under_wc_shop_image() {

    echo $product->get_categories( ', ', '' . _n( 'Category:', 'Categories:', sizeof( get_the_terms( $post->ID, 'product_cat' ) ) ) . ' ', '' );
}

add_action( 'woocommerce_before_shop_loop_item_title', 'sv_add_text_under_wc_shop_image', 10 );

A: Make a copy of content-product.php to your child theme and find this line:

<?php the_title(); ?>

Add this right after it:
<?php
        $terms = get_the_terms($post->ID,'product_cat');
        $count = count($terms); $i=0;
        if ($count > 0) {
            $term_list = '
';
            foreach ($terms as $term) {
                $i++;
                if ($term->parent==0) {
                    $term_list .= 'slug . '">' . $term->name . '';
                    if ($count != $i) $term_list .= ' · ';
                }
            }
            echo $term_list .'
';
        }
?>


text:
Q: C# adding reference problem I add selenium reference to the project and work ok but when i click rebuild project i get this error:

Error 3   The type or namespace name 'Selenium' could not be found (are you

missing a using directive or an
  assembly
  reference?)   D:\PROJEKTI\crawler\WebCrawlerSuite\NCrawler\Net
  4.0\NCrawler.WinDemo\SeleniumHtmlDocumentProcessor.cs 6   7   NCrawler.WinDemo

and this warning:

Warning   2   The referenced assembly "ThoughtWorks.Selenium.Core" could not

be resolved because it has a
  dependency on "System.Web,
  Version=4.0.0.0, Culture=neutral,
  PublicKeyToken=b03f5f7f11d50a3a" which
  is not in the currently targeted
  framework
  ".NETFramework,Version=v4.0,Profile=Client".
  Please remove references to assemblies
  not in the targeted framework or
  consider retargeting your
  project.  NCrawler.WinDemo

what can be wrong?

A: I'm guessing this is because your project is using the Client Profile ("Profile=Client" in the framework version).  Try setting the target framework to plain old ".NET Framework 4" in your project properties and see if that does the trick.
In this case, the Selenium  assembly is referencing System.Web, which is not allowed for the Client profile framework.  See http://msdn.microsoft.com/en-us/library/cc656912.aspx for details.


text:
Q: Why does matrix exponentiation work with transposes? Let $A^T$ denote the transpose of $A$.
Is it true that $(A^n)^T = (A^T)^n$?

A: The answer is affirmative. Maybe generalizing the properties of matrix transposes and powers will be insightful.
Let $A_i$ be a square matrix for $i=1,2,3,...,n$.
Consider the matrix product $B = A_1 A_2 A_3 \cdots A_n$. Recall that $(XY)^T = Y^T X^T$. It can be shown by induction that $$B^T = (A_1 A_2 A_3 \cdots A_n)^T \\
= A_n^T \cdots A_3^T A_2^T A_1^T.$$
In the special case where $A_i = A$ for all $i=1,2,3,\ldots,n$, then we have $B = AAA\cdots A = A^n$. Similarly, we have $B^T = A^T \cdots A^T A^T A^T = (A^T)^n$. But since $B = A^n$, then $B^T = (A^n)^T$. So altogether, we have $(A^n)^T = (A^T)^n$. QED

A: Yes, it follows from the fact $(AB)^{T}=B^{T}A^{T}$. Here let $B=A$.


text:
Q: MySQL: I have two tables, 1 production and 1 archive. I need to select distinct records from both as some records are identical I have a MySQL database containing 2 tables.  prod is an in-production and archive has archived records. The columns are exactly the same.  prod does not have all records in archive.
I need to access distinct records in 1 join of the two tables so I'm not duplicating records and throwing calculations off in excel.
SELECT
    a.order_no,
    a.date_of_sale,
    a.cost,
    b.order_no,
    b.date_of_sale,
    b.cost

FROM
    `prod` AS a
    LEFT JOIN `archive` AS b ON a.order_no = b.order_no

Results:
+----------+--------------+------+-------------+-----------------+---------+
| order_no | date_of_sale | cost | order_no(1) | date_of_sale(2) | cost(2) |
+----------+--------------+------+-------------+-----------------+---------+
|      333 | 11-28-2017   |   10 |         333 | 11-28-2017      |      10 |
|      334 | 11-28-2017   |   12 |         334 | 11-28-2017      |      12 |
|      336 | 11-29-2017   |   30 |         335 | 11-28-2017      |      25 |
|      337 | 11-30-2017   |   15 |             |                 |         |
|      338 | 11-30-2017   |   17 |         338 | 11-28-2017      |      17 |
+----------+--------------+------+-------------+-----------------+---------+

How can I structure my query to filter records that are the same in both tables?
The result I'd like:
+----------+--------------+------+
| order_no | date_of_sale | cost |
+----------+--------------+------+
|      333 | 11-28-2017   |   10 |
|      334 | 11-28-2017   |   12 |
|      335 | 11-28-2017   |   25 |
|      336 | 11-29-2017   |   30 |
|      337 | 11-30-2017   |   15 |
|      338 | 11-30-2017   |   17 |
+----------+--------------+------+```

A: I suspect that you want union rather than a join:
select order_no, date_of_sale, cost from prod
union
select order_no, date_of_sale, cost from archive

union removes duplicates between the resultsets (and within the resultsets as well).


text:
Q: Vlookup for InfoPath 2010 I'm trying to develop a calculator type from in InfoPath where the user will be asked to end weight,height, and age. I will then take those values and use them to look up other values that are based on that number. For example if the column headers are Gender, Age, Height, L, M, and S. I want to find the 'L,M,S' values associated with that height. All values in the case are different. So if height were 45, L=-1, M=1, S=2; if height were 50, L= -2, M= 5, S=3.
In excel you a Vlookup with the syntax of :
Dim A as double
Dim Height as double
height = txtHeight.Value
A = Application.WorksheetFunction.VLookup(height, Range("C2:F652"), 2, False)

This would give you the "L" value for the row in which that height is located.
How can I do this in InfoPath? I have seen that are cascading queries you can do for dropdowns and comboboxes, but I want them to be able to type in a value, find a value on a SharePoint list based on that number and then return that number to another text box to use for my calculation.

A: If the values you want to look up are in a SharePoint list, then you need to create a data connection to that list. Make sure to include all the fields you need. Don't load the data connection at form load.
Let the user enter the height. Create a rule for the height field that fires when the field changes. Add an action that sets the query field for the secondary data source to the value of the height field, then query the data connection. Now the secondary data source contains the record with that height and the fields in the secondary data source contain the values. You can copy the values into text boxes on the canvas.
More details:
After you have set up a data connection to the Heights list, click the Heights field and add a rule by clicking New > Action.

Click the Add button and add an action to set a field's value.

Click the button next to the "Field" text box. If you don't see the top drop-down to select a different data source than the main data source, click the "Show Advanced View" link. Select the secondary data source for the Heights list, open the node for queryFields and the node below that and select the Height field.

Click the fx button next to the "Value" text box, then click "Insert Field or Group" and select the "height" field of the main data source.

OK out of all dialogs.
Add another rule to query for data.

Select the secondary data source to the Heights list.
Add another rule to set a field's value. For "Field" select the main data source field into which you want to copy the looked up value. For "Value" select the secondary data source and drill into the dataFields node until you see the field names. Select the desired field and OK out of all dialogs.

The rules panel should now look similar to this, but with your column names.

Test the form. Enter a valid height into the height field and click out of the field. The corresponding value from the height list will be written into the textbox. The screenshot shows the SharePoint list in the background with the item for heigt "66" highlighted. The value returned to the InfoPath text box "getV1" is from the "V1" field of the SharePoint list.

Hope that makes it clearer.


text:
Q: Breakpoints does not work in lambda expression in Java I cannot understand what the following code does:
public class Main {

    public static void main(String[] args) throws UnsupportedProtocolException, IOException {
        new Thread(() -> {
            PropertiesLoader loader = new PropertiesLoader();
            loader.load(args);
            System.out.println(loader.getProperties());
        });
    }
}

I have put breakpoints in all lines of the main method but only the breakpoint at the line starting with new Thread gets hit.
However, no breakpoints in the lambda expression's body gets hit.
Plus, I don't understand what this code does. AFAIU, the lambda expression does not return any values. Hence, the code does not supply any arguments to Thread constructor.
Plus, I don't understand why is there a thread creation here.
Could you help me on how to reach inside of the lambda expression using breakpoints?

A: The reason that no breakpoints get reached inside the lambda is because the lambda never gets run.

() -> {
        PropertiesLoader loader = new PropertiesLoader();
        loader.load(args);
        System.out.println(loader.getProperties());
    }

is a lambda taking no arguments and having a void return type, which matches the functional interface java.lang.Runnable (because it has a method void run()). The constructor java.lang.Thread(java.lang.Runnable) is called to construct a new thread, but start() is never called on that thread, hence the lambda is never run.


text:
Q: How use jquery to change text of input button on click? I want to change the ADD text of the following button into "REMOVE" when clicking the button.
<input class="btn btn-6d" ahref="www.test.com" type="button" value="ADD"/>

I used the following jquery code for this:
$(':input[type="button"][class="btn-6d"]').click(function(){
var $this = $(this);
$this.toggleClass('btn-6d');
if($this.hasClass('btn-6d')){
    $this.value('ADD');
} else {
    $this.value('REMOVE');
}
});

I'm probably doing something wrong with my selectors but I'm relatively new to programming and can't figure out what I'm doing wrong.
Here is a fiddle for you to play with:
http://jsfiddle.net/stijn777/shzuwu0v/
Thanks in advance,
Stijn

A: You were using value() instead of val(). Anything else below is just a little bit of cleanup :)
JSFiddle: http://jsfiddle.net/TrueBlueAussie/shzuwu0v/3/
   // Find the element by the generic btn class
    $(document).on('click', '.btn:input[type="button"]', function(){
        var $this = $(this);
        $this.toggleClass('btn-6d');
        if($this.hasClass('btn-6d')){
            $this.val('ADD');
        } else {
            $this.val('REMOVE');
        }
    });

A: Think easier, you just need to use the class as a selector. Also note that the method name is .val() and not .value()

  $('.btn.btn-6d').click(function () {
    var $this = $(this);

    $this.toggleClass('btn-6d');

    if ($this.hasClass('btn-6d')) {
        $this.val('ADD'); // method name is .val()
    } else {
        $this.val('REMOVE');
    }
});
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<input class="btn btn-6d" ahref="www.test.com" type="button" value="ADD" />


text:
Q: PHP multi-dimensional array, merge duplicate keys into new arrays I have the following array:
Array (
  [ids] => Array (
    [0] => e348ae92
    [1] => 193ba701
    [2] => 58695854
  )
  [name] => Array (
    [0] => Customers
    [1] => Suppliers
    [2] => Users
  )
  [subs] => Array (
    [0] => 614
    [1] => 65
    [2] => 99
  )
)

I want to take each array key and turn it into a it's own array e.g.
array(
  [0] = array(
    [0] => e348ae92
    [1] => custommers
    [2] => 614
  )
  [1] = array(
    [0] => 193ba701
    [1] => Suppliers
    [2] => 65
  )
  [2] = array (
    [0] => 58695854
    [1] => Users
    [2] => 99
  )
)

I have looked at array_merge, array_combine and a few other things but I have been unsuccessful so far, any pointers in the right direction would be appreciated.

A: You can use array_map
 $f = array_map(null, $a['ids'], $a['name'], $a['subs']);
 print_r($f);

Working example:https://3v4l.org/dDG0Y-


text:
Q: Bootstrap Grids not working Intel XDK I am trying to build an app using the Intel XDK and using Bootstrap for the styling and grids. The problem is that when I test the app, the grids don't show up, the text just shows as separate rows rather than columns. Here is a screenshot I took
Is this an XDK specific problem or something else?

A: Bootstrap app should work in XDK if all the library files are included as part of the project you create or import. It is possible, if you are using the example right off bootstrap download, the libraries are outside the folder you have imported. Can you verify that you have sourced and included all the associated js and css files for bootstrap. You can open the debug button in the emulator and you should be able to see if there are any console errors.


text:
Q: Why are my variables not being calculated properly? I'm making a simple program for class to be able to find out the new mayor/president based on an electoral college based system.The input into my array and the subsequent output of the table of results all work perfectly but...My variables aStatesWon, bStatesWon, cStatesWon and dStatesWon (For Candidates A,B,C&D respectively) are not being calculated properly even though i thought i had them calculating correctly. I'm getting figures similar to -2324252 or 62341 not something like 2 or 3 like i'm expecting. Here's the code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define STATES 5
#define CANDIDATES 4

void declareNewMayor(int aStatesWon,int bStatesWon,int cStatesWon, int dStatesWon);

void main() {

    int votes[STATES][CANDIDATES];
    int StateWon = -1;
    int StateWinner;
    int aStatesWon = 0;
    int bStatesWon = 0;
    int cStatesWon = 0;
    int dStatesWon = 0;
    int newMayor;

    FILE* open;

    int i,j;

    for (i = 0; i < STATES; i++)
    {
        StateWinner = 0;
        StateWon = -1;

        for (j = 0; j < CANDIDATES; j++)
        {
            printf("Please enter the votes for candidate %d for state %d\n",(j+1),(i + 1));
            scanf("%d",&votes[i][j]);
            if (votes[i][j] > StateWon)
            {
                StateWon = votes[i][j];
                StateWinner = j;
            } //see if the won that state
        }
        printf("Winner of State %d is Candidate %d\n",i,j);
        if (StateWinner = 0)
        {
            aStatesWon++;
        }
        else if (StateWinner = 1)
        {
            bStatesWon++;
        }
        else if (StateWinner = 2)
        {
            cStatesWon++;

        }
        else if (StateWinner = 3)
        {
            dStatesWon++;

        }//increase number of states won by that candidate if the won that state

        printf("States Won  A:%d  B:%d   C:%d   D:%d", aStatesWon, bStatesWon, cStatesWon, dStatesWon);

    }//enter in votes for each candidate for each state
    open = fopen("votes.txt", "w");
    if (open == NULL)
    {
        printf("\nFile could not be opened\n");
    }
    else
    {

        printf("STATES CANDIDATE A    CANDIDATE B    CANDIDATE C    CANDIDATE D\n");
        fprintf(open,"STATES CANDIDATE A    CANDIDATE B    CANDIDATE C    CANDIDATE D\n");
        for (i = 0; i < STATES; i++)
        {
            printf("STATE %d", (i + 1));
            fprintf(open,"STATE %d", (i + 1));

            for (j = 0; j < CANDIDATES; j++)
            {
                printf("          %d       ", votes[i][j]);
                fprintf(open,"          %d       ", votes[i][j]);
            }
            printf("\n");

        }//print out table
    }

    declareNewMayor(aStatesWon,bStatesWon,cStatesWon,dStatesWon);

}//main
void declareNewMayor(int aStatesWon, int bStatesWon, int cStatesWon, int dStatesWon)
{

    char winner;
    int statesWon;

    if (aStatesWon > bStatesWon&&aStatesWon > cStatesWon&&aStatesWon > dStatesWon)
    {

        statesWon = aStatesWon;
        winner = "A";
    }
    else if (bStatesWon > aStatesWon&&bStatesWon > cStatesWon&&bStatesWon > dStatesWon) {

        statesWon = bStatesWon;
        winner = "B";
    }
    else if (cStatesWon > aStatesWon&&cStatesWon > bStatesWon&&cStatesWon > dStatesWon) {

        statesWon = cStatesWon;
        winner = "C";
    }
    else if (dStatesWon > aStatesWon&&dStatesWon > cStatesWon&&dStatesWon > aStatesWon) {

        statesWon = dStatesWon;
        winner = "C";
    }

    printf("The new Mayor is candiate %c with %d states won!", winner,statesWon);

}//calculate new mayor and declare it

A: There are some logic errir in your function declareNewMayor.
1> You assigned the string literal to character variable winner. It will result an undefined behavior
 winner = "A";
 winner = "B";
 winner = "C";

So should be replaced by:
 winner = 'A';
 winner = 'B';
 winner = 'B';

2> if ... else in the function declareNewMayor. You don't check other cases. For example: aStatesWon == bStatesWon == cStatesWon == dStatesWon. How is the result in that case? if you don't care other cases, you can initialize 2 variables winner, statesWon with some value that avoid the undefined behavior with uninitialized variable (that is reason why your output is strange with -2324252 or 62341). Here is my solution
void declareNewMayor(int aStatesWon, int bStatesWon, int cStatesWon, int dStatesWon)
{

char winner = '?';
int statesWon = 0;

if (aStatesWon > bStatesWon&&aStatesWon > cStatesWon&&aStatesWon > dStatesWon)
{

    statesWon = aStatesWon;
    winner = 'A';
}
else if (bStatesWon > aStatesWon&&bStatesWon > cStatesWon&&bStatesWon > dStatesWon) {

    statesWon = bStatesWon;
    winner = 'B';
}
else if (cStatesWon > aStatesWon&&cStatesWon > bStatesWon&&cStatesWon > dStatesWon) {

    statesWon = cStatesWon;
    winner = 'C';
}
else if (dStatesWon > aStatesWon&&dStatesWon > cStatesWon&&dStatesWon > aStatesWon) {

    statesWon = dStatesWon;
    winner = 'D';
}

printf("The new Mayor is candiate %c with %d states won!", winner,statesWon);

}//calculate new mayor and declare it


text:
Q: typeorm migration api does not generate automatic code hello I have a problem to generate the code of my migrations automatically.
basically i following some tutorials when changing a column the migration code is generated automatically, but it doesn't happen to me.
my script on package.json:
  "scripts": {
    "commit": "git-cz",
    "build": "babel src --extensions \".js,.ts\" --out-dir dist --copy-files --no-copy-ignored",
    "start": "node dist/server.js",
    "dev:server": "ts-node-dev --inspect --respawn --transpile-only --ignore-watch node_modules -r tsconfig-paths/register src/shared/infra/http/server.ts",
    "test": "jest",
    "typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
    "lint": "eslint --fix"
  },

my entitiy ( i change random column to other name to test generate migration with automatic code)
users.entitiy.ts:
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
import { SharedProp } from './sharedProp.helper';

@Entity({ name: 'users' })
export class User extends SharedProp {
  constructor(isActive: boolean, login: string, password: string) {
    super();
    this.isActive = isActive;
    this.login = login;
    this.password = password;
  }
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'login', nullable: false })
  login: string;

  @Column({ nullable: false })
  password: string;

  @Column({ name: 'is_active', nullable: false })
  isActive: boolean;
}

and this is my ormconfig:
const rootDir = process.env.NODE_ENV === 'development' ? 'src' : 'build/src';

module.exports = {
  type: 'postgres',
  host: process.env.DB_HOST,
  port: process.env.DB_PORT,
  username: process.env.DB_USER,
  password: process.env.DB_PASS,
  database: process.env.DB_NAME,
  synchronize: false,
  logging: false,
  entities: [rootDir + '/entities/**/*.{js,ts}'],
  migrations: [rootDir + '/migrations/*.{js,ts}'],
  subscribers: [rootDir + '/subscribers/**/*.{js,ts}'],
  seeds: [rootDir + '/migrations/seeds/**/*.{js,ts}'],
  factories: [rootDir + '/migrations/factories/**/*.{js,ts}'],
  cli: {
    entitiesDir: `${rootDir}/entities`,
    migrationsDir: `${rootDir}/migration`,
    subscribersDir: `${rootDir}/subscriber`,
  },
};

I started my server, changed the column password to passwords and executed the command:
yarn typeorm -- migration:create -n Password
yarn run v1.22.4
warning From Yarn 1.0 onwards, scripts don't require "--" for options to
be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
$ node --require ts-node/register ./node_modules/typeorm/cli.js migration:create -n Password
Migration G:\emasati_stockcontrol/src/migration/1595290975334-Password.ts has been generated successfully.
Done in 1.86s.

but for some reason it is not generating the alter table automatically in the migration:
export class Password1595290975334 implements MigrationInterface {

    public async up(queryRunner: QueryRunner): Promise<void> {
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
    }

}

A: Try add to package.json :
"scripts": {
   ...
   "migration:generate": "yarn run typeorm migration:generate -n"
}

and execute this command:
yarn run migration:generate -- [MigrationNameWithoutBrackets]


text:
Q: The graphical intuiton of the LASSO in case p=2 Since this question was already ask here, I hope that it isn't a duplicate because it isn't answered. In my question I'll use another graph to make it more clear:

The left plot is describing the lasso-problem. My question is regarding to the cases when it is more likely to intersect the corner (in this case $\beta_j=0$) or the side of the constrained area.
I more or less figured out two dependencies:

*

*As in the picture, if we increase the budget of the constrained area or decrease the tuning parameter $\lambda$, the diamond will be getting bigger. It will be more likely to intersect with a side as with a Corner.

*The intersection depends on the "graphical position" of the OLS solution. But I can't explain to myself how the dependence works. Can some of you give me some graphical intuition in the case of $p=2$, when the LASSO will not set coefficients to zero?

A: Recall that the Lasso minimization problem can be viewed as the minimization of two terms: $OLS + L_1$. To answer your question:

The intersection depends on the "graphical position" of the OLS
  solution. But I can't explain to myself how the dependence works.

*

*The solution to the constrained optimization lies at the intersection between the contours of the two functions, and this intersection varies as a function of $\lambda$. For $\lambda = 0$ the solution is the MLE (as usual) and for $\lambda = \infty$ the solution is at $[0,0]$.

*Since at the vertices of the diamond, one or many of the variables have value 0, there is a non zero probability that one or many of the coefficients will have a value exactly equal to 0.

As you can see from your picture, there must be some values of $\lambda$ for which the solution does not take place at the vertex of the diamond. The solution cannot simply jump from the OLS minimum (when $\lambda = 0$) to a vertex of the diamond.
This is a misunderstanding many people have. The lasso doesn't magically set coefficients to zero ! It optimizes the lasso cost function, and the particular structure of this optimization problem makes it likely that the solution lies at the vertex of the diamond.

Can some of you give me some graphical intuition in the case of p=2, when
  the LASSO will not set coefficients to zero?

The answer is every time the optimal solutions is not at a vertex of the diamond. Now to answer the question you have not asked.
What makes it more likely for the lasso coefficient to not be zero
One obvious factor is when features are correlated - or if there is strong multi-correlation in your data set. Visually this will have the effect of "flattening" the OLS cost function in one direction (in 2d) and thus will strongly influence the path of the lasso solution by forcing it to take a less "direct" path towards one of the vertex. See this picture for a case where the two features are very correlated.

If there were less correlation, the OLS contour plot would look more circular and the lasso solution may converge faster to a vertex. But again this depends on the particular shape of the OLS cost function for your given data set. In this case the OLS solution has a valley that is at an angle w.r.t the $0,0$ point. This where the notion of graphical position comes from
Sources
This post is strongly based on my previous post - For anyone interested, you can find most of the code and associated mathematical derivations on my blog and at this page

A: The ellipses are the equi-value contours of the loss, and the blue shapes are the regions of the penalty. By duality, the optimum occurs when a contour line intersects with a boundary of a blue shape.
The case you've shown is indeed one that foils Lasso sparsity - the axis of the ellipses is perpendicular to the surface of the diamond. This is possible, but not very likely. In higher dimensions, it is even less likely. For the 2D case it is easy to see that when the axis is not perpendicular to the surface of the diamond, the intersection will be either on the x or y axis.


text:
Q: Creation of a simple field failed in MySql CREATE TABLE bdt.transactions (
`transaction no`     int UNSIGNED NOT NULL  AUTO_INCREMENT,
data                 date    ,
by                   int  NOT NULL  ,
hours                int  NOT NULL  ,
for                  int  NOT NULL  ,
`transaction type`   set('normale','corso')   NOT NULL DEFAULT 'normale' ,
activity             text  NOT NULL  ,
CONSTRAINT pk_transactions PRIMARY KEY ( `transaction no` ) ) engine=InnoDB

Error:

You have an error in your SQL syntax; check the manual that
  corresponds to your MySQL server version for the right syntax to use
  near  'by                   int  NOT NULL  ,  hours                int
  NOT NULL  ,  for                  int  NOT NULL    at line 4

With backquotes is now OK

A: by is a reserved word, and so is for
You should surround reserved words with backquotes (`) if you use them as table or column names. Just to be on the safe side, surround all column names with backquotes
CREATE TABLE bdt.transactions (
`transaction no`     int UNSIGNED NOT NULL  AUTO_INCREMENT,
`data`               date    ,
`by`                 int  NOT NULL  ,
`hours`              int  NOT NULL  ,
`for`                int  NOT NULL  ,
`transaction type`   set('normale','corso')   NOT NULL DEFAULT 'normale' ,
`activity`           text  NOT NULL  ,
CONSTRAINT pk_transactions PRIMARY KEY ( `transaction no` ) ) engine=InnoDB

Give it a Try !!!


text:
Q: How can read/modify person account NetId? How can read/modify person account NetId? I could not find any reference to this particular person account information. Is this located as some Account field? (I could not find this one also)

A: I found the field:  Net_ID__pc


text:
Q: How to pass a non DB object from a template to a view outside the URL with Django ? I'm fairly new to Django. I'm writing an app that displays articles using RSS. I want users to be able to react to any given article.
On the index, I display the latest articles dynamically (they are not stored in the DB).
View :
class IndexView(generic.ListView):
    template_name = 'publisher/index.html'

    def get_context_data(self, **kwargs):
        context = super(IndexView,self).get_context_data(**kwargs)
        feeds = feedparser.parse('http://www.foo.com/rss/news.xml')
        context['feeds'] = feeds
        return context

Template :
{% for entry in feeds.entries %}

      {{entry.title}}
      I want to react

{% endfor %}

This works so far. I have a link next to each of these articles that should call the RSSReactView and display the article title, abstract, and a form to react. I don't want the article to be saved anywhere if the reaction is not posted, and thus I don't want any parameter to be included in the URL of the reaction form.
URL :
app_name = 'publisher'
urlpatterns = [
    url(r'^$', views.IndexView.as_view(), name='index'),
    url(r'^new_rss/react/$', views.RSSReactView.as_view(), name='rss_react'),
]

View :
class RSSReactView(generic.CreateView):
    model = ReactionArticle
    form_class = ReactionForm
    template_name = 'publisher/react.html'

    def get_context_data(self, **kwargs):
        context = super(ReactView,self).get_context_data(**kwargs)
        entry = self.kwargs['entry']
        context['entry'] = entry
        return context

    def form_valid(self, form):
        pass

Template :

You are reacting to article {{ entry.title }}

  {{ entry.description }}

Of course, I get a NoReverseMatch error since the URL pattern isn't built to catch anything.
Passing parameters from DB stored objects through the URL is straightforward, but how do I pass a context variable ('entry', in this case) as an object to another view without using the URL ?
NB : I'm aware of the solutions using sessions or posts, but I can't believe that's the only way of doing it.


text:
Q: In R Shiny, can one interactively highlight cells using DT::dataframe? Using R Shiny and DT : can one easily highlight/unhighlight interactively cells ?
I have been looking at the DT input$dt_cell_clicked to catch the row and the column that is clicked. I plan to then store that value in another column to highlight conditionally to that value (TRUE/FALSE).
My question is : can one do better + quicker with another option/function ?
library(shiny)
library(shinyjs)

library(dplyr)
library(DT)

options(DT.options = list(pageLength = 5))
df = as.data.frame(
        cbind(
                matrix(round(rnorm(50), 3), 10),
                sample(0:1, 10, TRUE),
                rep(FALSE, 10)
        )
)
# getwd()
setwd(here::here())
# write.csv(df, "data/df_test.csv")

ui <- fluidPage(
        h2("Last clicked:"),
        verbatimTextOutput("last_clicked"),
        actionButton("reset", "Reset clicked value"),
        h2("Datatable:"),
        DT::dataTableOutput("dt"),
        useShinyjs(),
        extendShinyjs(text = paste0("shinyjs.resetDTClick = function() { Shiny.onInputChange('dt_cell_clicked', null); }"))
)

server <- function(input, output) {

        # the last clicked value
        output$last_clicked <- renderPrint({
                str(input$dt_cell_clicked)
        })

        df_new <- reactive({

                # res <- read.csv("data/df_test.csv")
                res <- df
                res
        })

        output$dt <- DT::renderDataTable({
                # DT::datatable(head(mtcars, 2))
                DT::datatable(df_new(), select = "none", editable = TRUE) %>% formatStyle(
                        'V1', 'V6',
                        backgroundColor = styleEqual(c(0, 1), c('gray', 'yellow'))
                )
        })

        observeEvent(input$dt_cell_clicked, {
                validate(need(length(input$dt_cell_clicked) > 0, ''))
                # alert("You clicked something!")

                if(!is.null(input$dt_cell_clicked)){
                        # df[input$dt_cell_clicked$row, input$dt_cell_clicked$column] <- ifelse(0, 1, 0)
                        cat("changing value")
                        df_test <- df_new()
                        df_test[input$dt_cell_clicked$row, input$dt_cell_clicked$column] <- ifelse(0, 1, 0)
                        write.csv(df_test, "data/df_test.csv")
                        rm(df_test)
                        # i
                }
        })

        # use dt_cell_clicked to infer on bool cell

        # df_new <- eventReactive(input$dt_cell_clicked, {
        # df_new <- reactive({
        #
        # })

        observeEvent(input$reset, {
                js$resetDTClick()
        })
}

shinyApp(ui, server)

Expected (not yet implemented) : When clicked a cell highlight/unhighlight.
This code is mixed from :
How to change the cell color of a cell of an R Shiny data table dependent on it's value?
DataTables DT: reset value of clicked cell

A: You could simply use single cell selection for highlighting:
library(shiny)
library(DT)

options(DT.options = list(pageLength = 5))

DF = as.data.frame(
  cbind(
    matrix(round(rnorm(50), 3), 10),
    sample(0:1, 10, TRUE),
    rep(FALSE, 10)
  )
)

ui <- shinyUI(
  fluidRow(
    tags$style(HTML('table.dataTable tr.selected td, table.dataTable td.selected {background-color: lightgreen !important;}')),
    DT::dataTableOutput("myDT")
  )
)

server <- shinyServer(function(input, output, session) {

  output$myDT <- DT::renderDataTable({
    DT::datatable(DF, selection = list(mode="single", target="cell"), editable = TRUE) %>% formatStyle(
      'V1', 'V6',
      backgroundColor = styleEqual(c(0, 1), c('gray', 'yellow'))
    )
  })

})

shinyApp(ui, server)


text:
Q: Uniform Smoothness Inequality for Schatten Norms I'm looking for a proof of the inequality
$$
\left[ \frac12(\left\|A+B\right\|_p^p + \left\|A-B\right\|_p^p)\right]^{2/p} \leq \left\|A\right\|_p^2 +C_p \left\|B\right\|_p^2
$$
where A and B are complex matrices of the same size, $\left\| .\right\|_p$ refers to the Schatten p-norm,  p$\geq 2$, and $C_p=p-1$.
I have a reference for the opposite inequality when $1\leq p \leq 2$ but no mention of the one above. Are the two somehow equivalent? Am I missing an easy argument to follow one out of the other?


text:
Q: Integral formula logic For example we have to solve such an integral.How do we apply the steps to reduce the integral to a lower degree(speaking of m and n).How exactly do we apply the multiplication formula for Integrals and on which parts of the whole.$$\int \frac{\mathrm{d}x}{(a^2+x^2)^n}$$ and $$\int \frac{x^m\mathrm{d}x}{(a^2+x^2)^n}$$

A: With the way you've written this, it appears that $a$ and $b$ are constants. So,
$$\int\frac{dx}{(a^2+b^2)^n}=\frac1{(a^2+b^2)^n}\int dx=\frac x{(a^2+b^2)^n}+C$$
and
$$\int{x^m\,dx\over(a^2+b^2)^n}=\frac1{(a^2+b^2)^n}\int x^m\,dx={x^{m+1}\over(m+1)(a^2+b^2)^n}+C$$


text:
Q: Parsing Delimited Data In a DataFrame Into Separate Columns in R I have a data frame which looks as such
A  B  C
1  3  X1=7;X2=8;X3=9
2  4  X1=10;X2=11;X3=12
5  6  X1=13;X2=14

I would like to parse the C column into separate columns as such...
A  B  X1  X2  X3
1  3  7   8   9
2  4  10  11  12
5  6  13  14  NA

How would one go about doing this in R?

A: First, here's the sample data in data.frame form
dd<-data.frame(
    A = c(1L, 2L, 5L),
    B = c(3L, 4L, 6L),
    C = c("X1=7;X2=8;X3=9",
    "X1=10;X2=11;X3=12", "X1=13;X2=14"),
    stringsAsFactors=F
)

Now I define a small helper function to take vectors like c("A=1","B=2") and changed them into named vectors like c(A="1", B="2").
namev<-function(x) {
    a<-strsplit(x,"=")
    setNames(sapply(a,'[',2), sapply(a,'[',1))
}

and now I perform the transformations
#turn each row into a named vector
vv<-lapply(strsplit(dd$C,";"), namev)
#find list of all column names
nm<-unique(unlist(sapply(vv, names)))
#extract data from all rows for every column
nv<-do.call(rbind, lapply(vv, '[', nm))
#convert everything to numeric (optional)
class(nv)<-"numeric"
#rejoin with original data
cbind(dd[,-3], nv)

and that gives you
  A B X1 X2 X3
1 1 3  7  8  9
2 2 4 10 11 12
3 5 6 13 14 NA

A: My cSplit function makes solving problems like these fun. Here it is in action:
## Load some packages
library(data.table)
library(devtools) ## Just for source_gist, really
library(reshape2)

## Load `cSplit`
source_gist("https://gist.github.com/mrdwab/11380733")

First, split your values up and create a "long" dataset:
ddL <- cSplit(cSplit(dd, "C", ";", "long"), "C", "=")
ddL
#    A B C_1 C_2
# 1: 1 3  X1   7
# 2: 1 3  X2   8
# 3: 1 3  X3   9
# 4: 2 4  X1  10
# 5: 2 4  X2  11
# 6: 2 4  X3  12
# 7: 5 6  X1  13
# 8: 5 6  X2  14

Next, use dcast.data.table (or just dcast) to go from "long" to "wide":
dcast.data.table(ddL, A + B ~ C_1, value.var="C_2")
#    A B X1 X2 X3
# 1: 1 3  7  8  9
# 2: 2 4 10 11 12
# 3: 5 6 13 14 NA

A: Here's one possible approach:
dat <- read.table(text="A  B  C
1  3  X1=7;X2=8;X3=9
2  4  X1=10;X2=11;X3=12
5  6  X1=13;X2=14", header=TRUE, stringsAsFactors = FALSE)

library(qdapTools)
dat_C <- strsplit(dat$C, ";")

dat_C2 <- sapply(dat_C, function(x) {
    y <- strsplit(x, "=")
    rep(sapply(y, "[", 1), as.numeric(sapply(y, "[", 2)))
})

data.frame(dat[, -3], mtabulate(dat_C2))

##   A B X1 X2 X3
## 1 1 3  7  8  9
## 2 2 4 10 11 12
## 3 5 6 13 14  0

EDIT To obtain the NA values
m <- mtabulate(dat_C2)
m[m==0] <- NA
data.frame(dat[, -3], m)

A: Here's a nice, somewhat hacky way to get you there.
## read your data
> dat <- read.table(h=T, text = "A  B  C
  1  3  X1=7;X2=8;X3=9
  2  4  X1=10;X2=11;X3=12
  5  6  X1=13;X2=14", stringsAsFactors = FALSE)
## ---
> s <- strsplit(dat$C, ";|=")
> xx <- unique(unlist(s)[grepl('[A-Z]', unlist(s))])
> sap <- t(sapply(seq(s), function(i){
      wh <- which(!xx %in% s[[i]]); n <- suppressWarnings(as.numeric(s[[i]]))
      nn <- n[!is.na(n)]; if(length(wh)){ append(nn, NA, wh-1) } else { nn }
      })) ## see below for explanation
> data.frame(dat[1:2], sap)
#   A B X1 X2 X3
# 1 1 3  7  8  9
# 2 2 4 10 11 12
# 3 5 6 13 14 NA

Basically what's happening in sap is

*

*check which values are missing

*change each list element of s to numeric

*remove the NA values from (2)

*insert NA into the correct position with append

*transpose the result


text:
Q: Can not execute Findbugs: java.lang.OutOfMemoryError: Java heap space, while running mvn sonar:sonar -X i am trying to do the code analysis in sonar 2.11, using maven 3.
I am facing this error
java.lang.OutOfMemoryError: Java heap space.
i tried to increase the MAVEN_OPTS to -Xmx1024m -Xms512m -XX:MaxPermSize=256m but no use.
The project is of large size of about 900MB. I am using the command mvn sonar:sonar -X in maven 3. But the build is failure.
I am not running the tests or nor using  any surefire plugin in my superPOM. So i am unable to find the cause of the problem.
Please help me to figure out where the problem exixts.
Thanks in advance...
Here is the log...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] PHOENIX JAVA MODULE COMPONENT ..................... SKIPPED
[INFO] PHOENIX JAVA COMPONENT ............................ FAILURE [1:27:23.969s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:27:26.229s
[INFO] Finished at: Fri Dec 14 14:14:24 IST 2012
[INFO] Final Memory: 287M/1016M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar (default-cli) on project XXX: Can not execute Sonar: Can not execute Findbugs: java.lang.OutOfMemoryError: Java heap space -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar (default-cli) on project XXX: Can not execute Sonar
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Can not execute Sonar
    at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:118)
    at org.codehaus.mojo.sonar.Bootstraper.start(Bootstraper.java:65)
    at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:90)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: org.sonar.api.utils.SonarException: Can not execute Findbugs
    at org.sonar.plugins.findbugs.FindbugsExecutor.execute(FindbugsExecutor.java:120)
    at org.sonar.plugins.findbugs.FindbugsSensor.analyse(FindbugsSensor.java:58)
    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:64)
    at org.sonar.batch.phases.Phases.execute(Phases.java:93)
    at org.sonar.batch.bootstrap.ProjectModule.doStart(ProjectModule.java:143)
    at org.sonar.batch.bootstrap.Module.start(Module.java:89)
    at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:110)
    at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:105)
    at org.sonar.batch.bootstrap.BatchModule.doStart(BatchModule.java:100)
    at org.sonar.batch.bootstrap.Module.start(Module.java:89)
    at org.sonar.batch.bootstrap.BootstrapModule.doStart(BootstrapModule.java:96)
    at org.sonar.batch.bootstrap.Module.start(Module.java:89)
    at org.sonar.batch.Batch.execute(Batch.java:74)
    at org.sonar.maven3.SonarMojo.executeBatch(SonarMojo.java:147)
    at org.sonar.maven3.SonarMojo.execute(SonarMojo.java:136)
    at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:113)
    ... 23 more
Caused by: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:232)
    at java.util.concurrent.FutureTask.get(FutureTask.java:91)
    at org.sonar.plugins.findbugs.FindbugsExecutor.execute(FindbugsExecutor.java:112)
    ... 38 more
Caused by: java.lang.OutOfMemoryError: Java heap space
    at java.util.ArrayList.<init>(ArrayList.java:112)
    at edu.umd.cs.findbugs.ba.Frame.<init>(Frame.java:110)
    at edu.umd.cs.findbugs.ba.vna.ValueNumberFrame.<init>(ValueNumberFrame.java:58)
    at edu.umd.cs.findbugs.ba.vna.ValueNumberAnalysis.createFact(ValueNumberAnalysis.java:148)
    at edu.umd.cs.findbugs.ba.vna.ValueNumberAnalysis.createFact(ValueNumberAnalysis.java:55)
    at edu.umd.cs.findbugs.ba.Dataflow.execute(Dataflow.java:309)
    at edu.umd.cs.findbugs.classfile.engine.bcel.ValueNumberDataflowFactory.analyze(ValueNumberDataflowFactory.java:72)
    at edu.umd.cs.findbugs.classfile.engine.bcel.ValueNumberDataflowFactory.analyze(ValueNumberDataflowFactory.java:47)
    at edu.umd.cs.findbugs.classfile.impl.AnalysisCache.analyzeMethod(AnalysisCache.java:332)
    at edu.umd.cs.findbugs.classfile.impl.AnalysisCache.getMethodAnalysis(AnalysisCache.java:282)
    at edu.umd.cs.findbugs.ba.ClassContext.getMethodAnalysis(ClassContext.java:942)
    at edu.umd.cs.findbugs.ba.ClassContext.getValueNumberDataflow(ClassContext.java:361)
    at edu.umd.cs.findbugs.detect.FindInconsistentSync2.findObviouslyLockedCallSites(FindInconsistentSync2.java:963)
    at edu.umd.cs.findbugs.detect.FindInconsistentSync2.visitClassContext(FindInconsistentSync2.java:311)
    at edu.umd.cs.findbugs.DetectorToDetector2Adapter.visitClass(DetectorToDetector2Adapter.java:68)
    at edu.umd.cs.findbugs.FindBugs2.analyzeApplication(FindBugs2.java:979)
    at edu.umd.cs.findbugs.FindBugs2.execute(FindBugs2.java:230)
    at org.sonar.plugins.findbugs.FindbugsExecutor$FindbugsTask.call(FindbugsExecutor.java:137)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :XXX

A: This is a well-known problem: Findbugs is really memory hungry, so I'm not surprised that with a 900MB project, you have to increase the JVM memory options quite a lot.
3 things you can do:

*

*increase again the JVM memory options till it is OK

*reduce the amount of activated Findbugs rules in your Sonar quality profile

*refactor your project is smaller modules so that each module requires less memory to get analyzed by Findbugs
If I were you, I'd really go for at least option #3, because 900MB for a single project is really huge.

A: I had similar problem where it used to hung on Journal Flushing and ultimately timeout at whatever the value i set in Findbags Java default timeout in sonarqube or give Out of memory error.
I resolved this by using the following options while running the sonar maven command:- MAVEN_OPTS="-Xms256m -Xmx4096m -XX:+UseSerialGC"
This has fixed the issue for me.
The post which helped me:- http://sonarqube-archive.15.x6.nabble.com/SonarQube-terminates-at-quot-Journal-Flusher-quot-warning-and-heap-size-error-td5027066.html

A: Updating the JDK version on jenkins server to 64 bit solved this issue for me.
Try setting the parameter set SONAR_SCANNER_OPTS=-Xmx1024m in sonar-scanner.bat
or export SONAR_SCANNER_OPTS=-Xmx1024m if invoking through shell script.


text:
Q: Expected performance of training tf.keras.Sequential model with model.fit, model.fit_generator and model.train_on_batch I am using tensorflow to train a 1D CNN to detect specific events from sensor data. While the data with tens of millions samples easily fits to the ram in the form of an 1D float array, it obviously takes a huge amount of memory to store the data as a N x inputDim array that can be passed to model.fit for training. While I can use model.fit_generator or model.train_on_batch to generate the required mini batches on the fly, for some reason I am observing a huge performance gap between model.fit and model.fit_generator & model.train_on_batch even though everything is stored in memory and mini batch generation is fast as it basically only consists of reshaping the data. Therefore, I'm wondering whether I am doing something terribly wrong or if this kind of performance gap is to be expected. I am using the cpu version of Tensorflow 2.0 with 3.2 GHz Intel Core i7 processor (4 cores with multithreading support) and Python 3.6.3. on Mac Os X Mojave.
In short, I created a dummy python script to recreate the issue, and it reveals that with batch size of 64, if takes 407 seconds to run 10 epochs with model.fit, 1852 seconds with model.fit_generator, and 1985 seconds with model.train_on_batch. CPU loads are ~220%, ~130%, and ~120% respectively, and it seems especially odd that model.fit_generator & model.train_on_batch are practically on par, while model.fit_generator should be able to parallelise mini batch creation and model.train_on_batch definitely does not. That is, model.fit (with huge memory requirements) beats the other solution candidates with easily manageable memory requirements by a factor of four. Obviously, CPU loads increase and total training times decrease by increasing batch size, but model.fit is always fastest with a a margin of at least two up to batch size of 8096.
Is this kind of behaviour normal (when there is no GPU involved) or what could be done in order to increase the computation speed of the less memory intensive options? It seems that no such option is available to divide all data into manageable pieces, and then run model.fit in iterative manner.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tqdm       import tqdm

import numpy as np
import tensorflow as tf

import time
import sys
import argparse

class DataGenerator(tf.keras.utils.Sequence):
    'Generates data for Keras'
    def __init__(self, inputData, outputData, batchIndices, batchSize, shuffle):
        'Initialization'
        self.inputData    = inputData
        self.outputData   = outputData
        self.batchIndices = batchIndices
        self.batchSize    = batchSize
        self.shuffle      = shuffle
        self.on_epoch_end()

    def __len__(self):
        'Denotes the number of batches per epoch'
        return int( np.floor( self.inputData.size / self.batchSize ) )

    def __getitem__(self, index):
        'Generate one batch of data'

        # Generate data
        X, y = self.__data_generation(self.indexes[index*self.batchSize:(index+1)*self.batchSize])

        return X, y

    def on_epoch_end(self):
        'Updates indexes after each epoch'
        self.indexes = np.arange(self.inputData.size)
        if self.shuffle == True:
            np.random.shuffle(self.indexes)

    def __data_generation(self, INDX):
        'Generates data containing batch_size samples'

        # Generate data
        X = np.expand_dims( self.inputData[ np.mod( self.batchIndices + np.reshape(INDX,(INDX.size,1)) , inputData.size ) ], axis=2)
        y = self.outputData[INDX,:]

        return X, y

FLAGS = None

parser = argparse.ArgumentParser()

parser.add_argument('--batchSize', type=int,
                default=128,
                help='Batch size')
parser.add_argument('--epochCount', type=int,
                default=5,
                help='Epoch count')

FLAGS, unparsed = parser.parse_known_args()

batchSize = FLAGS.batchSize
epochCount = FLAGS.epochCount

# Data generation

print(' ')
print('Generating data...')

np.random.seed(0) # For reproducible results

inputDim  = int(104)                      # Input  dimension
outputDim = int(  2)                      # Output dimension
N         = int(1049344)                  # Total number of samples
M         = int(5e4)                      # Number of anomalies
trainINDX = np.arange(N, dtype=np.uint32)

inputData = np.sin(trainINDX) + np.random.normal(loc=0.0, scale=0.20, size=N) # Source data stored in a single array

anomalyLocations = np.random.choice(N, M, replace=False)

inputData[anomalyLocations] += 0.5

outputData = np.zeros((N,outputDim)) # One-hot encoded target array without ones

for i in range(N):
    if( np.any( np.logical_and( anomalyLocations >= i, anomalyLocations < np.mod(i+inputDim,N) ) ) ):
        outputData[i,1] = 1 # set class #2 to one if there is at least a single anomaly within range [i,i+inputDim)
    else:
        outputData[i,0] = 1 # set class #1 to one if there are no anomalies within range [i,i+inputDim)

print('...completed')
print(' ')

# Create a model for anomaly detection

model = tf.keras.Sequential([
    tf.keras.layers.Conv1D(filters=24, kernel_size=9, strides=1, padding='valid', dilation_rate=1, activation='relu', use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', input_shape=(inputDim,1)),
    tf.keras.layers.MaxPooling1D(pool_size=4, strides=None, padding='valid'),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(20, activation='relu', use_bias=True),
    tf.keras.layers.Dense(outputDim, activation='softmax')
])

model.compile( tf.keras.optimizers.Adam(),
               loss=tf.keras.losses.CategoricalCrossentropy(),
               metrics=[tf.keras.metrics.CategoricalAccuracy()])

print(' ')

relativeIndices = np.arange(inputDim)                       # Indices belonging to a single sample relative to current position
batchIndices    = np.tile( relativeIndices, (batchSize,1) ) # Relative indices tiled into an array of size ( batchSize , inputDim )
stepsPerEpoch   = int( np.floor( N / batchSize ) )          # Steps per epoch

# Create an intance of dataGenerator class
generator = DataGenerator(inputData, outputData, batchIndices, batchSize=batchSize, shuffle=True)

# Solve by gathering data into a large float32 array of size ( N , inputDim ) and feeding it to model.fit

startTime = time.time()

X = np.expand_dims( inputData[ np.mod( np.tile(relativeIndices,(N,1)) + np.reshape(trainINDX,(N,1)) , N ) ], axis=2)
y = outputData[trainINDX, :]

history = model.fit(x=X, y=y, sample_weight=None, batch_size=batchSize, verbose=1, callbacks=None, validation_split=None, shuffle=True, epochs=epochCount)

referenceTime = time.time() - startTime
print(' ')
print('Total solution time with model.fit: %6.3f seconds' % referenceTime)

# Solve with model.fit_generator

startTime = time.time()

history = model.fit_generator(generator=generator, steps_per_epoch=stepsPerEpoch, verbose=1, callbacks=None, epochs=epochCount, max_queue_size=1024, use_multiprocessing=True, workers=4)

generatorTime = time.time() - startTime
print(' ')
print('Total solution time with model.fit_generator: %6.3f seconds (%6.2f %% more)' % (generatorTime, 100.0 * generatorTime/referenceTime))
print(' ')

# Solve by gathering data into batches of size ( batchSize , inputDim ) and feeding it to model.train_on_batch

startTime = time.time()

for epoch in range(epochCount):

    print(' ')
    print('Training epoch # %2d ...' % (epoch+1))
    print(' ')

    np.random.shuffle(trainINDX)

    epochStartTime = time.time()

    for step in tqdm( range( stepsPerEpoch ) ):

        INDX = trainINDX[ step*batchSize : (step+1)*batchSize ]

        X = np.expand_dims( inputData[ np.mod( batchIndices + np.reshape(INDX,(batchSize,1)) , N ) ], axis=2)
        y = outputData[INDX,:]

        history = model.train_on_batch(x=X, y=y, sample_weight=None, class_weight=None, reset_metrics=False)

    print(' ')
    print('...completed with loss = %9.6e, accuracy = %6.2f %%, %6.2f ms/step' % (history[0], 100.0*history[1], (1000*(time.time() - epochStartTime)/np.floor(trainINDX.size / batchSize))))
    print(' ')

batchTime = time.time() - startTime
print(' ')
print('Total solution time with model.train_on_batch: %6.3f seconds (%6.2f %% more)' % (batchTime, 100.0 * batchTime/referenceTime))
print(' ')

A: model.fit - suitable if you load the data as numpy-array and train without augmentation.
model.fit_generator - if your dataset is too big to fit in the memory or\and you want to apply augmentation on the fly.
model.train_on_batch - less common, usually used when training more than one model at a time (GAN for example)


text:
Q: Batch file computing two numbers I am new to programming and I am having a problem on my batch file.
We were tasked to compute two numbers' difference and if the result is negative, it will compute x+y; if the result is zero, it will compute 2x + 2y; if the result is positive, it will compute x*y.
@echo off

set /p x=Enter the value of X:
set /p y=Enter the value of Y:
set /a diff=%x%-%y%

if diff LSS 0 (goto neg)
if diff EQU 0 (goto zer)
if diff GTR 0 (goto pos)

:neg
echo %diff% is a negative number
set /a R=%x%+%y%
echo R = X + Y where X = %x% and Y = %y%
echo R = %x% + %y% = %R%
echo R = %R%

:zer
echo %diff% is equal to 0
set /a R1=2*%x%+2*%y%
echo R = 2X + 2Y where X = %x% and Y = %y%
echo R = 2(%x%) + 2(%y%) = %R%
echo R = %R1%

:pos
echo %diff% is a positive number
set /a R2=%x%*%y%
echo R = X * Y where X = %x% and Y = %y%
echo R = %x% * %y% = %R2%
echo R = %R2%

pause

when I tried to run and input 1 and 2, which will surely result to a negative. My code displayed the result as positive and it also doesn't detect it if it's == 0 if I input numbers that will result to 0.
Please tell me what I have to change. Thank you.

A: Tip:- You can try to debug your batch script by removing the @echo off command, which will show you each step that the script takes(i.e. How exactly is the code being executed)
There are two mistakes in your code:
1.In the third paragraph when you are trying to compare the value of diff variable in the if statement, you forgot to surround it with "%" (i.e. %diff%).
Which made the if statement compare the "diff" as a string, not its value, to 0. Hence, no matter what value you provided, the if statement would always render the false result, therefore not executing any given statements (i.e. not jumping to the any labels).
2.And for the second issue, you should know that the script is executed line by line. Meaning once a statement is executed, it'll jump the next. Suppose you gave the value of 10 and 5 as the inputs, then there seems to be no problem, because after the diff is greater than 0, it jumps to the :pos label and gradually the code below the label ends exactly with the script.
But if you gave the inputs something like (5 and 10) or (10 and 10), it jumps to the labels :neg and :zer respectively. But since you haven't specified a statement that tells the script to stop running after the block of code below these two labels, all the statements below these two labels are executed.
So, the solution to this issue would be to end the script after the execution of the block of code below these two labels(:neg and :zor).
And you can do so by adding exit /b.
Below is your code rectified with the above methods :
@echo off
set /p x=Enter the value of X:
set /p y=Enter the value of Y:
set /a diff=%x%-%y%

if %diff% LSS 0 (goto neg)
if %diff% EQU 0 (goto zer)
if %diff% GTR 0 (goto pos)

:neg
echo %diff% is a negative number
set /a R=%x%+%y%
echo R = X + Y where X = %x% and Y = %y%
echo R = %x% + %y% = %R%
echo R = %R%
pause
exit /b

:zer
echo %diff% is equal to 0
set /a R1=2*%x%+2*%y%
echo R = 2X + 2Y where X = %x% and Y = %y%
echo R = 2(%x%) + 2(%y%) = %R%
echo R = %R1%
pause
exit /b

:pos
echo %diff% is a positive number
set /a R2=%x%*%y%
echo R = X * Y where X = %x% and Y = %y%
echo R = %x% * %y% = %R2%
echo R = %R2%
pause


text:
Q: precision of a sum of double in jvm I have tests that assert that a sum of values is equal to some expected results. These sum are not exactly the value, so I need to put a precision. This is logical as sum([a, a, a, ...n-times..., a]) != n*a.
But instead of putting an arbitrary precision, I would like to know the expected bound. How can I compute such a bound?
In the specific case that lead to my question, I sum n zeros and k ones (which are obtained by computing difference of doubles, v1-v2). This should thus be equals to k +- precision.
So what precision should be used?

*

*k * 10e-15

*(n+k) * 10e-15

I guess the 10e-15 also depends on the values added: 0 and 1 here


text:
Q: Почему mime_types не правильно определяется? Всем привет, подскажите пожалуйста почему мое загруженное изображение JPEG определено неправильным типом
правильный параметр должен быть image/jpeg на сколько я понимаю

      $mime_types = ['image/bmp', 'image/gif', 'image/jpeg', 'image/png'];

      Validator::extend('is_image_array', function($attribute, $values, $params, $validator) use ($mime_types) {

          foreach ($values as $k => $value) {
              $f = finfo_open();

              $result = finfo_buffer($f, base64_decode($value), FILEINFO_MIME_TYPE);

              dd($f, $value,$result, $mime_types);
              if ( !in_array($result, $mime_types)){
                  return false;
              }
          }
          return true;
      });


text:
Q: Erlang:creating list of tuples within lists:foreach I query the list of users from Mnesia Database in Chicagoboss. I'm getting the error when I try to add the Lists within lists:foreach with ++ operator. My aim is, based on userid I will do ets:lookup to my cache and create a List like - [{{<<"name">>,<<"Batman">>}, {<<"steps">>,2552}, {<<"distance">>,2050}}].
For each user I'll create this list and add with the previous List. So that ultimately I can can sort on <<"steps">> and convert the binary list by json encoding and send it to the client via Websockets.
I'm getting the error at this line:
Reading1 = Reading2 ++ Currentlist
as I've decalred Reading1 as an Empty list.
My question is how can I manipulate the lists within the lists:foreach and then send the result List via websocket?
        BelugaUsers = boss_db:find(users, [{accesstoken, 'not_equals', ''}]),
        Reading1 = [],
        Reading2 = [],
        lists:foreach(fun(X) ->
        {_,_,BEmail,BName,_,_,BAccessToken,_} = X,
        UserKey = BEmail ++ "-" ++ ?MYAPICALL1,
        io:format("UserKey for Leader Board: ~n~p~n",[UserKey]),
        [Reading] = ets:lookup(myapi_cache, list_to_binary(UserKey)),
        {_,Result} = Reading,

        ActivitySummary = proplists:get_value(<<"activitySummary">>, Result),
        %Print ActivitySummary for the user ....printing fine
        io:format("ActivitySummary ==========: ~n~p~n",[ActivitySummary]),

        %Create a list of the format
        %[{{<<"name">>,<<"Batman">>}, {<<"steps">>,2552}, {<<"distance">>,2050}}]

        Currentlist = [{{<<"name">>, list_to_binary(BName)}, {<<"steps">>, proplists:get_value(<<"steps">>, ActivitySummary)}, {<<"distance">>, proplists:get_value(<<"distance">>, ActivitySummary)}}],
        %% HERE I'M GETTING error%%
        Reading1 = Reading2 ++ Currentlist
        end, BelugaUsers),
        %sort the list
        Reading3 = lists:keysort(2, Reading1),
        %reverse the list
        Reading4 = lists:reverse(Reading3),
        WebSocketId ! {text, jsx:encode(Reading4)},

A: Erlang variables are single-assignment; once bound to a value, they can't be re-bound to a different value.
The lists:foreach/2 function is not useful for this problem because it can't create a new value and return it to its caller. You should instead use lists:map/2, perhaps like this:
BelugaUsers = boss_db:find(users, [{accesstoken, 'not_equals', ''}]),
Reading = lists:map(
            fun(X) ->
                    {_,_,BEmail,BName,_,_,BAccessToken,_} = X,
                    UserKey = BEmail ++ "-" ++ ?MYAPICALL1,
                    io:format("UserKey for Leader Board: ~n~p~n",[UserKey]),
                    {_,Result} = hd(ets:lookup(myapi_cache, list_to_binary(UserKey))),

                    ActivitySummary = proplists:get_value(<<"activitySummary">>, Result),
                    %%Print ActivitySummary for the user ....printing fine
                    io:format("ActivitySummary ==========: ~n~p~n",[ActivitySummary]),

                    %%Create a tuple of the format
                    %%{{<<"name">>,<<"Batman">>}, {<<"steps">>,2552}, {<<"distance">>,2050}}
                    {{<<"name">>, list_to_binary(BName)},
                     {<<"steps">>, proplists:get_value(<<"steps">>, ActivitySummary)},
                     {<<"distance">>, proplists:get_value(<<"distance">>, ActivitySummary)}}
            end, BelugaUsers),
%%sort the list
Reading2 = lists:keysort(2, Reading),
%%reverse the list
Reading3 = lists:reverse(Reading2),
WebSocketId ! {text, jsx:encode(Reading3)}.

The lists:map/2 function applies a function to each value in a list to a produce a potentially different value and returns a new list consisting of those new values. This is essentially what you were trying to do with lists:foreach/2 and your attempt to use imperative assignment to add each element to an already-existing list.
You could alternatively use a list comprehension but I think lists:map/2 is clearer in this situation.


text:
Q: Rhino and envjs: share Javascript objects with Java application I'm using rhino and envjs embedded in my java application as described in the envjs guide
Java code:
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.tools.shell.Global;
import org.mozilla.javascript.tools.shell.Main;
...
Context cx = ContextFactory.getGlobal().enterContext();
cx.setOptimizationLevel(-1);
cx.setLanguageVersion(Context.VERSION_1_5);
Global global = Main.getGlobal();
global.init(cx);
Main.processSource(cx, "path/to/your/JSfile");

This is working and my test javascript file correctly loads a remote site and does some manipulation with the HTML elements using jQuery.
What I can't figure out is how to send data from the JavaScript back to my Java application.
Here's my .js file:
load('env.rhino.js');
load('jquery.js');
Envjs.scriptTypes['text/javascript'] = true;
window.location = 'http://[mytestpage].html'
var body = $("body");
print("The body is: "+ $.trim(body));//this prints in the Java console!

//I'd like to call a function in my Java code from the Javascript and pass the bodyText as a parameter to it. How can i do this?
myJavaFunction(bodytext);

A: So this Rhino tutorial was very useful in learning how to connect your Java to JS.
https://developer.mozilla.org/en-US/docs/Scripting_Java


text:
Q: how to pass data from one test to another using set/getattribute in testng rest api testing? I am having issue where I am able to extract the token from login response

So when I do System.out.println(testContext.getAttribute("AUTH_TOKEN")); it prints token but when I use this token in next method to create user it
becomes null

A: The reason behind this is because your second method is running before the first one.
Please change it to as below
@Test(dependsOnMethods="testStatusCode")
public void createUser1(ITestContext testContext) {
//Test code goes here
}

This will ensure that the method createUser1() runs only after the method testStatusCode() (wherein you are setting the AUTH_TOKEN into the ITestContext as an attribute)


text:
Q: How to Build Multiple Dependent .NET Solutions in TeamCity? We've got an application which components are developed in multiple Visual Studio solutions (.sln). From time to time a solution is added or removed. The build output such as DLLs are copied into a shared folder. Projects from other solutions reference those DLLs. Here's a simplified example: solutions A and B consist of two projects each. The project B2 of solution B references project A2 of solution A.

Side note: We're in the process to replace the shared drive with NuGet packages; however, the following question is still apparent.
TeamCity supports build dependencies. This video demonstrate how to set it up manually.
However, we would like TeamCity to automatically(!!) resolve dependencies between projects. So in the above example we'd like that TeamCity builds solution A first and solution B next. How can we configure TeamCity to pick up these dependencies automatically without maintaining them manually?

A: Unfortunately it can't automatically.  You can consider writing your own plugin.
You would usually setup a snapshot dependency, in your example B build would have a snapshot dependency on A build.
In the case of when you have moved to NuGet, it will restore whatever the solution is referencing. You might want to have snapshot dependency like above but not required, each solution would determine what it needs.
Update 1 - Automating
I think you should be able to do it with the Rest API, documentation is not very clear but I did find this gist which has an example of adding and deleting snapshots.
You'll probably need to work out some convention that projects are setup with to make it easier to match projects.
You should also checkout the plugins page for libraries that abstract the API.

A: I have asked this question in the JetBrains Developer Community. JetBrain's comment on this:

[...] it is not a TeamCity-specific issue since I expect that you
  should be able to reproduce such a build procedure locally on
  developer machines. [...] the .net ecosystem itself doesn't provide a
  solution. There is [...] the option to write your own plug-in for
  msbuild or generate solutions (.sln files). [...]

In other words: even using the latest version TeamCity 9 there is no automated way to solve the described problem out of the box. There are multiple alternatives though from fully manual set-ups to custom tooling:

*

*Change multi-solution approach to single solution.

*Change to NuGet rather than manually set up assembly references.

*Set up dependencies in TeamCity manually.

*Write your own plug-in; see also JonSquared's answer.

*Write a custom tool that generates a single solution (SLN) which can be digested by TeamCity.

A: NuGet is certainly a better approach then having the assemblies on a shared drive, so I'm glad to see you're moving in that direction.
As for automatically building consuming projects after a dependant project has been built, you have a few options to trigger the build. Either:

*

*Use the NuGet build trigger
This allows triggering a build when a new package version is added.

*Set up a build dependency between the project.

The next part is tricky and you have a few (tough) choices.
The challenge you have is packages are defined in packages.config and while you can update the package using NuGet update, you need to decide if you want TeamCity to check in the changes. So some ideas on what you can do are:

*

*Check if a package update is available (using NuGet update) and fail the build if there is. This is used as a notification to developers to then manually update the package and deal with any integration issues that may arise.

*Update the packages and check in packages.config. This should be done on a new build configuration which is triggered when a new dependency is available. As this will create a check in, your existing project build will run using the new packages.config.

I would suggest starting with 1) and then move on to 2) when you're feeling confident with the workflow and things aren't going wrong.
What you are trying to do is quite tough, so I hope I've given you more solutions to consider. But I think it's a worthwhile exercise that will help you in the long run. Unfortunately there isn't a one size fits all so you'll have to experiment and mature your processes.
While TeamCity is a great system, it does fall short specifically in how you are attempting to use it. I suggest having a look at ThoughWorks GO. It's better suited for what you are trying to achieve, but unfortunately not as intuitive and mature as TeamCity.
http://www.go.cd


text:
Q: How to detect that after patch value, form data has been changed or not in angular6? In my app, I did patchValue to my formControl, when user click on next/submit button, I want to detect that, Is form value has been changed or not?
Tried

*

*ngOnChanges(changes: SimpleChanges): void {
  alert("Change found");
}

*this.partnerForm.valueChanges.subscribe(val => {
  console.log("[partnerForm valueChanges subscribe]", val);
});

Reason why I need this?

*

*I need to call API when form value has any change otherwise I just need to navigate the user to next page.

A: form.valueChanges doesn't work after patch value.
so for a detect change, you can compare your objects:
let valueChange = (JSON.stringify(oldObj) === JSON.stringify(currentObj))

it will return true or false according to your value changes.

A: first, get your control as FormControl
then check yourFormControl.hasChanged()
this returns true if the value of your form control gets changed


text:
Q: How to fix a terminal after a binary file has been dumped inside it? After having played with curl, a binary file has been dumped inside my terminal. For example, the horizontal lines: ─ I use to format my prompt are replaced by 'q', and it can be much worse.
Why does this happen, and how can you fix it without having to close the terminal
?

A: Best solution I've found is:
echo <ctrl-v><esc>c<enter>
I alias this to "unbinary"

A: I think reset would definitely fix it.
Consider looking into man page.
Example:
[m0nhawk@terra:~]> cat /dev/urandom
êIÉè;┤Ü)MåÇ▐¿÷¢§ôWdO┘&!π¡
[└█┼░▒┬┐@├err▒:·]> c▒├ /de┴/┤r▒┼do└

And resetfixes this.

A: Typing the command stty sane should fix it.


text:
Q: Natural logs with L'Hopital's rule Given $$\lim_{x\to 0} (e^x-2x)^\frac{1}{x} $$ I know that you take the natural log $$\lim_{x\to 0} \frac{1}{x}\ln(e^x-2x) $$ which is $$\lim_{x\to 0} \frac{\ln(e^x-2x)}{x} $$ but what is after this?

A: Now since the limit is of $0/0$ form we can apply L'Hopital's rule. So differentiate numerator and denominator, we get
$\lim_{x \to 0}(e^x-2)/(e^x-2x)=-1$.
Now the real limit comes out to be $e^{-1}$.

A: $$\lim_{x\to 0} (e^x-2x)^{1/x}\neq \lim_{x\to 0} \frac{1}{x}\ln(e^x-2x)$$
$$\lim_{x\to 0} (e^x-2x)^{1/x}=\lim_{x\to 0} e^{\ln{(e^x-2x)}/x}=$$
$$=\exp\left(\lim_{x\to 0}\frac{\ln (e^x-2x)}x\right)$$
Now we can apply L'Hospital Rule, which means differentiating both numerator and denominator
$$\exp\left(\lim_{x\to 0}\frac{e^x-2}{e^x-2x}\right)=e^{-1}=\frac1e$$

A: For the form of limit 1^(infinity),
lim f(x)^g(x) = e^ lim [{f(x) - 1}•g(x)]
Using Maclaurin expansion, you will get e^(-x/x) which is e^-1
e^x = 1 + x/1! + (x^2)/2! + (x^3)/3! ...


text:
Q: QT1070 inconsistent readings on touch pins I recently transitioned my projects capacitive touch IC from using the MPR121 to the QT1070.
I am getting irregular/inconsistent readings on one of the touch pins.  In this particular situation, it is Pin 7 (which equates to "key6" from the docs).  The pin keeps changing its state from touch to untouched, seemingly at random.
Does anyone have any experience operating this chip, particularly in comms mode with I2C?
I am using the schematic below (from the datasheet), and am using 4.7k resistors on all the touch pins.

Is it possible I have to play around with this "detect threshold" business from the docs?

Detect Threshold
  The device detects a touch when the signal has crossed a threshold level and remained there for a specified number
  of counts (see Section 5.10 on page 19). This can be altered on a key-by-key basis using the key threshold I2C
  commands.

I should note that the resistors are not attached to anything, as it is currently operating on a bread board.

A: I found a solution which stabilized the readings.
What I ended up discovering with the QT1070 chip is that you can in fact set a sensitivity threshold for each individual pin.  The sensitivity has to be a value between 1 and 255 and can be set like this:
Wire.beginTransmission(chip_address); //  0x1B
Wire.write(38); // adress for pin 6
Wire.write(200); // sensitivity value between 1 - 255
Wire.endTransmission();

The SeeedQTouch library has a function called setNTHRForKey(value, key) you can use to make this step easier.