SUM values of specific column from all tables LIKE table_%

Question: I need help to create an SQL query in order to SUM the values of specific column from all tables LIKE table_% as the tables will grow over time and this must cater for new table names based on the format below

Scheme Name: database_01
Table Names: tb_data_'YEAR'_'MONTH'

YEAR and MONTH are both values which range from all 12 months and years from 2011 to 2018.

Each Table contains a column called TOTAL_VALUE. I have a php script that triggers an SQL query to pull data from the database.
I would like to SUM the total of each tables TOTAL_VALUE column and save the value for my script below to push the array.
$sql = "SELECT TOTAL_VALUES FROM tb_data_2017_october";
$result = mysqli_query($conn, $sql);

$data = array(); while($enr = mysqli_fetch_assoc($result)){
    $a =  array($enr['TOTAL_VALUES']);
    foreach ($a as $as){
        echo "'".$as."', ";}
    array_push($data, $as); }

I have been trying to alter the SQL with options such as:
SELECT id FROM table1
    UNION
    SELECT id FROM table2
    UNION
    SELECT id FROM table3
    UNION
    SELECT id FROM table4

However i need to cater for the ability to check all tables that are like tb_data_%
Comment: This is a bad database design. If you can - rethink it.
Comment: Agreed with you, however currently this is how the data sits. Migration to single database with columns specifying the data must be done. However I would appreciate any feedback on a possible solution for current. Thanks for your response though.
Comment: Then select all tables from `schema` with names that you need and create a big union query.
Comment: what database server are you using?
Comment: hint: use a loop
Comment: There are new Tables every month, do you know of the method to have it select the table with a similar function to the WHERE LIKE 'name%'
Comment: I am using mySQL 5.1
Comment: Why such an old version?
Comment: Start with https://stackoverflow.com/questions/8334493/get-table-names-using-select-statement-in-mysql
Comment: I tried Dynamic methods from previous stackoverflow questions based on my searchs but my query window states it does not know the language in my version.
Comment: You can also use a the `FEDERATED` engine to create a virtual table that's the union of all those tables. Every month you update the definition of this table to add the new table.
Comment: Oops, I meant the [MERGE](https://dev.mysql.com/doc/refman/5.7/en/merge-storage-engine.html) engine.
Comment: Thanks for the above comments and link. I will read into these.
Answer: Use the MERGE storage engine to create a virtual table that combines all the monthly tables.
CREATE TABLE tb_all_data (
    ...
) ENGINE=MERGE UNION=(tb_data_2017_october, tb_data_2017_november, ...);

List all the tables in the UNION= list, and update it whenever you create a new table.
Then you can just query from tb_all_data.
Comment: @user9560017 From the documentation: The maximum number of rows in a MERGE table is 2^64 (~1.844E+19). If each table contains about 250K rows, you can only combine 72 trillion tables.
Comment: Thanks for this share, is there any limitations i should be cautious about as each table have around 250,000 rows. Also there is no reference in the tables of the month and year, this is only in the table name.
Comment: @user9560017 At 250k rows, you should definitely select the `sum(TOTAL_VALUES)`, and not each individual row.
Comment: Read the documentation I linked to for more caveats.
Comment: There will probably be performance issues if you combine many tables like this, but the same thing happens if you write a `UNION` query.
Comment: You wouldn't use the merged table for queries that need to be specific to a particular month and year, then you use the month-specific table.
Comment: I am running a few other tests now based on the documentation, will let you know the outcome.
Answer: Try this- it will loop through all the tables with the pattern you want and create sums for you:
declare @table table (rowid int identity, name varchar(max))
        insert @table
        select name from sys.tables where name like '%yourname%'

        declare @holding table (name varchar(max), sumvalue int)

        declare @iterator int = 1
        declare @tablename varchar(max)
        while @iterator<=(select max(rowid) from @table)
        begin
        select @tablename=name from @table where rowid=@iterator

        insert @holding
        exec('select '+@tablename+' sum(TOTAL_VALUE)TOTAL_VALUE from '+@tablename+' group by +'+@tablename+'')

        set @iterator=@iterator+1
        end

    select * from @holding

Answer: See this question for information about getting the list of tables: Get table names using SELECT statement in MySQL
You can get the list of tables in one query result, and then query each table. I'll rework your code slightly to give an example:
// Get the tables
$tables_sql = "SELECT table_name
                FROM information_schema.tables
                WHERE table_schema='<your DB>'
                AND table_name LIKE 'tb_data%'";

$tables = mysqli_query($conn, $sql);

// Iterate over the tables
while($table = mysqli_fetch_assoc($tables)){
{
    /*
    * Your code
    */

    // This query assumes that you can trust your table names not to to an SQL injection
    $sql = "SELECT TOTAL_VALUES FROM " . $table['table_name'];
    $result = mysqli_query($conn, $sql);

    $data = array(); while($enr = mysqli_fetch_assoc($result)){
        $a =  array($enr['TOTAL_VALUES']);
        foreach ($a as $as){
            echo "'".$as."', ";
        array_push($data, $as); }
}

You can do whatever you need once your have your list of tables. You can build one big union query (which would be more efficient than querying each table individually), or feed the tables to the MERGE engine, as in barmar's answer
Comment: The following code in full errors relating to sudden end to file. No Echo is resulting unfortunately, could this be based on the table not pulling through the TOTAL_VALUE column?
Comment: @user9560017 It looks like it is because the code that I copied from your question had an extra `}` in it. I've just edited the question to remove the `}` at the end of your echo line (`echo "'".$as."', ";`) in my example.


Detecting open PC COM port from USB Virtual Com Port device

Question: I am using an STM32F105 microcontroller with the STM32_USB-FS-Device_Lib_V3.2.1 USB library and have adapted the VCP example for our purposes (integration with RTOS and serial API).
The problem is that if the USB cable is attached, but the port is not open on the Windows host, after a few minutes the device ends up permanently re-entering the USB ISR until the port is opened and then it all starts working normally.
I have instrumented interrupt handler and can see that when the fault occurs, the ISR handler exits and then immediately re-enters.  This occurs because on exit from the interrupt the IEPINT flag in OTG_FS_GINTSTS is not clear. The OTG_FS_DAINT at this time contains 0x00000002 (IEPINT1 set), while DIEPINT1 has 0x00000080 (TXFE).  The line in OTGD_FS_Handle_InEP_ISR() that clears TXFE is called, but the bit either does not clear or becomes immediately reasserted. When the COM port on the host is reopened, the state of OTG_FS_GINTSTS and OTG_FS_DAINT at the end of the interrupt is always zero, and further interrupts occur at the normal rate.  Note that the problem only occurs if data is being output but the host has no port open.  If either the port is open or no data is output, the system runs indefinitely.  I believe that the more data that is output the sooner the problem occurs, but that is anecdotal at present.
The VCP code has a state variable that takes the following enumerated values:
  UNCONNECTED,
  ATTACHED,
  POWERED,
  SUSPENDED,
  ADDRESSED,
  CONFIGURED

and we use the CONFIGURED state to determine whether to put data into the driver buffer for sending. However the CONFIGURED state is set when the cable is attached not when the host has the port open and an application connected.  I see that when Windows does open the port, there is a burst of interrupts so it seems that some communication occurs on this event; I wonder if it is possible therefore to detect whether the host has the port open,.
I need one of two things perhaps:

To prevent the USB code from getting stuck in the ISR in the first instance
To determine whether the host has the port open from the device end, and only push data for sending when open.
Comment: Did you mean stm32f105 instead of stm32f015?
Comment: @Étienne : Only three years for that to be spotted!  Thanks.
Answer: Part (1) - preventing the interrupt lock-up - was facilitated by a USB library bug fix from ST support; it was not correctly clearing the TxEmpty interrupt.
After some research and assistance from ST Support, I have determined a solution to part (2) - detecting whether the host port is open.  Conventionally, when a port is opened the DTR modem control line is asserted.  This information is passed to a CDC class device, so I can use this to achieve my aim.  It is possible for an application to change the behaviour of DTR, but this should not happen in any of the client applications that are likely to connect to this device in this case.  However there is a back-up plan that implicitly assumes the port to be open if the line-coding (baud, framing) are set.  In this case there is no means of detecting closure but at least it will not prevent an unconventional application from working with my device, even if it then causes it to crash when it disconnects.
Regarding ST's VCP example code specifically I have made the following changes to usb_prop.c:
1) Added the following function:
#include <stdbool.h>
static bool host_port_open = false ;
bool Virtual_Com_Port_IsHostPortOpen()
{
    return bDeviceState == CONFIGURED && host_port_open ;
}

2) Modified Virtual_Com_Port_NoData_Setup() handling of SET_CONTROL_LINE_STATE thus:
else if (RequestNo == SET_CONTROL_LINE_STATE)
{
  // Test DTR state to determine if host port is open
  host_port_open = (pInformation->USBwValues.bw.bb0 & 0x01) != 0 ;
  return USB_SUCCESS;
}

3) To allow use with applications that do not operate DTR conventionally I have also modified Virtual_Com_Port_Data_Setup() handling of SET_LINE_CODING thus:
  else if (RequestNo == SET_LINE_CODING)
  {
    if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
    {
      CopyRoutine = Virtual_Com_Port_SetLineCoding;

      // If line coding is set the port is implicitly open
      // regardless of host's DTR control.  Note: if this is
      // the only indicator of port open, there will be no indication
      // of closure, but this will at least allow applications that
      // do not assert DTR to connect.
      host_port_open = true ;

    }
    Request = SET_LINE_CODING;
  }

Answer: I found another solution by adopting CDC_Transmit_FS.
It can now be used as output for printf by overwriting _write function.
First it checks the connection state, then it tries to send over USB endport in a busy loop, which repeats sending if USB is busy.
I found out if dev_state is not USBD_STATE_CONFIGURED the USB plug is disconnected. If the plug is connected but no VCP port is open via PuTTY or termite, the second check fails.
This implementation works fine for me for RTOS and CubeMX HAL application. The busy loop is not blocking low priority threads anymore.
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
    uint8_t result = USBD_OK;

    // Check if USB interface is online and VCP connection is open.
    // prior to send:
    if ((hUsbDevice_0->dev_state != USBD_STATE_CONFIGURED)
            || (hUsbDevice_0->ep0_state == USBD_EP0_STATUS_IN))
    {
        // The physical connection fails.
        // Or: The phycical connection is open, but no VCP link up.
        result = USBD_FAIL;
    }
    else
    {

        USBD_CDC_SetTxBuffer(hUsbDevice_0, Buf, Len);

        // Busy wait if USB is busy or exit on success or disconnection happens
        while(1)
        {

            //Check if USB went offline while retrying
            if ((hUsbDevice_0->dev_state != USBD_STATE_CONFIGURED)
                        || (hUsbDevice_0->ep0_state == USBD_EP0_STATUS_IN))
            {
                result = USBD_FAIL;
                break;
            }

            // Try send
            result = USBD_CDC_TransmitPacket(hUsbDevice_0);
            if(result == USBD_OK)
            {
                break;
            }
            else if(result == USBD_BUSY)
            {
                // Retry until USB device free.
            }
            else
            {
                // Any other failure
                result = USBD_FAIL;
                break;
            }

        }
    }

    return result;
}

CDC_Transmit_FS is used by _write:
// This function is used by printf and puts.
int _write(int file, char *ptr, int len)
{
    (void) file; // Ignore file descriptor
    uint8_t result;

    result = CDC_Transmit_FS((uint8_t*)ptr, len);
    if(result == USBD_OK)
    {
        return (int)len;
    }
    else
    {
        return EOF;
    }
}

Regards
Bernhard
Comment: It seems, that you solution deosnt work. The following condition is false even if port is not opened on a host.
hUsbDevice_0->ep0_state == USBD_EP0_STATUS_IN
Comment: 'USBD_EP0_STATUS_OUT' is set if port is opened.
'USBD_EP0_STATUS_IN' is set if port is not opened.

Are you sure, that you use '==', but not '!=' ?
Answer:
I need one of two things perhaps:

To prevent the USB code from getting stuck in the ISR in the first instance
To determine whether the host has the port open from the device end, and only push data for sending when open.

You should attempt to do option 1 instead of 2.  On Windows and Linux, it is possible to open a COM port and use it without setting the control signals, which means there is no fool-proof, cross-platform way to detect that the COM port is open.
A well programmed device will not let itself stop functioning just because the USB host stopped polling for data; this is a normal thing that should be handled properly.  For example, you might change your code so that you only queue up data to be sent to the USB host if there is buffer space available for the endpoint.  If there is no free buffer space, you might have some special error handling code.
Comment: I posted the solution I used in an answer in March 2011.  The interrupt lock-up was a bug in the vendor's code. The driver was already fed from a queue that baulks when full in any case; detecting port open was implemented as described, but is not critical to the application.  Since then 50000 units have shipped - so I guess it is successful.
Answer: After so much searching and a kind of reverse engineering I finally found the method for detecting the open terminal and also it's termination. I found that in the CDC class there is three Data nodes , one is a control node and the other two are data In and data Out nodes.Now when you open a terminal a code is sent to the control node and also when you close it. all we need to do is to get those codes and by them start and stop our data transmission tasks. the code that is sent is  respectively 0x21 and 0x22 for opening and closing the terminal.In the usb_cdc_if.c there is a function that receive and interpret those codes (there is a switch case and the variable cmd is the code we are talking about).that function is CDC_Control_FS . Here we are, Now all we need to do is to expand that function so that it interpret the 0x22 and 0x21 . there you are , now you know in your application whether the port is open or not.
Answer: I have the same requirement to detect PC port open/close. I have seen it implemented it as follows:
Open detected by:

DTR asserted
CDC bulk transfer

Close detected by:

DTR deasserted
USB "unplugged", sleep etc

This seems to be working reasonably well, although more thorough testing will be needed to confirm it works robustly.
Answer: Disclaimer: I use code generated by Cube, and as a result it works with HAL drivers. Solutions, proposed here before, don't work for me, so I have found one. It is not good, but works for some purposes.
One of indirect sign of not opened port arises when you try to transmit packet by CDC_Transmit_FS, and then wait till TxState is set to 0. If port is not opened it never happens. So my solution is to fix some timeout:
uint16_t count = 0;
USBD_CDC_HandleTypeDef *hcdc =
        (USBD_CDC_HandleTypeDef*) USBD_Device.pClassData;

while (hcdc->TxState != 0) {
    if (++count > BUSY_TIMEOUT) { //number of cycles to wait till it makes decision
        //here it's clear that port is not opened
    }
}

The problem is also, that if one tries to open port, after device has tried to send a packet, it cant be done. Therefore whole routine I use:
uint8_t waitForTransferCompletion(void) {

    uint16_t count = 0;
    USBD_CDC_HandleTypeDef *hcdc =
             (USBD_CDC_HandleTypeDef*) USBD_Device.pClassData;

    while (hcdc->TxState != 0) {
        if (++count > BUSY_TIMEOUT) { //number of cycles to wait till it makes decision
            USBD_Stop(&USBD_Device); // stop and
            MX_USB_DEVICE_Init(); //            init device again
            HAL_Delay(RESET_DELAY); // give a chance to open port
            return USBD_FAIL; // return fail, to send last packet again
        }
    }

    return USBD_OK;
}

The question is, how big timeout has to be, not to interrupt transmission while port is opened. I set BUSY_TIMEOUT to 3000, and now it works.
Answer: I fixed it by checking of a variable  hUsbDeviceFS.ep0_state.
It equal 5 if connected and 4 if do not connected or was disconnected.
But. There are some issue in the HAL. It equal 5 when program started.
Next steps fixed it at the begin of a program
        /* USER CODE BEGIN 2 */
            HAL_Delay(500);
            hUsbDeviceFS.ep0_state = 4;

...

I do not have any wishes to learn the HAL - I hope this post will be seeing by developers and they will fix the HAL.
It helped me to fix my issue.


Unable to install tensorflow on windows 7

Question:
I'm currently trying to install tensorflow on windows 7 (64 bits). I have python 3.5.2 version (64 bits). I tried to follow the instructions on https://www.tensorflow.org/install/install_windows by taping:
pip3 install --upgrade tensorflow in the cmd.

I had the error below:

Could not find a version that satisfies the requirement tensorflow
  from versions.  No matching distributions found from tensorflow.

I tried the other way using a wheel file that I downloaded from https://pypi.python.org/pypi/tensorflow/1.0.1 :
pip3 install --upgrade tensorflow-1.0.1-cp35-cp35m-win_amd64

or
pip install --upgrade tensorflow-1.0.1-cp35-cp35m-win_amd64

They both don't work and it gives me now:

Could not find a version that satisfies the requirement tensorflow
  from versions. No matching distributions found for wheel from
  tensorflow

Could someone help me please?!!!
Comment: if you have downloaded the wheel file tensorflow-1.0.1-cp35-cp35m-win_amd64 then try pip3 install tensorflow-1.0.1-cp35-cp35m-win_amd64, If you want tot download tensorflow then don't put the entire name in the cmd
Comment: If you do `pip3 -V` in the command line, what do you see? If you have multiple python versions installed, pip3 might be part of a different python version than you think it is.  It also might be worth moving to anaconda.  It'll let you get venvs set up and try different python versions more easily.
Comment: I put pip3 -V in the cmd and I got:

pip 8.1.1 from C:\Python35\lib\site-packages
Answer: Try upgrading pip3 to recent version and install using
{pip3 install --upgrade tensorflow}


How to customize titles and y labels in a relplot

Question: I currently have a seaborn relplot
harker = sns.relplot(data = majorsLong, x = "SiO2", y = "Wt %", palette = colors,
                     markers = marks, style = "Lithology", hue = "Lithology",
                     kind = "scatter", col = "Oxide", col_wrap = 2, s = 150,
                     facet_kws = {'sharey': False, 'sharex': True},
                     linestyle = "None", legend = False)

Which creates this figure.

I want to do two things with this figure. First, I want to remove all of the subplot titles. Second, I want to set each y label (even the interior ones) to be "Oxide" + " Wt %", but can't figure out how to do either.
Answer: You can set those directly from you harker FacetGrid object:
harker.set_titles("")
harker.set_ylabels("My Label", clear_inner=False)

You don't need to iterate through the axes, these methods set them on all facets.
Answer: You can iterate through harker.axes:
for ax in harker.axes.flatten():
    ax.set_title('')
    ax.set_ylabel('Oxide + Wt %')

Comment: This is the answer to use if someone wants to independently customize each y-label or title.
Answer: Above answers would work, but they hack the matplotlib axes/facets.
Seaborn implements this functionality in FacetGrid which relplots (and other faceted plots) all use:
g.set_titles(col_template="{col_name}", row_template="{row_name}")

From the documentation:

The FacetGrid object has some other useful parameters and methods for tweaking the plot:

g = sns.FacetGrid(tips, col="sex", row="time", margin_titles=True)
g.map_dataframe(sns.scatterplot, x="total_bill", y="tip")
g.set_axis_labels("Total bill ($)", "Tip ($)")
g.set_titles(col_template="{col_name} patrons", row_template="{row_name}")
g.set(xlim=(0, 60), ylim=(0, 12), xticks=[10, 30, 50], yticks=[2, 6, 10])
g.tight_layout()
g.savefig("facet_plot.png")


Install Vanilla Wordpress to Drupal to use Vanilla Forum

Question: any one knows how to install vanilla forum to drupal. I try to search a good article but could not success.I need step by step to do this.
Comment: Wordpress and Drupal are completely separate CMS. You don't install Wordpress on Drupal, you install both on your webserver. Can you clarify what exactly you want to achieve?
Comment: requirement says to install vanilla wordpress install to drupal. I believe it vanilla forum.
Comment: yep. I want to know how to add this to Drupal project and how ti use this.
Answer: You might need to install Orchid. Only by using this module you can integrate Drupal with Vannila Forum.
Comment: i have successfully install the module and try to follow the guide in https://drupal.org/node/1117992. It seems I didn't get the consept behind this. How do I install Vanilla forum and  jsconnect plugin to the drupal site. currently i'm running aquia drupal one


node_load_multiple does not respect node access grants

Question: I used $nodes = node_load_multiple(NULL, array("title" => "Foo Bar")); to fetch nodes by titles. But after going through Drupal security standards, node_load_multiple is not the right way to load all nodes.
node_load_multiple() will load ALL nodes regardless of access, so that must not be used here.
Solution suggestion is:

Use an entity query instead. "When adding a node listing to your
  module, be sure to use an entity query, which will add a tag of
  "node_access". This will allow modules dealing with node access to
  ensure only nodes to which the user has access are retrieved"

But I'm not sure how to apply above statement programmaticly?
Is below query the right way that solves security issues?
\Drupal\node\Entity\Node::loadMultiple(NULL, array("title" => "Foo Bar"));

If not, please suggest an appropriate alternate of loading nodes by title that respects node access grants.
Answer: You can do it like this. First, query the NIDs, with a query that is tagged for node access, then load the nodes with the found NIDs.
$nids = db_select('node_field_data', 'n')
  ->fields('n', ['nid'])
  ->condition('title', $my_title)
  // The node_access tag will check access rights.
  ->addTag('node_access')
  ->execute()
  ->fetchCol();

$nodes = Node::loadMultiple($nids);

Untested in D8, but it should work.
Comment: That won't work in D8 as there are multiple tables. You should use an entity query instead, which includes node access by default. Otherwise correct answer
Comment: Oops - you're right. I updated the code to deal with that. As for entity query - I haven't done any benchmarking in D8, but in D7 it (EntityFieldQuery) was significantly heavier for queries, to a level that I never used it. I'll have to do some D8 benchmarking to see if it's improved.
Comment: It's definitely still slower, but that's not the point. It is the only supported API when querying entities. It is technically supported to alter the node entity type and make it non-translatable or non-revisionable, which changes the table structure
Answer: You could get all the node titles with a SQL query like:
  $row = db_query('SELECT nid FROM {node} WHERE title = :mytitle',   array(':mytitle' => $myNewTitle))->fetchField();
   if(!isset($row['nid'])) {
//safe to continue
     } else {
//that title is already there and its in node with node id "nid"
 }

And if there are no results returned then you may assume you're good to go.


What property should I use for a Dispatch Queue after ARC?

Question: I maintain a dispatch queue as a property with my view controller. I create this queue once in my view controller's init method, and reuse a few times for some background tasks. Before ARC, I was doing this:
@property (nonatomic, assign) dispatch_queue_t filterMainQueue;

And in init:
if (filterMainQueue == nil) {
     filterMainQueue = dispatch_queue_create("com.myQueue.CJFilterMainQueue", NULL);
}

But after ARC, I'm not sure if this should still be "assign", or should it be "strong" or "weak". The ARC convertor script didn't change anything but I'm not sure if a subtle bug is coming from the fact that this queue might be deallocated while it's being used?
What would be the difference between the 3 types of properties, and what will work the best for a dispatch queue, when using ARC?
Answer: Updated answer:
In current OS X and iOS, Dispatch objects are now treated as Obj-C objects by ARC. They will be memory-managed the same way that Obj-C objects will, and you should use strong for your property.
This is controlled by the OS_OBJECT_USE_OBJC macro, defined in <os/object.h>. It's set to 1 by default when your deployment target is OS X 10.8 or higher, or iOS 6.0 or higher. If you're deploying to an older OS, then this is left at 0 and you should see my original answer below.

Original answer:
Dispatch objects (including queues) are not Obj-C objects, so the only possible choice is assign. The compiler will throw an error if you try to use strong or weak. ARC has no impact on GCD.
Comment: This is no longer true in Mountain Lion - see /usr/include/os/object.h.  GCD and XPC "objects" (anything you might explicitly release) now behave enough like ObjC objects that they can participate in ARC.
Comment: It is a good idea to check not if support present, but rather if it's in use. check for `OS_OBJECT_USE_OBJC` instead
Comment: @Ankur: As of iOS 6.0, yes.
Comment: @JimThio: [Grand Central Dispatch](http://developer.apple.com/library/ios/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html)
Comment: @jkh does that include the iOS platform as well?
Comment: @KevinBallard Given that this is the accepted answer but is now wrong (as the comments note), you should edit your answer so people don't get wrong information.
Comment: So you use `strong` but no asterisk. Ok!
Answer: Here is how one would define dispatch_queue_t property for iOS 6.0 and above AND below iOS 6.0
#if OS_OBJECT_HAVE_OBJC_SUPPORT == 1
@property (nonatomic, strong) dispatch_queue_t serialDispatchQueue;
#else
@property (nonatomic, assign) dispatch_queue_t serialDispatchQueue;
#endif

Basically OS_OBJECT_HAVE_OBJC_SUPPORT is defined as 1 for iOS 6.0 and above. (MAC 10.8 and above). Below iOS 6 it is defined as 0.
OS_OBJECT_HAVE_OBJC_SUPPORT defines that OS objects like GCD have objective C support. So ARC, memory management, reference counting etc. applies to GCD objects.
Comment: This somehow fails for CocoaPods libraries http://stackoverflow.com/q/27267865/1049134
Answer: Here is what I use:
@property (readwrite, strong, nonatomic) __attribute__((NSObject)) dispatch_queue_t queue;

Comment: It basically turns a non-ObjC object into an ObjC property so you can easily use it like self.queue
Comment: I would agree...those crazy folks at Apple. What will they do next? ;-)
Comment: @Arvin Something changed with 6.1 that affected this. It complained about __attribute__ and removing it seems to work now. I haven't run into any issues so I'm guessing property (readwrite, strong, nonatomic) dispatch_queue_t queue is safe?
Answer: Based on iOS7, I tested whether dispatch_queue object is an objective-C object and I figured out they already are objective-c object.  to paraphrase this, attribute((NSObject)) is not necessary now.
Answer: TL;DR: dispatch_queue_t is an Objective C object now and can be managed with ARC.
I haven't tested how far back this is true, but using the iOS 7 SDK and Xcode 5, dispatch_queue_t is an object type. I am declaring a property for a queue as
@property (nonatomic, strong) dispatch_queue_t syncQueue;

The compiler is happy and everything works as expected. I know definitively that this used to not work in iOS 4 or 5 (pre-ARC it was retain instead of strong). I dug into the definition for dispatch_queue_t and found this:
/*!
 * @typedef dispatch_queue_t
 *
 * @abstract
 * Dispatch queues invoke blocks submitted to them serially in FIFO order. A
 * queue will only invoke one block at a time, but independent queues may each
 * invoke their blocks concurrently with respect to each other.
 *
 * @discussion
 * Dispatch queues are lightweight objects to which blocks may be submitted.
 * The system manages a pool of threads which process dispatch queues and
 * invoke blocks submitted to them.
 *
 * Conceptually a dispatch queue may have its own thread of execution, and
 * interaction between queues is highly asynchronous.
 *
 * Dispatch queues are reference counted via calls to dispatch_retain() and
 * dispatch_release(). Pending blocks submitted to a queue also hold a
 * reference to the queue until they have finished. Once all references to a
 * queue have been released, the queue will be deallocated by the system.
 */
DISPATCH_DECL(dispatch_queue);

By the sounds of that, it shouldn't work, so I checked the definition of DISPATCH_DECL and found this, which explains everything:
/*
 * By default, dispatch objects are declared as Objective-C types when building
 * with an Objective-C compiler. This allows them to participate in ARC, in RR
 * management by the Blocks runtime and in leaks checking by the static
 * analyzer, and enables them to be added to Cocoa collections.
 * See <os/object.h> for details.
 */


Use of KS statistics to choose the probability cut-off in logistic regression model

Question: I was doing some reading on choosing the score cut-off of a logistic regression model using the KS-Stats. Suppose I fitted a logistic regression model on the train data and now want to decide the probability cut-off to get the confusion matrix. After ranking them into deciles based on the estimated probabilities and calculated the KS value for each group. Let's assume the supremum KS lies in the 4th group. In practice, practitioners take the minimum probability of that group as the score cut-off and build the confusion matrix. Now my question is why to choose the minimum probability of that decile/group? The actual supremum(if we increase the number of groups we will be closer to the actual supremum) may lie anywhere in the 4th decile or 5th decile. Intuitively I can understand the logic, still, if someone can explain the logic in a more statistical way, it would be great.
Comment: I suggest you take a look at this: https://stats.stackexchange.com/a/312787/1352 (note the links to blog posts by Frank Harrell).
Answer: There are many fundamental misunderstandings of statistical modeling encapsulated in your question.  These misunderstandings have been written about at length on this site.   Among them, the logistic model is a probability estimator and uses no cutoffs on the resulting estimates.  KS is not relevant here, and quantile groups are not relevant either.  The logistic model is distinct from the logistic distribution for continuous responses.


Showing the closure of a compact subset need not be compact

Question: Could someone tell me if my line of reasoning is correct here:
Say we have the topological space $(\mathbb{N}, T)$ comprising of the empty set together with all subsets of $\Bbb N$ that contain the element $1$.
I want to show that the closure of a compact set in this topology need not be compact.
Let $A \equiv \{1, ...., n\}$.
Then, this set is compact as it can be covered by a single open set in $T$.
Its limit points are every number in $\Bbb N$ which is not 1.
Therefore, its closure is $\overline{A} = \Bbb N$
If the above is true then I get confused because it seems that $\Bbb N$ is an open set in $T$ so therefore can it not also be covered with a single open set in T and so would be compact as well? (I know intuitively that compact, being in some sense a measure of 'smallness', would indicate that $\Bbb N$ shouldn't be compact but I don't see how to get that line of reasoning using the properties of this topology)
Comment: Your reasoning for $A$ being compact seems incorrect. $A = \{1, \ldots, n\}$ is compact because given an open cover $\{ B_\alpha \}$ of $A$, we can find $B_{\alpha_k} \ni k$ for each $k \in A$ so that $\{ B_{\alpha_k} \}_{k=1}^n$ covers $A$. $\mathbb{N}$ is not compact in your topology because the infinite cover $\{  \{1, \ldots, n\} \}_{n=1}^\infty$ of $\mathbb{N}$ cannot be reduce to a finite subcover.
Comment: I'm not sure what you mean, but you should use [this definition of compactness](https://en.wikipedia.org/wiki/Compact_space#Open_cover_definition). I've included an argument for why $\mathbb{N}$ is not compact in my comment above that you can revisit after understanding the linked definition.
Comment: @parsiad Ah okay , so I should think of each one of the points in A needing to be covered by an open set in T rather than the set itself being able to be fully covered by a single set. So then using that fact I could then use the rest of my argument to say that $\Bbb N$ is not compact as given an open cover $\{B_\alpha\}$ of $\Bbb N$ then for each $n\in \Bbb N$ we can cover it with a set from T but we need infinitely many to do it for all points so it's not compact ?
Comment: @parsiad what you said in your comment is what I meant. Thanks ! But maybe the part I was unclear about was that I think I had been considering the set A={1,...n} as being able to be covered by the set {1,....n} in T, but as it says in the definition we have to think about A as being covered by points in a collection of open sets within A, and this can be reduced to a finite number of open sets which do this . Are the limit point and closure part of my argument is fine ,correct ?
Comment: Yes, I think that part of your argument is correct. I posted a detailed answer anyways.
Comment: @parsiad thank you, everything you've said has completely cleared things up for me :)
Comment: The definition of a compact set requires that *every* open cover has a finite sub-cover. *Some* open covers will always have a finite sub-cover, indeed every set has an open cover that is already finite, consisting of just the whole space.
Comment: FYI: it looks like someone [your counterexample](https://math.stackexchange.com/questions/2399624/closure-of-a-compact-space-always-compact) is a common one to demonstrate this phenomenon!
Answer:
Definition. Let $A \subset X$ where $(X, \tau)$ is a topological space.
  We call $A$ compact if for each collection $\{ B_\alpha \} \subset \tau$ such that $\cup_\alpha B_\alpha \supset A$, we can find a finite subcollection $\{B_{\alpha_1}, \ldots, B_{\alpha_n}\}$ such that $B_{\alpha_1 } \cup \cdots \cup B_{\alpha_n} \supset A$.
Remark. We call the original collection an open cover and the subcollection a finite subcover.

Consider the topology in your original question.
Let $A \equiv \{1, \ldots, n\}$ and $\mathscr{B} \equiv \{B_\alpha\}$ be an open cover of $A$.
Let $k$ be a member of $A$.
Since $\mathscr{B}$ is a cover of $A$, we can find $\alpha_k$ such that $k \in B_{\alpha_k}$.
Therefore, $\{B_{\alpha_k}\}_{k=1}^n$ covers $A$, and hence $A$ is compact.
Next, let $C_n \equiv \{1,\ldots,n\}$ and consider the cover $\mathscr{C} \equiv \{C_n\}_{n=1}^\infty$ of $\mathbb{N}$.
Let $\mathscr{C}^\prime$ be a finite subcollection of $\mathscr{C}$.
Note that the set $\bigcup_{C \in \mathscr{C}^\prime} C$ has a maximum element (call it $N$) and hence this subcollection does not cover $\mathbb{N}$ (because none of its members contain $N+1$).
This shows that $\mathbb{N}$ is not compact.
Next, let $n > 1$.
Since any open set in your topology must have 1 as a member, it follows that $n$ is a limit point of $A$.
Therefore, $\overline{A} = \mathbb{N}$.
In summary, you have just found an example of a topology for which the closure of a compact set is not necessarily compact.
This is only possible for non-Hausdorff spaces.
Indeed, your topology is non-Hausdorff since any two non-empty neighbourhoods are not disjoint because they both contain the point 1.
Comment: Is there a topological space $Y$ that has a compact subset $A\subset Y$ with _infinitely many points_ ($|A|=\infty$), and still $\overline{A} \ne A$? Maybe even $\overline{A}$ is noncompact like above.
Comment: @JeppeStigNielsen: [You can modify the same idea in OP's example to get what you want](https://math.stackexchange.com/questions/548865/topology-example-of-a-compact-set-but-its-closure-not-compact/549439) :-)
Answer: $A=\{1\}$ is compact as any cover of it has a one-element subcover.
$\overline{A} = \mathbb N$ which is not compact, as witnessed by the open cover $$\{\{1,2\},\{1,3\},\{1,4\},\ldots, \{1,n\}, \ldots\}$$ of $\mathbb N$ from which we cannot omit a member (or it wouldn't cover), so has no finite subcover.
Comment: To the proposer: No infinite $B\subset \Bbb N$ is  compact in this topology because $\{\{1,b\}: b\in B\}$ is an open cover of $B$ with no finite sub-cover.  And any finite subset (in any topological space) is compact.  So in this topology on $\Bbb N,$ a subset is compact iff it is finite.   So if $1\in C\subset \Bbb N$ and $C$ is finite then $C$ is compact but  $\overline C=\Bbb N$ is not compact.


How to fast return and count rows from one table based on filter by two another tables

Question: I have 3 tables:
products (1 500 000 rows)
+------------+-------------+-------------+-------------+
|     id     |     shop    |    brand    |   category  |
+------------+-------------+-------------+-------------+

id int(11), AI, PK;
shop int(11);
brand int(11);
category int(11);

tags (1 300 000 rows)
+------------+------------+-------------+
|     id     |   product  |     tag     |
+------------+------------+-------------+

id int(11), AI, PK;
product int(11) - it's id from 'products' table;
tag int(11);

sizes (1 300 000 rows)
+------------+------------+-------------+
|     id     |   product  |     size    |
+------------+------------+-------------+

id int(11), AI, PK;
product int(11) - it's id from 'products' table;
tag int(11);

Every column has index.
I need to filter all products (including count rows) which may be filtered by brand,shop,category,tag,size. So, for example if i need to just show products where brand=1 and shop=1 I will not use tags and sizes tables. It's simple. But the problem is, when I would like to show all products which are in some categories, some shops, has some brand, some tags and some size.
There are many combinations to cache all of them and update. Get live count costs about 6 second. To show all filtered products is fast because of limit for paggination.
I have spent more then week to test what is faster, which option and structure of database is better but definitely don't know to make it faster than this:
select p.id
  FROM
products p
  INNER JOIN tags t ON(p.id = t.product and tags=2)
  INNER JOIN sizes s ON(p.id = s.product and sizes in (1,2))
  WHERE
p.shop in (1,13,31,65)
  and
p.category in (270,126,127,144,143,145,146,839,147,148,149,150,158,151,155,157,123,124,128,129,602,120,121,122,152,153,154,482,526,40,42,46,115,119,138,142,133,135,136,137,130,131,132,116,117,32,103,485,112,113,114,566,39,107,108,109,110,118,265,516,527,528,529,530,106,159,161,185,30,86,87,88,89,90,91,92,267,531,532,104,105,28,29,31,33,34,35,36,37,38,41,43,44,45,102,165,269,487,2)
  GROUP BY p.id

There are now only 1,5M products and the filtering based on category which has 200k products (because of top of tree) is loading (counting and showing data) about 5s. It's because filtered products has result of 13k rows in category of 200k products. But still need to compare and search in all data tables. One of solution could be to separate all products to f.e. 10 table categories (for clothing, electro, drug store, food...) and search just there. But I don't think it's the best solution for the problem. Only better then now.
Doing result of this SQL with the  order by p.id DESC limit 0,120 is pretty fast. About 0,8s but count them in some case is about 8-12s. Is there any chance to get faster the result and count by changing SQL query or changing structure of DB?
Thank you for any help.
Comment: "Every column has index" is not necessarily the optimal solution to use indexes. A covering index might improve speed (see: https://stackoverflow.com/questions/8213235/mysql-covering-vs-composite-vs-column-index)
Comment: Do you need all the data at once? Limiting the fetched rows might be also helpful
Comment: A good way to experiment with the indexes, and the covering indexes Luuk suggested, is to use [EXPLAIN](https://dev.mysql.com/doc/refman/8.0/en/using-explain.html).
Comment: @Luuk I'll try and let you know.
Comment: @MetaPakistani as i said, i don't need to use all data only 120 of them per one page. BUT, if i want to know how many pages show and as well use the number in title of category, i need to count all of them.
Comment: @KIKOSoftware I have used EXPLAIN but don't really understand how to use it to change my query.
Comment: While there are many things that you can optimize including primary keys, indices and the sql query, if fesible, I will suggest storing the related tables' count number along with categories/shops and periodically updating them via corn
Comment: @MetaPakistani did you read it till the end?
PKs are there, storing (as i mentioned caching) is not possible because of too many combinations and it doesn't make sense to have updated product every month. Products are changing hourly.
Comment: In last paragraph, you mentioned that limiting the results is pretty fast but when you include counting then it bumps to 8s, I am saying that instead of counting them dynamically in query, pre-process and store the counting related which you can fetch statically
Comment: @MetaPakistani Yes, I understand you. But I don't know what all combinations user will use. Prepare all combinations of filter which every product has. It's all combinations of all categories inside the product is (may be 100) and combinations of shop and brand (3 combinations because one brand and one shop per product and may be f.e. shop- brand; shop; brand) that everyhing in combinations of all of sizes (if the product has some, but may be about 20 sizes)
Comment: @MetaPakistani continue of message: and ALL of this with combinations of tags. Now you know, why caching the count of products is not possible? It may be 20B of rows. It'll takes me two month to come again to update first product.
Answer:
Try to make separate caches for all types of filtering. For example:

$tagProductIds = $yourCachingSystem->getAllIdsByTag($_POST['tag']);
$sizeProductIds = $yourCachingSystem->getAllIdsBySize($_POST['size']);
$categoryProductIds = $yourCachingSystem->getAllIdsByCategory($_POST['category']);

//...other filters by the product table

$neededProductIds = array_intersect($tagProductIds, $sizeProductIds, $categoryProductIds
//...other filtered ids
);

return $yourOrm->fetchAll(" ... product.id IN ($neededProductIds)");

You can create MySQL tables using the MEMORY engine. These tables are stored in the RAM and maybe this will speed up the extraction of data.

CREATE TABLE if not exists  `products_tmp`
(
   //cols and indexes
) ENGINE = MEMORY
SELECT * products; //tags, sizes

Comment: 1. Interesting solution. I will try.
2. Don't understand. Do you mean to use in comb. with option nr. 1 or it's the second option. Will the result 100% or just "what memory remember"?
Comment: The second solution is an alternative one. Create copies of tables on the MEMORY engine and select from them.
But you will need to keep the tables in RAM up to date. If you are updating "products", you should also update the products_tmp. After rebooting the server, the tables will also have to be recreated.
Comment: OH MY GOD! The same but wrote as opt. 1 is 0,3s!!! Thank you so much for this different view of problem. :)
Comment: You're welcome:) You may also need to warmup the cache. To do this, you can use CRON with:
foreach($tags as $tag) {
$yourCachingSystem->getAllIdsByTag($tag);
}


Superscript notation inverse block matrix.

Question: Is it conventional to use superscript notation to denote the inverse of a block matrix. The context is the quadratic expression in the exponential of a multivariate Gaussian probability density distribution:
$$-\frac{1}{2}({\bf X - \mu})^T\, \Sigma^{-1}\, ({\bf X - \mu})$$
The covariance matrix $\Sigma$ is a block matrix:
$$\Sigma = \begin{bmatrix} \Sigma_{11} & \Sigma_{12} \\ \Sigma_{21} & \Sigma_{22} \end{bmatrix}$$
The question is how accepted or conventional is it to express
$$\Sigma^{\color{red}{-1}} = \begin{bmatrix} \Sigma^{\color{red}{11}} & \Sigma^{\color{red}{12}} \\ \Sigma^{\color{red}{21}} & \Sigma^{\color{red}{22}} \end{bmatrix}$$
?
Equivalently, I guess I could be asking about common notation for the precision matrix.
Answer: I have never seen superscripts to denote blocks (or elements) of the inverse matrix.  This does not indicate that it has never been used.
Comment: Check [this](http://fourier.eng.hmc.edu/e161/lectures/gaussianprocess/node7.html).


What is rhythmic counterpoint?

Question: Apparently, poly-meter creates "rhythmic" counterpoint. What does this mean? Nothing online shows anything. What are other effects of poly-meter?
Answer:
This post comes in three parts:
1) basics
2) techniques
3) examples

Rhythmic counterpoint basics
Rhythmic counterpoint requires one of two conditions:

Pulse onsets occur at different times,
Pulse onsets occur at different intensities.

Example of condition 1
X:1
T:Rhythmic Counterpoint
T:condition 1 example
K:none
M:C
V:P1 K:none clef=perc stafflines=1
V:P2 K:none clef=perc stafflines=1
L:1/4
[V:P1]BzBz :|]
[V:P2]zBzB :|]

Example of condition 2
X:1
T:Rhythmic Counterpoint
T:condition 2 example
K:none
M:C
V:P1 K:none clef=perc stafflines=1
V:P2 K:none clef=perc stafflines=1
L:1/4
[V:P1]"^>"BB"^>"BB :|]
[V:P2]B"^>"BB"^>"B :|]

Rhythmic counterpoint techniques
Polyrhythm
In polyrhythm, two or more concurrent rhythms share the same underlying pulse, but in contrasting subdivisions that don't obviously relate to each other. Polyrhythm satisfies condition 1.
X:1
T:Rhythmic Counterpoint
T:Polyrhythm
K:none
M:C
V:P1 K:none clef=perc stafflines=1
V:P2 K:none clef=perc stafflines=1
L:1/16
[V:P1] (3B2B2B2 (3B2B2B2 (3B2B2B2 (3B2B2B2 :|]
[V:P2] (5BBBBB  (5BBBBB (5BBBBB (5BBBBB :|]

Polymeter
Meter is the presence of "regularly occurring patterns and accents" (Source: Wikipedia). In polymeter, two or more such "regularly occurring patterns and accents" are present simultaneously. Because they share a basic pulse, but have different groupings of strong and weak beats, polymetric music satisfies condition 2.
One must be careful, however, in choosing the meters. If they coincide too often, the sense of polymeter is lost.
Example of ineffective polymeter
This will just sound like 2/4 time.
X:1
T:Rhythmic Counterpoint
T:ineffective polymeter
K:none
V:P1 K:none clef=perc stafflines=1
V:P2 K:none clef=perc stafflines=1
L:1/4
[V:P1][M:2/4]"^>"BBBB | "^>"BBBB :|]
[V:P2][M:4/4]"^>"BB | "^>"BB | "^>"BB | "^>"BB :|]

Example of effective polymeter
Here, the strong pulses of all three "voices" coincide only once every 30 pulses.
X:1
T:Rhythmic Counterpoint
T:effective polymeter
K:none
V:P1 K:none clef=perc stafflines=1
V:P2 K:none clef=perc stafflines=1
V:P3 K:none clef=perc stafflines=1
L:1/4
[V:P1][M:2/4]"^>"BB | "^>"BB  | "^>"BB | "^>"BB | "^>"BB | "^>"BB | "^>"BB | "^>"BB | "^>"BB | "^>"BB | "^>"BB | "^>"BB | "^>"BB | "^>"BB | "^>"BB  :|]
[V:P2][M:3/4]"^>"BBB | "^>"BBB | "^>"BBB | "^>"BBB | "^>"BBB | "^>"BBB | "^>"BBB | "^>"BBB | "^>"BBB | "^>"BBB :|]
[V:P3][M:5/4]| "^>"BBBBB  | "^>"BBBBB | "^>"BBBBB | "^>"BBBBB | "^>"BBBBB | "^>"BBBBB :|]

Phasing
In phase music, two or more instruments play a single rhythm but with one instrument remaining in exact time while the others introduce gradual delays. This also creates a form of rhythmic counterpoint in which the rhythms are sometimes perceived as entirely separate and at other times as forming a single composite rhythm.
Example of phase music
See musical example, below.
Rhythmic tiling / Rhythmic canons
Rhythmic tiling is a mathematical composition technique by which non-overlapping rhythmic patterns fill a metrical space. A rhythmic canon accomplishes this with only a single, non-trivial rhythm, distributed among pats. The mathematics behind the technique were first developed by Dan Tudor Vuza1 and figure prominently in the music of Tom Johnson.
Example of rhythmic tiling
Derived from Tom Johnson's "Tilework for String Quartet" (see video below).
X:1
T:Rhythmic Counterpoint
T:tiling rhythmic canon
K:none
M:none
V:P1 K:none clef=perc stafflines=1
V:P2 K:none clef=perc stafflines=1
V:P3 K:none clef=perc stafflines=1
V:P4 K:none clef=perc stafflines=1
L:1/8
[V:P1] BBzBBBzzB
[V:P2] xxxxxxBBzBBBzzB
[V:P3] xxxxxxxxxxxxBBzBBBzzB
[V:P4] xxxxxxxxxxxxxxxxxxBBzBBBzzB

Rhythmic counterpoint examples
Polyrhythm

Polymeter
The Cars's "Touch and Go" (opening section: 5/4 bass/drums; 4/4 vocals/keybaord)

Phasing
Steve Reich's "Clapping Music"

Tiling
Tom Johnson's "Tilework for String Quartet" (includes composer discussion)

1Vuza, Dan Tudor. "Supplementary Sets and Regular Complementary Unending Canons (Part One)." Perspectives of New Music 29, no. 2 (1991): 22-49. Accessed October 9, 2020. doi:10.2307/833429; Vuza, Dan Tudor. "Supplementary Sets and Regular Complementary Unending Canons (Part Two)." Perspectives of New Music 30, no. 1 (1992): 184-207. Accessed October 9, 2020. doi:10.2307/833290; Vuza, Dan Tudor. "Supplementary Sets and Regular Complementary Unending Canons (Part Three)." Perspectives of New Music 30, no. 2 (1992): 102-24. Accessed October 9, 2020. doi:10.2307/3090628; Vuza, Dan Tudor. "Supplementary Sets and Regular Complementary Unending Canons (Part Four)." Perspectives of New Music 31, no. 1 (1993): 270-305. Accessed October 9, 2020. doi:10.2307/833054.
Answer: No need to over-think this.   Homophony is when two (or more) musical voices follow the same rhythm.  Counterpoint is when they don't.  The terms are most often used to describe music where pitches as well as rhythms are involved.  But it's an easy leap to the concept of purely rhythmic counterpoint.  And poly-meter - like a 3/4 rhythm being played against a 4/4 one - is pretty well guaranteed to produce this 'rhythmic counterpoint'.
Comment: Isn't "homorhythm" the rhythmic term? Homophony is about harmony.
Answer: I think what you are asking about must be about polyrhythm not polymeter.
Counterpoint literally means "point against point" as in pitch against pitch, or two melodic lines that follow different pitch contours.
But, another way to describe counterpoint is independence of parts. Different rhythms in different parts is an effective way to achieve independence of parts. (IMO it's more effective that pitch difference.)
If you look at the "points" on a grid of a polyrhythm you will see that the points occur independently, meaning that don't happen at the same time between parts...

...notice that the two parts only strike at the same time at the 1st and 13th boxes (at the first beat of each measure.) The other times they strike independently. With the polyrhythm there is a lot of independence of the parts, the independence of the parts creates rhythmic counterpoint.

What is rhythmic counterpoint?


RequestScoped bean destroyed in confirmDialog

Question: I have RequestScoped bean because I'm redirecting the user from dataTable with records to edit page. In this dataTable I have delete buttons:

        <f:setPropertyActionListener value="#{news}" target="#{newsBean.news}" />

And here is the dialog:

    <h:form>

    </h:form>

When newsBean.delete is fired, newsBean not longer exists so I get a lot of ugly validation exceptions. I have other pages like this with ViewScoped beans and there it is working like a charm. Help?
Comment: newsBean will exist but it will be a fresh instance. Please show error log and implementation of newsBean.delete.
Comment: Thats the point! How to maintain the old instance instead of getting new one? Error log will be useless at this point, it's just bunch of validation exceptions due to null news property. The delete method is just calling entityManager.remove(entityManager.merge(news)), not directly of course.
Comment: Change your bean to ViewScope
Comment: Not an option cuz I need it on edit page redirected from the page with dataTable.
Comment: Just now I realized my edit doesn't work either :D. I think I have to stick with SessionScoped in that case. Or maybe there is a better solution?
Answer: A request scoped bean has a lifetime of exactly one HTTP request/response. So retrieving the entire view with the form is already one HTTP request/response. The request scoped bean is trashed by end of the response. When you fire an ajax request on the view, then you're essentially sending a new HTTP request. This will thus create a new request scoped bean which get trashed by end of HTTP response. So every ajax request on the same view get its own request scoped bean instance.
This is not what you want if you need to maintain data related to the view. You need to put the bean in the view scope instead. The bean will live as long as you're interacting with the same view by ajax and return null or void in action listener methods. Note that when you return a String, even if empty, the view will be recreated and thus the view scoped bean will be trashed.
See also:

How to choose the right bean scope?


Formulário HTML e CSS

Question: Estou fazendo um teste e preciso fazer um formulário padrão de "trabalhe conosco", com envio de currículo..
Preciso saber como validar esse formulário e fazer com que ele receba arquivos..
<form>
Nome*:
<input class="nome" type="text">

Email:
<input class="email" type="password">

UF:
<input class="uf">
Cidade:

<input class="cidade" type="text">
Mensagem:
<textarea class="msg" cols="35" rows="8"></textarea>

<input class="bnt_submit" type="submit" value="Enviar">
</form>

Comment: Pesquise sobre o PHPMailer
Comment: Claro.. estou com duvido sobre oque devo usar pra isso.. é Jquery, PHP.. ?
Comment: vc vai precisar de um backend para o caso do upload de arquivo. E para validar vc pode usar desde a validação do html. Eu sugiro que vc tente com js ou com jquery.
Answer: Então, cara. O html e o css vão está na máquina de quem está acessando seu site, ou seja, lá no navegador, podemos dizer que eles estão rodando no cliente. Porém, se você deseja pegar os dados que o cliente está trabalhando você precisa de uma plicação servidor que vai receber estes dados, isso pode ser feito em php, node, python, etc.
Se você está começando a estudar isso agora, aconselho a usar o php, pois a comunidade ainda é a maior. Assim que decidir qual usar, você pode jogar passar as informações do cliente para o servidor usando o atributo action="meuphp.php" da tag form do html. Para pegar os dados nesse arquivo use a variável $_GET["cidade"] por exemplo. O nome dentro do get deve ser o name do seu input.
Para fazer upload com html, use:
<input type="file" name="fileUpload">

Comment: Muitooo obrigada. Tu já me deu um norte bem grande hahaha.
Comment: Qualquer coisa, só perguntar.
Answer:

    Formulario

        Cadastro de DEVs
        Complete suas informações

<form id="form">

    <fieldset class="grupo">

            Nome
            <input type="text" name="nome" id="nome" required>

            Sobrenome
            <input type="text" name="sobrenome" id="sobrenome" required>

    </fieldset>

    <fieldset class="grupo">

            Email
            <input type="email" name="email" id="email" required>

            CPF
            <input type="text" id="identification" required>

    </fieldset>

        Data de Nascimento:
            <input type="date" name="data_nascimento" id="data_nascimento" required>

        De qual lado da aplicação você desenvolve?

            <input type="radio" name="devweb" value="frontend" checked>Front-end

            <input type="radio" name="devweb" value="backend">Back-end

            <input type="radio" name="devweb" value="fullstack">Fullstack

        Senioridade
        <select id="senioridade" required>
            <option selected disabled value="">Selecione</option>
            <option>Junior</option>
            <option>Pleno</option>
            <option>Senior</option>
        </select>

    <fieldset class="grupo">

            Selecione as tecnologias que utiliza:

            <input type="checkbox" id="tecnologia1" name="tecnologias[]" value="HTML" checked>
            HTML
            <input type="checkbox" id="tecnologia2" name="tecnologias[]" value="CSS">
            CSS
            <input type="checkbox" id="tecnologia3" name="tecnologias[]" value="Javascript">
            Javascript
            <input type="checkbox" id="tecnologia4" name="tecnologias[]" value="PHP">
            PHP
            <input type="checkbox" id="tecnologia5" name="tecnologias[]" value="C#">
            C#
            <input type="checkbox" id="tecnologia6" name="tecnologias[]" value="Python">
            Python
            <input type="checkbox" id="tecnologia7" name="tecnologias[]" value="Java">
            Java

    </fieldset>

        Conte um pouco da sua experiência:
        <textarea rows="6" style="width: 26em" id="experiencia" name="experiencia" required></textarea>

    <button class="botao" type="submit" id="submit" onclick="enviar()">Concluído</button>
</form>

//css
/* Todos os elementos da página */

{
margin: 0;
padding: 0;
}

/* Elementos com o ID "titulo" */
#titulo {
font-family: sans-serif;
color: #181717;
margin-left: 7%;
}
/* Elementos com o ID "subtitulo" */
#subtitulo {
font-family: sans-serif;
color: #2e2d2d;
margin-left: 10%;
}
#check{
display: inline-block;
}
/* Elementos de tag */
fieldset {
border: 0;
}
/* Elemento de tag  */
body{
background-image: linear-gradient(to right, rgb(87, 98, 105), rgb(222, 236, 242));
font-family: sans-serif;
font-size: 1em;
color: #131313;
margin-left: 36%;
margin-top: 2%;
justify-content: center;
}
/* Elementos de tags , , ,  e  */
input, select, textarea, button {
font-family: sans-serif;
font-size: 1em;
color: #151516;
border-radius: 5px;
}
/* Elementos de classe "grupo" nos estados das pseudoclasses "before" e "after" */
.grupo:before, .grupo:after {
display: table;
}
/* Elementos de classe "grupo" no estado da pseudoclasse "after" */
.grupo:after {
clear: both;
}
/* Elementos de classe "campo" */
.campo {
margin-bottom: 1em;
}
/* Elementos de classe "campo" de tag  */
.campo label {
margin-bottom: 0.2em;
color: #1c1c1e;
display: block;
}
/* Elementos de classe "campo" ou "grupo" de tag  */
fieldset.grupo .campo {
float:  left;
margin-right: 1em;
}
/* Elementos de classe "campo" das tags  com atributo text e email, da tag  e da tag */
.campo input[type="text"], .campo input[type="email"], .campo select, .campo textarea {
padding: 0.2em;
border: 1px solid #000000;
box-shadow: 2px 2px 2px rgba(255, 251, 251, 0.2);
display: block;
}
/* Elementos de classe "campo" de tag  e */
.campo select option {
padding-right: 1em;
}
/* Elemento de classe "campo" com tag ,  e  tocas com estado da pseudoclasse "focus"*/
.campo input:focus, .campo select:focus, .campo textarea:focus {
background: #ffffff;
}
/* Elemento de classe "botao" */
.botao {
background-image: linear-gradient(to right,rgb(176, 40, 40), rgb(38, 36, 40));
width: 50%;
border: none;
padding: 15px;
color: white;
font-size: 15px;
cursor: pointer;
border-radius: 10px;
}
/* Elemento de classe "botao" com o estado da pseudoclasse "hover" */
.botao:hover {
background: #89888a;
box-shadow: inset 2px 2px 2px rgba(0,0,0,0.2);
text-shadow: none;
}
/* Elementos de classe botão e de tag  */
.botao, select{
cursor: pointer;
}
................
//js
document.getElementById('identification').addEventListener('input', function (e) {
let x = e.target.value.replace(/\D/g, '').match(/(\d{0,2})(\d{0,3})(\d{0,3})(\d{0,4})(\d{0,2})/);
e.target.value = !x[2] ? x[1] : x[1] + '.' + x[2] + (x[3] ? '.' : '') + x[3] + (x[4] ? '/' : x[4]) + x[4] + (x[5] ? '-' + x[5] : '');
if (e.target.value.length < 15) {
x = e.target.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,3})(\d{0,2})/);
e.target.value = !x[2] ? x[1] : x[1] + '.' + x[2] + (x[3] ? '.' : '') + x[3] + (x[4] ? '-' + x[4] : '');
}
console.log('formatação: ' + e.target.value);
});
Comment: //head

Formulário HTML e CSS


Plotting greatest integer function II

Question: I am confused on how to plot $f(x)=\frac{1}{\lfloor1/x\rfloor}$ where $\lfloor x\rfloor$ is the greatest integer function.
This is how I started: For $0<x<1$, $1<1/x<\infty$ and then I do not know what to do.
Comment: From $\epsilon$ to $1$ since you have a problem when $x>1$.
Answer: Hints: Try breaking your function down into "smaller pieces".
If you have a general graph $y = g(x)$, do you have an idea what the graph $y = \lfloor g(x) \rfloor$ looks like? If not, draw a "typical" differentiable function $g$ on a sheet of lined paper, think of the lines as integer values, and use them to graph $y = \lfloor g(x) \rfloor$. :)
Now you should be able to graph $y = \lfloor 1/x \rfloor$ with no trouble. The final step is to graph the reciprocal, whose height at each point is your $f(x)$. This should be straightforward. (As Claude Leibovici notes, you'll need to consider which points are in the domain of $f$.)

Plotting greatest integer function II


Do weighted keys on a keyboard lead to more expressive playing?

Question: I use an acoustic piano to learn/play classical music. I use a midi keyboard to record/produce own music. My piano has weighted keys while my midi keyboard has a very light touch. I find that I am able to play more expressively with my piano.
I would like to know if this is purely because of familiarity, or do the weighted keys offer more control. I do not know which of the two paths to take: practice more on the midi keyboard to gain familiarity with the light keys OR get a new midi keyboard with weighted keys.
Comment: Professional piano players will try dozens or hundreds of pianos before selecting one to purchase, or even for a specific concert. Even though they are all acoustic pianos with weighted keys, they find that their ability to express the material can be different even between two of the same model of piano. Weighted keys may be part of the solution for you, personally, to express the music the way you prefer, but it might not be. There is no silver bullet - you will serve yourself best by trying a dozen or more keyboards with and without weighted keys and find which hits your sweet spot.
Comment: It very likely also has to do with the _sounds_ you use with the MIDI keyboard. Modelling an acoustic piano well is still not a solved problem; even if your playing itself is very expressive on the keyboard it will likely not _sound_ as expressive as the same playing on the acoustic piano, certainly not if you don't use a high-quality sound module or plugin.
Answer: Weighted keys offer a different kind of response to the touch of a finger since they have more stationary momentum. This helps connect your physical action to the sound itself, which results in what seems like more expressive piano playing.
The other thing you are experiencing is the difference between velocity control for either instrument. If both the MIDI keyboard and the acoustic piano had identical resolutions for velocity, then it would be theoretically possible to play each instrument with the same expression though it would be much harder to train yourself to do so on the MIDI keyboard (for the first reason mentioned). However, they do NOT have identical resolutions! The MIDI keyboard has 128 different levels of velocity it can communicate to the synthesizer module, while the acoustic piano has specificity down to the quantum level.
Lastly, non-weighted keys make more sense for different kinds of playing. If you are controlling an organ or synthesizer lead, non-weighted keys are going to be easier to play since those sounds can be very rhythmic or make use of glissando in a different way. But for piano playing, where velocity control and expression is much more important, an acoustic piano or high-quality fully weighted keyboard is preferable. If you're recording/producing acoustic piano music, then yes, a fully weighted keyboard will probably benefit you. If you're recording and producing organ sounds or synth parts, you should be fine with the non-weighted keyboard you have.
Comment: I don't agree with the velocity control being a limiting factor. 128 levels is a _lot_, and I haven't been able to reliably distinguish between a level of, for example, 100 and 101.
Comment: @Babu Whether you notice it or not, it's still true. The MIDI keyboard is not going to have individual samples for every velocity increment either, everything is a compromise. There are subtle ways the acceleration of the hammer can affect the sound differently from the basic velocity as well; that has yet to be replicated digitally.
Comment: I agree with every word you've said (especially your advice on when to use a weighted keyboard), but I don't agree that the velocity effect you're mentioning will be noticeable when comparing a good soundfont and a real piano. There are certainly edge cases where there is no substitute for a real instrument. But for most purposes, I don't think that there is a practical difference.
Comment: The acoustic piano will have limitations too.  It takes a great deal of effort to regulate the action and voicing so that E responds exactly as F does, and it doesn't take long to get out of regulation.  I doubt that you can play E and F and get them within 1% of each other on a typical acoustic piano.
Comment: @MarkLutton True, but that organic nature can also be grouped under expression (see also "Why music snobs prefer acoustic instruments over synthesized ones"). By the same token, won't you have the same problem with regulating the pressure sensors and solenoids of a MIDI controller?
Answer: I played a semi-weighted MIDI keyboard for years, and usually play piano and organ sounds.
When my keyboard failed, I replaced it with a hammer action one and boy, was there a difference in what I heard from Piano synths.
The playing had so much more dynamics, and it was an audible difference. Even though the weighted keys are supposed to be harder to play, I actually found that it was harder and needed more effort and force to play loud sounds with the non-weighted keyboard, which is of good quality brand and make.
Also, besides the momentum mentioned, I notice by measuring that the keys of the Piano type weighted keys were longer by half an inch than the non-weighted and also maybe about 1 millimeter wider, so there is also a travel distance to consider. It is not the same to cram 128 values into a X distance, than into Y distance travelled if Y is larger than X. You immediately get more expression room.
I mention that on the first keyboard only a few keys failed, and so this comparison was done with both keyboard playing the same MIDI channel and the same exact patch and synth, with both connected and placed side by side.
I think is something similar to compressing audio. You compress audio, and you loose dynamics.
I even like the hammer action when playing B3 Hammond clones. One of them does respond to velocity sensing, another responds by making certain clicks and effects in accordance to velocity...So there IS expression there to be had too.
So if expression is dynamics, there is a definitive real, measurable difference in the distance travelled, where the 128 values are to be rendered.
In my opinion, and I have had various MIDI keyboards, and had to fix some and discard others, the best is yet to come when they stop using the silicon bubble switches to detect "velocity", and start using optical sensors.
I also would mention that by plain attention to the issue, we should realize that the velocity with which we play is not constant, but rather is variable, meaning that when we strike the key we can strike fast and modulate to soft and vice-versa. This is very difficult to formulate with only a starting time and ending time, as is currently done. So, a real piano, is way a difference in expression, and even more so in actual sound production, when compared to any computerized rendering, and hearing is the feedback to the pianist and is used to modulate the expression. We are fortunate to have the current technologies, though.
Answer: If a piano key has inertia, varying the amount of force with which keys are played will vary the rate at which they move.  A player need not try to "hold back" his fingers from pressing keys too quickly; if the player only applies a light pressure, the keys simply won't move as fast as if a heavier pressure was applied.
If a key has no inertia, then pressure and velocity will be essentially independent.  Until a key hits bottom, the player will have no control over pressure; once it hits bottom, there won't be any velocity.  A keyboard could have separate axes of control for the velocity with which the key hits the bottom and the pressure with which it is driven at that point, but it's hard for a person to control the speed at which fingers are moving without being able to regulate the pressure, or to control the amount of pressure that will be placed upon keys at the moment they hit bottom.  Having an established the relationship between pressure and velocity makes it easier for the player to control the loudness with which keys will play.
Answer: There can be the danger of playing too fast on an unweighted keyboard and it all becoming a bit of a scramble I find. Having said that I also find that some 'weighted' or 'hammer action' keyboards on digital pianos or master keyboards can be too heavy. Many acoustic pianos (especially grands) have quite a light action actually if you try them (although not as light as an unweighted plastic synth. keyboard!). I tried a Pleyel grand piano once (19th century) and one of the makes favoured by Chopin and it had a very light action (like a synth). Even a 9'6" 97 note Bosendorfer grand has quite a light action. Steinways can be a bit heavier, but they vary a lot. However there is a lot more to it than that, things like escapement for example. It all depends on what you want to do with the keyboard. I think you'd definitely find it difficult to get the level of expression and control out of an unweighted keyboard if you want to play some serious classical music, and don't even think about practising said music on an unweighted keyboard and then doing a performance on an unfamiliar acoustic piano!!! The other way round is not so difficult (maybe) although you'd probably play a lot of bum notes. If you play a lot on an acoustic you build up strength in your fingers I think and you've probably got more chance of controlling whatever is thrown at you than the average man in the street. Try some keyboards and find what works best for you. If you play piano and organ sounds for example then maybe a semi-weighted keyboard would be a good compromise, whereas if you play mainly piano sounds go for the keyboard that best feels like an acoustic piano as long as it doesn't break your back trying to lift it. Any opinions? or am I talking a load of nonsense?
Answer: There's no conclusive answer to this question.  But many players find that some "resistance" helps them to play more accurately, more evenly, even perhaps faster!    We can compare this to a wind instrument which, while it needs to be "free-blowing" also maut offer some resistance, some thing for the player to "work against".
As a sidenote, I've had to replace key contacts and even the complete keybed  more often on my weighted keyboards than on my synth-type ones.  You play harder, you cause more wear.
Answer: Any musician worth their salt can play just as flawlessly on a non weighted keyboard as they can a weighted one, I know because I've been playing piano on both types of keyboards for over 25 years, weighted keys are a marketing gimmick that makes people THINK they're playing with more expression when in actuality, all you need for expressive playing are velocity sensitive keys, pianowise, my yamaha dgx 230 does just as good a job as my p250


get a specific value within a html tag in a file

Question: i have a text file with the following content
<?xml version="1.0" encoding="UTF-8"?> <slave> <name>slave1</name> <description>00.000.000.00</description> <remoteFS>/home/<dir>/</remoteFS> <numExecutors>8</numExecutors> <mode>NORMAL</mode> <retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/> <launcher class="hudson.plugins.sshslaves.SSHLauncher" plugin="email@example.com"> <host>00.000.000.00</host> <port>9192</port> <credentialsId>xxxxx-xxxx-xxxxxx</credentialsId> <javaPath>/usr/bin/java</javaPath> <maxNumRetries>0</maxNumRetries> <retryWaitTime>0</retryWaitTime> <sshHostKeyVerificationStrategy class="hudson.plugins.sshslaves.verifiers.NonVerifyingKeyVerificationStrategy`"/> </launcher> xxxxx <nodeProperties> <hudson.slaves.EnvironmentVariablesNodeProperty> <envVars serialization="custom"> <unserializable-parents/> <tree-map> <default> <comparator class="hudson.util.CaseInsensitiveComparator"/> </default> <int>4</int> <string>CTS_HOME</string> <string>xxxx</string> <string>xxxxx</string> <string>xxxxx</string> <string>PYTHONPATH</string> <string>/home/<dir></string></tree-map> </envVars> </hudson.slaves.EnvironmentVariablesNodeProperty> </nodeProperties> </slave>`

i want the value <launcher class="hudson.plugins.sshslaves.SSHLauncher" from this whole file, but i am unable to get this value
Also hudson.plugins.sshslaves.SSHLaunchervalue is different for different launch method the jenkins slave uses
How can i get only the launcher class value?
Here is what i have tried so far,
cat text_file | sed -nr 's/.*launcher="([^"]+)".*/\1/p'
cat text_file | sed -n 's:.*<launcher>\(.*\)</launcher>.*:\1:p'
cat text_file | grep -o '<launcher>.*</launcher>'

but none of these 3 work.
can someone help me out here?
Answer: Here it is :
sed -n 's:.*<launcher class="\(.*\)" plugin=".*">.*</launcher>.*:\1:p' text_file

It should output :
hudson.plugins.sshslaves.SSHLauncher

Comment: no i can get the other details...i just need this value SSHLauncher from the file....the value of launcher class field from the file
Comment: Please explain what output you want
Comment: i just want this value ""hudson.plugins.sshslaves.SSHLauncher" from the text file..i have a lot of text files whih have different values from launcher class...so i just need the value of the launcher class...which is hudson.plugins.sshslaves.SSHLauncher in this particular case
Comment: Nice to hear. If it solves your problem don't forget to `plus` and mark my post as `answer`
Comment: Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/183504/discussion-between-poobear-and-andre-ds).


PCA: How to get PC2 and PC3 scores?

Question: How I can get the score of PC2 and PC3 (Dim2 and Dim3)? I run this code which generated a graph with only PC1 and PC2 scores.
library("FactoMineR")
library("factoextra")
mydata<- read.csv("mussels.csv", TRUE, ",")
mydata[is.na(mydata)]=0
attach(mydata)
X=cbind (As, Co, Cr, Cu, Mn, Mo, Ni, Pb, Zn)
summary(X)
cor(X)

res.pca <- princomp(X, scores=TRUE, cor=TRUE)
summary(res.pca)

fviz_pca_var(res.pca, col.var="contrib",
         gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
         repel = TRUE # Avoid text overlapping
)

Comment: Dear Nick Cox, please kindly note, I am a fisheries biologist and we usually don't have a good command on programming. For us finding PC3 and PC4 scores without an expert helps is really impossible.
Comment: The point is simply is that this is off-topic here. For similar questions you are really are better off trying a forum that supports questions about R code. (I am not a statistician either.)
Answer: Unfortunately, I do not have your data to work with. I'll solve your problem using iris dataset:
library("FactoMineR")
library("factoextra")

res.pca <- princomp(iris[, 1:4], scores=TRUE, cor=TRUE)
summary(res.pca)

fviz_pca_var(res.pca, col.var="contrib",
             gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
             repel = TRUE, # Avoid text overlapping
             axes = c(2, 3) # choose PCs to plot
)

Notice that I just used axes = c(2, 3) argument inside fviz_pca_var function in order to plot the principal components I want.

PCA: How to get PC2 and PC3 scores?


Updating a table using JOIN

Question: I'm trying to compose an SQL statement but keep getting errors...
Here is my situation:
I have a table with sales orders and a table with item transfers.
The sales orders have an order number and an extension, where the ID itself might not be unique, but the combination of order number and extension is. The extension can be null.
The item transfer table has a reference number and sometimes a sales order number plus extension, but not always.
The reason is that sometimes items are transferred for a sales order, sometimes for other reasons. Also, a sales order can happen without the item being transferred first. One order can only have one transfer though, and vice versa.
I added a field "transref" to the sales order table so an order can be connected to a transfer, if applicable. (This info can't be computed on-the-fly for performance reasons.) So my tables now look like this (they are actually bigger but this is the important info):
SALESORDERS
ORDERNO ORDEXT TRANSREF
1       (null) (null)
2       (null) (null)
2       a      (null)
3       (null) (null)

TRANSFERS
TRANSREF ORDERNO ORDEXT
t1       1       (null)
t2       (null)  (null)
t3       2       a

Now I need to get the transref code into the sales orders table so that it looks like this:
SALESORDERS
ORDERNO ORDEXT TRANSREF
1       (null) t1
2       (null) (null)
2       a      t3
3       (null) (null)

I tried all kinds of statements, e.g.
UPDATE SALESORDERS
INNER JOIN TRANSFERS
ON SALESORDERS.ORDERNO = TRANSFERS.ORDERNO and (SALESORDERS.ORDEXT = TRANSFERS.ORDEXT or (SALESORDERS.ORDEXT is null and TRANSFERS.ORDEXT is null))
SET SALESORDERS.TRANSREF = TRANSFERS.TRANSREF
WHERE TRANSFERS.ORDERNO IS NOT NULL

but nothing worked so far. Can someone help me untie the knot I got in my brain after trying a dozen tutorials and answers for this?
Comment: *not working so far* is not a valid error message in any DBMS I have used.
Comment: a) what do you mean "nothing worked", b) what database?
Comment: *This info can't be computed on-the-fly for performance reasons* Either way you have to do a join, I don't see the need for the `TRANSREF` field in `SALESORDERS`.
Comment: I may agree with @RedFilter, what is wrong with just getting the `TRANSREF` when you select the data, why do you need to store it again in the `SALESORDERS` table?
Comment: Sorry I forgot to mention I'm working on an AS400/DB2 database.

It would need a really long explanation why I need to do it this way and I don't like it either but I can't help it. :(
Answer: Since you've called it an AS/400 several times, I'm going to assume you're on an old version of the operating system.  You probably want a correlated subselect.  Something like:
update salesorders o
set transref = (select t.transref
  from transfers t
  where o.orderno = t.orderno
    and (o.ordext = t.ordext or (t.ordext=null and o.ordext=null))
    and t.transref <> null)
where ordext = null;

Comment: This worked perfectly, only the t.transref in the second to last line should be t.orderno and the system complained about the = before a null (should be "is"), but that was easy to fix. Thank you so much!
Comment: I don't care how many name iterations the platform goes through, I'll still call it an AS/400. :-P
Answer: The syntax for this depends entirely on your variety of SQL
For instance, this may work (SQL Server)
UPDATE SALESORDERS
SET SALESORDERS.TRANSREF = TRANSFERS.TRANSREF
FROM
SALESORDERS
INNER JOIN TRANSFERS
ON SALESORDERS.ORDERNO = TRANSFERS.ORDERNO and (SALESORDERS.ORDEXT = TRANSFERS.ORDEXT or (SALESORDERS.ORDEXT is null and TRANSFERS.ORDEXT is null))
WHERE TRANSFERS.ORDERNO IS NOT NULL

Comment: Thank you for your quick reply. I get the error message that TRANSFERS is not defined in this context.

I forgot to mention I'm working on an AS400/DB2 database, by the way.
Comment: This approach won't work in DB2.  In DB2 you need to use `MERGE`.
Answer: You are having this problem because DB2 doesn't allow you to use a JOIN with a simple UPDATE statement (one of its many seemingly arbitrary restrictions).
The best way to do this in DB2 is to use MERGE.  Something like this should work:
merge into salesorders
    using transfers
    on transfers.orderno = salesorders.orderno and (
           transfers.ordtext = salesorders.ordtext or (
               transfers.ordtext is null and
               salesorders.ordtext is null
           )
       )
    when matched then update set
        salesorders.transref = transfers.transref;

Comment: On the AS/400 (iSeries), I'm pretty sure the MERGE SQL command is not supported.  AS/400's don't get all of the SQL commands that other DB2 databases get.
Comment: @Tracy, ok, I didn't see the comment mentioning AS/400 at the time.
Answer: MERGE works fine, either embedded in SQLRPGLE or with interactive STRSQL.
Comment: That depends entirely on the version of DB2 he has - `MERGE` wasn't available until V7R1, which may not have been what he was working with.

Updating a table using JOIN


Proper Forcing and Sequence of Names for Reals.

Question: I read something that seems to suggest the following is true:
If $\mathbb{P}$ is a proper forcing, $|\mathbb{P}| = \aleph_1$, and $\mathsf{CH}$ holds, then there exists a sequence $\{(p_\xi, \tau_\xi) : \xi < \omega_1\}$ with $p_\alpha \in \mathbb{P}$ and $\tau_\xi$ a $\mathbb{P}$-name such that for all $p \in \mathbb{P}$ and names $\tau$, if $p \Vdash \tau \in 2^\omega$, then there exists some $\xi < \omega_1$ with $p_\xi \leq p$ and $p_\xi \Vdash \tau = \tau_\xi$.
Is statement indeed true? If so, can someone provide a reference or brief sketch of the proof.
I believe the above should imply that if the ground model satisfy $\mathsf{CH}$, then $\mathsf{CH}$ remains true in a generic extension by a $\aleph_1$ size proper forcing.
Thanks.
Comment: Could you perhaps give some details as to what suggested this to you?
Answer: This was answered positively by Komjath here under the weaker assumption that $P$ preserves $\omega_1$.
Comment: You mean that $|\Bbb P|=\aleph_1$ and that it preserves $\omega_1$, right?
Comment: Yes. Otherwise this is false.
Comment: Of course. I just wanted to make sure which assumption was weakened (just the properness, not all of them). Side effects of being tired and whatnot.


Copy multiple ranges with VBA

Question: I am trying to copy multiple ranges using Excel VBA. I understand that in order to select multiple ranges, syntax similar to that below is used:
Range("A1:B4000, F1:F4000").Select

This works fine in selecting the appropriate range. However, the following:
Range("A1:B4000, F1:F4000").Copy

...only copies the A1:B4000 range. This is the first problem I am facing.
Secondly, I would like to dynamically copy the data to the bottom row, which is not necessarily row #4000. If selecting a single range, the syntax is as follows:
Range("A1", Range("B1").End(xlDown)).Copy

The above code successfully copies everything from A1 to the bottom of the B column. I can't find any material on the net explaining how to do this for multiple selections.
What I'm essentially trying to do is copy A1:B(bottom) and F1:F(bottom), but the above two issues are stopping me. I assume this is a syntax issue..?
Comment: Can you just do a loop and copy and paste twice (so copy and paste the first range and then copy and paste the second range)?  It seems that since you are using VBA, you are adding extra complexity by trying to do it all in one step.
Comment: Yep, I could do that - that's my current workaround. I just hate workarounds :P
Comment: I just used your code and it worked fine for me (it copied the three columns and pasted them side by side below).  What version of Excel are you on?
Comment: Have a look at `Range("A1").CurrentRegion`.  That's the easiest path to dynamic ranges, if your data meets the requirements.
Answer: Use the "Union" method.
Dim range1 as Range, range2 as Range, multipleRangeAs Range
Set range1 = Sheets("Sheet1").Range("A1:B4000")
Set range2 = Sheets("Sheet1").Range("F1:F4000")
Set multipleRange= Union(range1, range2)

Then you can mess around with mutipleRange as per normal.
Comment: I would just adjust the following, since the OP asked for dynamic range names, `Set range1 = Range("A1:B" & Range("B" & Rows.Count).End(xlUp).Row)` to get the real last cell in column B. Do the same for column F as well.
Answer: @Scott Holtzman provided the solution in a comment:

I would just adjust the following, since the OP asked for dynamic
  range names, Set range1 = Range("A1:B" & Range("B" &
  Rows.Count).End(xlUp).Row) to get the real last cell in column B. Do
  the same for column F as well

Copy multiple ranges with VBA


How to access field in view template?

Question: I am trying to access from views-view-field--title.tpl template to another field...
I have this code:
<?php print $output;
  print $row->{$view->field['field_NAME']->field_alias};
 ?>

But it shows me just a number.. (1,2,3,4,5,....)
Can someone help me?
Thank you!
Answer: I'd suggest that you enable the Devel module on your drupal site (hopefully not a production version ;-).  Once you've enabled that module, you can use the dsm() function, within php tags in your templates to inspect in detail the variables that are provided in each template!
So enable the Devel module, then add the following to your template file:
<?php dsm($view->field['field_NAME']); ?>

Clear your cache and go to a page that contains a view... What the dsm() function should do is output your object in the 'Help' section of your page:

Just click on the object and start inspecting all the fields it has available.  You'll see that what it's returning with the 'field_alias' property is just the nid of that node...
Since you didn't specify what you're trying to get with the additional field, I can't be any more specific, but hopefully digging around will let you figure out how to get to the field property/properties you need.  Let us know if you figure it out!
p.s.  Since the 'title' field template is called for each row displayed in your view, you will get that 'field' object multiple times - once for each time the template was called.
Comment: Thank you very much! Working. Here is the code if someone need it: print $row->_field_data['nid']['entity']->field_NAME['und'][0]['value'];
Answer: I had the exact same problem, I inspected the $row variable using this
foreach ($row as $key => $value)
{
   print $key;
   print " : ";
   print $value;
   print "
";
}

until I had this
foreach ($row->field_field_link_text[0]["rendered"] as $key => $value)
{
   print $key;
   print " : ";
   print $value;
   print "
";
}

Which finally gave me the answer I was looking for:
$row->field_field_link_text[0]["rendered"]["#markup"]

Answer: I wish I had known about this before :-)

How to access field in view template?


Qual o significado de do erro 406?

Question:
Not Acceptable
An appropriate representation of the requested resource
  /aa/bb/cc.php could not be found on
  this server.
Additionally, a 404 Not Found error was encountered while trying to
  use an ErrorDocument to handle the request.

Recebendo este erro, o que remete?
Entendo que a página está negando acesso aos recursos, mas quais poderiam ser os motivos para isto correr?
Answer: É um problema de content type. Provavelmente a requisição ou resposta está usando um mime-type que o servidor ou o cliente não pode manipular. Também pode ser um charset ou encoding inválido. Ainda pode ser uma língua inválida ou o tamanho do recurso. Provavelmente um dos dois lados está mal configurado. O mais provável é que esteja recebendo isto em algum cliente específico que não está mandando a requisição corretamente.
Como não há detalhes, só dá para responder genericamente.
Coloquei no GitHub para referência futura.
Comment: Para acrescentar afim de ajudar futuras consultas, eu adicionei a seguinte linha e me ajudou a resolver também, `curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);`
Comment: Faz sentido....
Comment: estava a enviar a requisição através do seguinte formato: `http://www.dominio.com.br/subdominio/arquivo.php`, e dava o erro 406, alterei para `http://www.subdominio.dominio.com.br/arquivo.php` e funcionou, existe alguma explicação? Posso acessar normalmente o arquivo da primeira maneira, mas ao tentar enviar uma requisição com cURL da primeira maneira não parece funcionar, apenas no formato anterior( e de fato, é um subdominio que está hospedado o arquivo).
Comment: Só com estas informações é difícil explicar. Mas é comum dar esse tipo de erro usado um cliente que não seja um navegador. O programador sempre esquece de fazer alguma coisa.
Answer: Tive o mesmo problema mas com o erro HTTP 406 em uma requisição com cURL na linguagem PHP, consegui solucionar acrescentando o CURLOPT_USERAGENT.
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

Qual o significado de do erro 406?


Why does Facebook use PHP instead of ASP.NET MVC?

Question: In every comparison between these two languages, ASP is recommended for "serious" web projects, so why does Facebook use PHP? PHP can't hold persistent database connections and in case of Facebook, I think this would slow down the application. Or am I wrong?
For example: Speed of code execution: ASP.NET-MVC versus PHP
I found that they use PHP because Mark Zuckerberg developed the first version of Facebook in PHP and a change would cost to much afford and money. But assumed Facebook started today, would it be intelligent to use ASP.NET instead of PHP?
Comment: For what it's worth, the Stack Overflow community tends to discourage language wars, since they are rarely useful. Speed is only one factor when choosing a language - large organisations need to consider how expensive hiring is for a specific skillset, what works with their current stack, what the security implications are of a language, whether a language works with their development culture, etc. So, "Facebook use PHP because it works for them", maybe?
Comment: This answer may be useful for you: http://programmers.stackexchange.com/questions/55091/why-did-facebook-use-c-beside-php
Comment: Why ASP.NET? Why not RoR, Java, Python, Erlang, C++ or whatever else? Your question invites pure speculation. (And Facebook has enough resources to build their own PHP compiler and VM. They're not exactly your typical PHP user.)
Comment: But assumed Facebook started today, would it be intelligent to use ASP.NET instead of PHP? Still this question is unanswered..
Comment: Mat, your right, RoR would also be an great alternative to PHP. I'll edit the Question.
Comment: 1. In every comparison between these two languages, ASP is recommended for "serious" web projects
A: PHP is built for web! You can definetelly use PHP for "serious" web projects.

2. PHP can't hold persistent database connections
A: Of course it can. Where did you get that from?

3. Or am I wrong?
A: Yes. You are wrong.
Comment: Why is this question opinion-based? There has to be specific reasons why PHP was chosen by Facebook devs right?
Answer: Because the original version of Facebook was an open source project.
Facebook project was one of Mark Zuckerberg's university assignments, and he had to do it with an open source project.
Except asp.net, other web programming languages are hard to learn or not fast enough.
If you compare PHP with other web programming languages (as I said except asp.net) it's more reasonable.
And as you said if he want to switch to Asp.net it have a lot of cost for Facebook.
Comment: @halfer as you say Facebook organisation do open source thing , but what you mean about their main product isn't proprietary code?
Comment: No , as i said First of facebook project was completly open source, and as you say we cant say that it fully open source now , but if you refer to question he said that why facebook is PHP ?
Comment: Based on your comment, I've added a clarification to your answer.
Comment: @Halfer Thank you very much , you make my answer more clarification
Answer: As far as I know, The creators of facebook knew PHP and not ASP.NET, but I could be wrong here.


How to create statistical reports about data contained in various content types?

Question: I have page in drupal for hockey league. Till now, there was only nodes, some specific content types, simple views, but now, they want to create full statistics for the entire league. I was looking for some modules, but unsuccessfully.
My friends from this league want to type final score of match and system will know who is winner, credit points and calculate any other statistics data for team. I was trying to create something like this with rules, but I failed. I dont know ho to get SUM of fields from one content type, then calculate some value and get it to another content type, filter some values in views and get it to another view for his filtering.
I think that rules, views are insufficient for this. I need help, what way to choose.. trying do this in modelus or best way is to learn module development and create my own module to do this?
Answer: You may want to look at Computed field. You can use PHP to do calculations from information from other fields and show display the result. If you want, you can also save it to databse for use elsewhere. You can also try to do it in Views with Views calc. I think Views would be your better bet.
Comment: Views calc is good, but I need to save this values to database because I sort view by this values. For example: I have content type "team" where I have name of team and number of games, and value for games I want to get from another content type "games" where I want to get number of games played byt this team.. something like this: SELECT COUNT(team) where team = 'THIS TEAM'.


Linear least squares with quadratic equality constraint

Question: I would like to use linear least squares to solve for $x \in \mathbb{R}^5$ where
$$ Ax = b \rightarrow x = (A^TA)^{-1}A^Tb $$
but would like to include the constraint
$$ x_1^2 + x_2^2 = 1 $$
I looked around and found a few examples of how to solve using linear constraints of the form
$$ Cx = d$$
but unsure how to continue with quadratic constraints. Thanks!
Comment: So effectively you are saying you want to minimize $(Ax-b)^T(Ax-b)$ under the constraint $x^Tx=1$.
Comment: @Johan Yes, but I should have mentioned $ x \in \mathbb{R}^5 $. Updated question.
Comment: $x^\top \begin{pmatrix}1&0&0&0&0\\0&1&0&0&0\\0&0&0&0&0\\0&0&0&0&0\\0&0&0&0&0\end{pmatrix}x=1$
Comment: Using Royi's answer https://math.stackexchange.com/a/2402360/125757 should yield a good approach: by relaxing $x^Tx = 1 \to x^Tx \le 1$ and then finding an optimal multiplier for the constraint such that it is tight.
Answer: Quadratic optimization over a single quadratic constraint is a classical problem. One way to address it in a global fashion is to employ a semidefinite relaxation, which can be shown to be tight in this special case (also called a lossless application of the S-procedure)
One reference out of many
http://arxiv.org/abs/1312.1400
Here is some MATLAB reference code to setup and solve the semidefinite relaxation (called moment relaxation sometimes). It assumues you have the modelling toolbox YALMIP installed (disclaimer, developed by me), and a semidefinite solver, such as sedumi, sdpt3, mosek.
<code>A = randn(10,5);
b = rand(10,1);
x = sdpvar(5,1);

p = (A*x-b)'*(A*x-b);
h = 1-x(1)^2-x(2)^2;

[diagnostics,xhat] = solvemoment(h == 0,p)
xhat{1}
</code>
The semidefinite relaxation boils down to a generalized eigenvalue problem in this case, so a general semidefinite programming approach might be a bit of an overkill, but it is convenient and fast enough (~0.1s) unless you have to solve many of these.
Having said that, this problem is also small enough to be easily solved using a standard global nonlinear solver, such as baron, scip or bmibnb in YALMIP.
<code> optimize(h == 0,p,sdpsettings('solver','bmibnb'))
 value(x)
</code>


Alterar o nome de uma tabela no H2 Database Engine

Question: Estou tentando alterar o nome de uma tabela no H2, mas não encontro a sintaxe.
Alguém sabe?
Answer: Descobri a sintaxe:
Exemplo:
<code> ALTER TABLE TEST RENAME TO MY_DATA
</code>
Referência: Manual da gramática do H2 Database Engine:
Disponível em : http://www.h2database.com/html/grammar.html#alter_table_rename_constraint
Comment: Se tiver a referência à documentação oficial eu creio que atrairá mais positivos