text:
Q: Implementation of adversarial examples generator using evolutionary algorithm performs poorly I am trying to implement evolutionary algorithm using MAP-Elites evolutionary strategy and polynomial mutation operator (as defined here at point 2.) as discussed in this paper. I created a three different MNIST models and trained them using tensorflow==2.0.0a using Keras API. The models are performing fine (all around 95% accuracy).
My understanding of the mentioned evolutionary strategy is that we create a starting population and then with each iteration mutate a randomly chosen specimen from that population. If after the mutation the new specimen gets the certainty of belonging to any class higher than a previously chosen best specimen for that class then we treat it as the best and add it to population. The expected result is that after algorithm is finished we should have a specimen for each of the classes that manages to get classified within that class with high certainty. The initial population of images is created is created using uniform distribution.
The issue is that my models classify random input created with uniform distribution always as the same class with high certainty (i.e CNN model always classifies it as 8). So most or all specimens i end up with are being classified as the same class (with slightly varying certainties of belonging to other classes) even after big starting population and number of iterations (i.e 1000 starting specimens and 20000 iterations).
Input samples are normalized to range [0.0, 1.0]. All of the reasoning bellow is constrained for simplification sake just to Dense model (CNN, and simplified LeNet5 yield similar results) described at the bottom.
Using normal distribution with mean=0.0 and stddev=0.3 or mean=0.5 and stddev=0.3 for generating starting population and mutation chance of 0.3 (instead of 0.1 as in paper) yields similar results.
I tried using (1 , λ) evolutionary strategy with targeting just one class (starting population 100, 100 generations) and it yields better results than the MAP-Elites implemented bellow (i can generate specimen for more than one class).
I tried not normalizing the data for model and training it again using [0, 255] range but the results were almost the same. I also tried using Gaussian mutation operator instead of polynomial but it didn't seem to make much of a difference.
Turning off data augmentation when training doesn't seem to have effect.
Here is the implementation i wrote.
def evolutionary_attack(model, population_size, generations_nmb, min=0.0, max=1.0, mutation_chance=0.1, mutation_power=15):
    population = [] #
    best_in_class = {} #dictionary of specimen performing best for given class

    for x in range(population_size):
        population.append(np.random.uniform(min, max, model.get_input_shape())) #initialize specimens with random values
        # population.append(np.random.normal(0.0, 0.3, model.get_input_shape())) #initialize specimens with random values

    for i in range(generations_nmb):
        current_specimen = random.choice(population) #choose specimen at random from the population
        mutated_specimen = mutate_specimen(current_specimen, min, max, mutation_chance, mutation_power)
        logits = model(tf.expand_dims(tf.convert_to_tensor(mutated_specimen, dtype=tf.float32), 0))
        certainties_per_class = tf.squeeze(logits).numpy()

        for cur_class in range(len(certainties_per_class)):
            if cur_class in best_in_class:
                _, best_certainty = best_in_class[cur_class]
                if certainties_per_class[cur_class] > best_certainty:
                    #if the new specimen performs better in given class make it a new best and add it to the population
                    best_in_class[cur_class] = (mutated_specimen, certainties_per_class[cur_class])
                    population.append(mutated_specimen)
            else:
                best_in_class[cur_class] = (mutated_specimen, certainties_per_class[cur_class]) #handles the case when there is no best specimen for the given class

def mutate_specimen(specimen, min, max, mutation_chance, mutation_power=15):
    specimen = np.copy(specimen)
    with np.nditer(specimen, op_flags=['readwrite']) as it:
        for old_val in it:
            if np.random.uniform() < mutation_chance:
                u = np.random.uniform()
                if u <= 0.5:
                    delta = ((2.0 * u) ** (1.0 / (mutation_power))) - 1.0
                    new_val = old_val + delta * (old_val - min)
                else:
                    delta = 1.0 - (2 * (1 - u))** (1 / (1 + mutation_power))
                    new_val = old_val + delta * (max - old_val)
                old_val[...] = new_val
    return np.clip(specimen, min, max)

In the paper authors state that they were able to get specimens for each digit classified with >99.99% confidence after 50 generations. This is vastly different from the results that i get. It seems that i am doing something wrong but i am unable to pinpoint the issue. I am not sure whether it is just some small bug in the code or is my reasoning behind implementation wrong.
My model is constructed like this
DenseModel (sigmoid activation functions on all layers except of last one)
input_1 (InputLayer)         [(None, 28, 28, 1)]       0

flatten (Flatten)            (None, 784)               0

dense (Dense)                (None, 784)               615440

dense_1 (Dense)              (None, 800)               628000

dense_2 (Dense)              (None, 800)               640800

dense_3 (Dense)              (None, 10)                8010
It have been trained for multiple epochs with data augmentation using Adam optimizer.
EDIT: i just noticed that i am not clipping values of specimens after mutation. If i do that then using normal distribution yields similar results to using uniform distribution. i fixed this in posted code. stupid mistake

A: I think you have misinterpreted MAP-Elites. You are tracking an append-only population separately from the elites, but according to this reference you are supposed to track only the elites. So I think the line to select the current specimen should be:
current_specimen, _ = random.choice(list(best_in_class.values()))

So the maximum population size would be 10 for MNIST. I'm not 100% sure that this is your main problem, but it should at least make the algorithm more greedy, moving search away from the oldest solutions.
Modification of MAP-Elites
Thinking about this some more, I'm not sure why this method should work on MNIST with direct pixel parameters. It would be very unlikely to generate a different digit just by random mutation, especially not after a few steps of optimization towards that same class, with all the other classes remaining empty.
It seems your implementation is actually doing this part correctly according to the paper:

[...] and replaces the current champion for any objective if the new
  individual has higher fitness on that objective.

But in the original MAP-Elites, the goal was to track a single global fitness metric over the whole  population. It was possible that some cells remained empty because no solution was ever mapped to this cell. The paper actually tracks a different fitness metric for each cell. This should have been stated more prominently as a modification of MAP-Elites. With this modification it seems plausible that this should work, but it no longer makes sense to allow empty cells.


text:
Q: C#, Winforms automation app throwing 0x800AC472 error when saving excel file I am writing a winform app that reads data from an sql database, paste it into excel and then saves the file in a given location.
My current issue is i'm encountering system error : 0x800AC472 when saving down the excel file.
So far I have tried adding
 GC.Collect();
 GC.WaitForPendingFinalizers();

to the on click method, after calling the excel save function.
From my googling it seems as though it may be due to the COM object not being removed after usage? these GC methods were meant to clear this, but it doesn't seem to be working properly. The reason I think it's not working properly is that there is still a microsoftoffice.exe process running in task manager after executing the code and receiving the error.
Something else worthy of mention is that if i wrap the code in a try-catch, the error is pasted to the console and the excel file is saved without issue, the only issue being that the process is still running in the task manager.
Is anyone here able to help me isolate the issue in my code causing this error? Thank you.
Here is the code that is called upon button press;
else if (((DataGridView)sender).Columns[e.ColumnIndex].DataPropertyName == "Run")
                    {
                    // return SQL into datatable
                    var returnedDT = SQLAcess.SQLtoDataTable(dataGridView1[0, e.RowIndex].Value.ToString()!);

                    //find item to open
                    string loadstring = DataGridClass.CellColumn(dataGridView1, "Load_Location", e.RowIndex);

                    //finds workbook to paste into.
                    var SettingsDataset = XMLData.ReturnXMLDataset(2);
                    var workbookstring = XMLData.returnXMLcellwithcolumnname(SettingsDataset, "Data_Dump_Worksheet_name", e.RowIndex);

                    //find location to save it
                    string savestring = DataGridClass.CellColumn(dataGridView1, "Save_location", e.RowIndex);

                    //execute export to excel, with the locations saved from above.
                    GXOMIClassLibrary.My_DataTable_Extensions.ExportToExcelDetailed(returnedDT, loadstring, workbookstring, savestring);
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    }

The
GXOMIClassLibrary.My_DataTable_Extensions.ExportToExcelDetailed(returnedDT, loadstring, workbookstring, savestring);
method refers to a class library I have created with this method below;
public static void ExportToExcelDetailed(this System.Data.DataTable DataTable, string ExcelLoadPath, string WorksheetName, string ExcelSavePath)
        {
            try
            {

                int ColumnsCount;

                //if datatable is empty throw an exception.
                if (DataTable == null || (ColumnsCount = DataTable.Columns.Count) == 0)
                    throw new Exception("ExportToExcel: Null or empty input table!\n");

                // load excel, and create a new workbook
                //Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application();
                //Excel.Workbooks.Add();

                var excelApp = new Excel.Application();
                Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(ExcelLoadPath);

                //TELL THE PROGRAM WHAT WORKBOOK TO OPEN
                // select the right worksheet.
                var Worksheet = excelWorkbook.Sheets[WorksheetName];

                // DataCells
                int RowsCount = DataTable.Rows.Count;
                object[,] Cells = new object[RowsCount, ColumnsCount];

                for (int j = 0; j < RowsCount; j++)
                    for (int i = 0; i < ColumnsCount; i++)
                        Cells[j, i] = DataTable.Rows[j][i];

                //find last row
                var xlRange = (Excel.Range)Worksheet.Cells[Worksheet.Rows.Count, 1];
                long lastRow = (long)xlRange.get_End(Excel.XlDirection.xlUp).Row;
                long newRow = lastRow + 1;

                ///cells[2,1] needs to become cell below last paste
                Worksheet.Range((Microsoft.Office.Interop.Excel.Range)(Worksheet.Cells[newRow, 1]), (Microsoft.Office.Interop.Excel.Range)(Worksheet.Cells[newRow + RowsCount -1, ColumnsCount])).Value = Cells;

                // check fielpath
                if (ExcelSavePath != null && ExcelSavePath != "")
                {
                    try
                    {
                        Worksheet.SaveAs(ExcelSavePath);
                        excelApp.Quit();
                       // Worksheet.Close(0);
                        //richTextBox1("Excel file saved!");
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("ExportToExcel: Excel file could not be saved! Check filepath.\n"
                            + ex.Message);
                        excelApp.Quit();
                    }
                }
                else    // no filepath is given
                {
                    excelApp.Visible = true;
                }
                excelApp.Quit();
            }
            catch (Exception ex)
            {
                throw new Exception("ExportToExcel: \n" + ex.Message);

            }

        }

A: changing this part of the ExportToExcelDetailed seems to have corrected the issue;
  if (ExcelSavePath != null && ExcelSavePath != "")
                {
                    try
                    {
                        Worksheet.SaveAs(ExcelSavePath);
                        excelApp.Quit();
                        Marshal.ReleaseComObject(Worksheet);
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("ExportToExcel: Excel file could not be saved! Check filepath.\n"
                            + ex.Message);
                        excelApp.Quit();
                    }
                }
                else    // no filepath is given
                {
                    excelApp.Visible = true;
                }

redpajama_set_name: RedPajamaStackExchange


text:
Q: SQL Server 2012 stop working after specific time SQL Server 2012 stops working after every 6 to 7 hours, SQL Server Management Studio not connected, almost every service related to SQL Server stops, after system restart every service is working fine, I have got error in event window
   OpenSQLServerInstanceRegKey:GetRegKeyAccessMask failed (reason: 2).

SQL Server Agent log error

Sql server Log


text:
Q: PHP gdrive upload file There is no error. Why is not the file sent?
error_reporting(E_ALL);
    ini_set('display_errors',1);
         try{
    require_once './vendor/autoload.php';

    $client = new Google_Client();

    $oauth_credentials = './vendor/test.json';

    $client = new Google_Client();
    $client->setAuthConfig($oauth_credentials);
    $client->setScopes('https://www.googleapis.com/auth/drive');

    $driveService = new Google_Service_Drive($client);

    $fileMetadata = new Google_Service_Drive_DriveFile(array(
        'name' => 'photo.png'));

    $content = file_get_contents('./vendor/plik.png');
    $file = $driveService->files->create($fileMetadata, array(
        'data' => $content,
        'mimeType' => 'image/png',
        'uploadType' => 'multipart',
        'fields' => 'id'));
    printf("File ID: %s\n", $file->id);

    }catch(Exception  $e){
    echo $e->getMessage();
    }

A: You appear to be using a service account.   A service account is not you.  Files uploaded using a service account will be uploaded to the service accounts google drive account.
Tips for using service accounts with google drive:

*

*No there is no web view for the service accounts files.

*Do a file.list to see if the file was in fact uploaded to your service account.

*share a directory on your personal google drive account and have the service account upload to that.  Remember to grant yourself permissions to the file.


text:
Q: Checksum Generation from sum of bits in python I am trying to control a chiller through RS232 with python. I am stuck at generating a checksum as required by the following method.
"The checksum is two ASCII hexadecimal bytes representing the least significant 8 bits of the sum of all preceding bytes of the command starting with the sor."
The "sor" in this case in bytes is "2E".
-Example
For example, the PC requires the chiller mode be set to Stand By. It will transmit the following sequence of bytes.
2E 47 30 4135 0D
Note that 2Eh is the start of header ("."), 47h is the command ("G"), 30h is the qualifier to set the mode to Stand by.  41h and 35h are checksum bytes representing the ASCII hex for "A5" which is the least significant byte of the sum of 2Eh + 47h + 30h and 0Dh is carriage return.
Does anyone know how to generate the checksum bytes 4135?
Thankyou!!

A: You can find the sum in hexadecimal as
>>> hexsum = hex(0x2e + 0x47 + 0x30)[2:].upper()
>>> hexsum
'A5'

(the 0x at the front is sliced off by [2:])
Then you can get the ASCII values of the characters in hexadecimal as
>>> bytes = [hex(ord(c))[2:] for c in hexsum]
>>> bytes
['41', '35']

(again, the frontal 0x is removed from each element)
Then you can join them together:
>>> checksum = ''.join(bytes)
>>> checksum
'4135'

Or everything can be done with this one-liner:
>>> ''.join(hex(ord(c))[2:] for c in hex(0x2e + 0x47 + 0x30)[2:].upper())
'4135'

A: Python 2
The function rs232_checksum calculates the sum of the bytes.
Then it converts the sum to an uppercase hexadecimal string and returns is as bytes.
def rs232_checksum(the_bytes):
    return bytes('%02X' % (sum(map(ord, the_bytes)) % 256))

checksum_bytes = rs232_checksum(b'\x2e\x47\x30')

Python 3
The function definition simplifies to (with binary "and" to get the least significant eight bits):
def rs232_checksum(the_bytes):
    return b'%02X' % (sum(the_bytes) & 0xFF)


text:
Q: Cakephp encrypt an decrypt with RIJNDAEL I have a beforeSave and afterFind function in my Model. The function encrypt and decrypt the string successfully:
    public function beforeSave($options = array()) {
   foreach($this->encryptedFields as $fieldName){
    if(!empty($this->data[$this->alias][$fieldName])){
        $this->data[$this->alias][$fieldName] = Security::rijndael($this->data[$this->alias][$fieldName], Configure::read('Security.key'), 'encrypt');
    }
}
return true;

}
But. If I do this
    $mobileno = 1234
    $mobile = Security::rijndael($mobileNo, Configure::read('Security.key'), 'encrypt');

and then I run query for example like:
   select * from table where mobileno = $mobileno;

I cant get the result. Because now the mobileno which is I encrypt above is different from the encrypt mobile number which is in db.

A: That is because Security::rijndael() uses a random initialization vector on every call.
In order to workaround this you would have to use a fixed IV, however this would degrade security, so that might not be a good idea!
For such situations I usually additionally encrypt the value using deterministic encryption, and store an HMAC hash (not a regular hash! Also should use a different secret/key than the one used for encryption!) of that value in an additional column, that way the select can be easily done with the hash of the deterministically encrypted value, and you're note completely loosing the improved security of non-deterministic encryption.
If you aren't able to use such a technique (ie utilizing a different value for identifying the record), then you might not get around selecting all datasets, decrypting them, and searching for the record in question manually.
If your DBMS supports AES encryption/decryption, you could try utilizing that functionality, it will most likely perform better than decrypting and selecting with PHP. But make sure that you assess possible security related pitfalls that might be introduced by exposing the encryption key to the DBMS!


text:
Q: Issue with multiple routes in one file - only two out of three work, the last one won't work I'm working on making an API using express and MySQL. I'm having issues with my routes. I have it in a separate folder, requiring the different controller files and exporting the router at the end. Here's the issue. The last router.get function will not work. I can swap it and whatever is last will not work. I'll get back an empty array. I'm at a loss as to what can be wrong. Here's my code, the routes file:
const express = require('express');
const router = express.Router();

const getEmployeesController = require('../controllers/getEmployees');
const getEmployeesByIdController = require('../controllers/getEmployeesById');
const getEmployeesByFirstNameController = require('../controllers/getEmployeesByFirstName');

router.get('/', getEmployeesController.getEmployees);

router.get('/:id', getEmployeesByIdController.getEmployeesById);

router.get('/:first_name', getEmployeesByFirstNameController.getEmployeesByFirstName);

module.exports = router;

The 'first_name' router worked when it was second, after the '/', but now it won't. Same with the 'id', worked when its second, but not when it's third.
Here's the controller function, one as an example:
const mysql = require('mysql')
const pool = require('../mysql/connection')
const { handleSQLError } = require('../mysql/error')

const getEmployeesById = (req, res) => {
  let sql = "SELECT ?? FROM ?? WHERE ?? = ?"
  sql = mysql.format(sql, ['*', 'employees', 'emp_no', req.params.id])

  pool.query(sql, (err, rows) => {
    if (err) return handleSQLError(res, err)
    return res.json(rows);
  })
}

  module.exports = { getEmployeesById };

A: /:first_name and /:id match the exact same URLs so only the first one you register is going to get all the matching URLs.  They both match /anything.
You really can't define routes like that.  There's no way Express knows which route handler you want to use with /anything is the requested URL.
Instead, you need to define a route structure where those two types of URLs are different and you can design a route handler that will uniquely catch each one.  I personally don't ever use top level wildcard routes like this because they match every top level URL and they prohibit you using top level URLs for any other purpose in your site.
Instead, you might change your URL design to do this:
router.get('/id/:id', ...)
router.get('/firstname/:firstname', ...);

Then, it would be completely clear from the URL what type of resource was being requested and each route would match only the appropriate URLs.


text:
Q: android volley simple http request New to volley.
Quick question.
I can get volley simple HTTP request to work fine when placed in onCreate
Is it possible to put the request into a separate class?
Android studio cannot resolve "stringRequest" in this example. Help much appreciated...
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Retriever go = new Retriever();
        go.queue.add(stringRequest);
    }

public class Retriever {

    RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
    String url = "http://www.google.com";

    public StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    // mTextView.setText("Response is: " + response.substring(0, 500));
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            // mTextView.setText("That didnt work!");
        }

    });

}

}

A: Since your stringRequest variable is in the scope of Retriever class, its visibility is contained in that class only. That's why you are getting that error.
It will go away if you write
go.queue.add(go.stringRequest);

as you are referencing the object from the instance of its class.


text:
Q: upload laravel on siteground routes not working when upload the laravel on the siteground server it workes put the routes not working
I tried to upload htaccess
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]

so why the routs is not wroking ?

A: You will likely have to put your public part of laravel within /public_html and not /public which is what Lavavel is expecting.  So create a symbolic link to create a fake /public folder:
ln -s public_html public


text:
Q: Joomla SEF and Jumi URL output I'm using jumi at the moment to create custom pages for joomla. However, when i try to use JRoute (eg: JRoute::_('index.php?option=com_jumi')) to redirect to a menu item i created for the jumi page, I get the following url http://www.mydomain.com/component/jumi/confirm?ad_code=MDAwMV8wNTgx.(WHERE confirm is my jumi alias)
My question now is: how can i get rid of the "/component/jumi/" statement in the url. (ie: http://www.mydomain.com/confirm?ad_code=MDAwMV8wNTgx)

A: Can you try this

*

*In your Menu Item Manager (Menus, Select a Menu) .

*Create a new Menu item, Select your Component from the Menu Type Options

*Enter in the Menu Item Details Title and Alias.  The title will now be the text shown as the link and will remove the /component/ from your URL.

The above tips is taken from here


text:
Q: construct cut-off function in the tensor product form $\rho_1\otimes \rho_2$ Let $K$ be compact subset of $\Bbb{R}^2$,prove given $K^\epsilon = K+\overline{B}_\epsilon$,there exist some cutoff function that support in $K^\epsilon$ and constant one on neiborhood of $K$.
I do as follows:Let $\pi_i$ be the projection on the corresponding coordinate,then we can see exist $\rho_1$ support on $\pi_1(K^\epsilon)$ and constant 1 on neiborhood of $\pi_1(K)$ (e.g denote it $N_1$).Similar for the second coordinate,hence $\rho_1(x_1)\otimes \rho_2(x_2)$ then we know it's constant 1 on neiboorhood of $K$ , the question is how to guarantee it support on $K^\epsilon$.


text:
Q: Rust: Trait as a return type Lets say there's this kind of code:
trait A {
  fn something(&self) -> String
}

struct B {
  things: Vec<u64>
}

struct C {
  thing: Box<&dyn A>
}

impl A for B { ... }

fn create_thing() -> B {
  //
}

impl C {
  pub fn new() {
    let thing = create_thing();
    C { thing }
  }
}

My question is what exactly should be the return type of create_thing to match with Box<&dyn A> or how exactly should the returning value be wrapped to match with Box<&dyn A>?
Equivalent C# code would look something like:
interface A {}
class B : A {}
class C {
  public A field;
  public C() {
    this.field = new B();
  }
}

A: Find below your code with minor adjustments to get it to compile.
I suspect that Box<&dyn A> was not intended since it means that
the reference itself is heap-allocated (not the referred to object).
On the other hand, Box<dyn A> matches your C# example.
The return type create_thing() looks good to me because it
does not assume any particular kind of storage (stack, heap, inside
a vector...) for the returned value.
You just have to Box this resulting value in order to provide
it when initialising a C.
However, if you want to hide the fact that the exact returned
type is B in create_thing(), you can change it like this
fn create_thing() -> impl A.
If you really want to return a dyn trait object, then change
it to fn create_thing() -> Box<dyn A> and create the box
here rather than in C::new().
trait A {
    fn something(&self) -> String;
}

struct B {
    things: Vec<u64>,
}

struct C {
    thing: Box<dyn A>,
}

impl A for B {
    fn something(&self) -> String {
        format!("something on B with {:?}", self.things)
    }
}

fn create_thing() -> B {
    B {
        things: vec![1, 2, 3],
    }
}

impl C {
    pub fn new() -> Self {
        let thing = Box::new(create_thing());
        Self { thing }
    }
}

fn main() {
    let c = C::new();
    println!("{}", c.thing.something());
}


text:
Q: how to query if point is inside a circle schema _ mongoose this is my schema :
var schema = new Schema({
    loc: {
        type: {
            type: String
        },
        coordinates: []
    },
     radius : {
      type : 'Number'
     }
});
schema.index({
    loc: '2dsphere'
});
var A = mongoose.model('Circle', schema);

and this is my collection example:
{
 loc: {type : "Point", coordinates: [77.69866, 13.025621]}, radius: 100.21
}

my question is: is it possible to check if this point  [12.1222, 29.2112] is inside my Circle collection?

A: One possible solution is to use the $geoNear aggregation stage.
Model.aggregate([
    {$geoNear: {
        near: {type:"Point", coordinates:[12.1222, 29.2112]},
        distanceField: "distance"
    }},
    {$match: {
       $expr: {$lt: ["$distance", "$radius"]}
    }}
])


text:
Q: Expresão ternaria para atribuição de valor em uma variavel do iReport com problema Galera seguinte, criei uma expressão ternaria que com base nos valores de duas variaveis do mesmo contexto ("grupo"), para que me traga uma media. Porém por algum motivo nao esta funcionando e estou com duvida. Segue a expressão e o retorno do iReport.
Error filling print... Error evaluating expression :
Source text : $V{QtdViagens_1} > 0 ? new BigDecimal($V{QtdPessoas_1}).divide( new BigDecimal($V{QtdViagens_1})) : new BigDecimal("0")

A: Tente acrescentando o toString();
$V{QtdViagens_1} > 0 ? new BigDecimal($V{QtdPessoas_1}).divide( new BigDecimal($V{QtdViagens_1})).toString() : new BigDecimal("0").toString()

tenha certeza que as variáveis não estão nulas e
coloque Expression Class:   java.lang.String


text:
Q: Tailwind dynamic grid issue with vue3 I am new in stack overflow.
I am using Vue3 + tailwindcss.
I want to create dyamic grid like this

Corrrection: Here i want repetitive layout and the item of loop are dynamic
Here is My code:
<template>

      <template v-for="(i,index) in 8" :key="index">

 {{ index }} {{updateCounter(index) }}

{{ index }}

      </template>

</template>

But i get Wrong output.

I already spend 2 day but i can't find any solution.
So can anyone help me to how i do this?
Thank you in advance.

A: What really complicates your solution is you're modifying the state while calculating the layout (in the v-for loop). Never do that!
When you change the value of state, everything that uses that piece of reactive state gets recalculated (including the items that have already been looped through).
It's an anti-pattern, for a couple of reasons:

*

*it often leads to performance issues (changes triggering each other endlessly)

*it's particularly difficult to follow the mutations trail, while trying to debug it and everyone, including yourself, will have a hard time debugging it, should it start failing.

The fact you asked the question is proof to it. I'm confident you'd have figured out the function below by yourself, had you not modified the state inside the loop.

What you need is:

*

*the count

*a function returning md:col-span-${x} correctly for the last items based on count and index, along these lines:

const count = ref(8)
const getMdClass = (index) => {
  const rest = count.value % 3;
  if (index > count.value - rest - 1) {
    return `md:col-span-${12 / rest}`;
  }
  return "md:col-span-4";
}

This function returns md:col-span-4 all the time, except:

*

*md:col-span-6 for the last 2 items with a (3 x n) + 2 count,

*md:col-span-12 for the last item with a (3 x n) + 1 count.

Here's a proof of concept (haven't used typescript or


text:
Q: Flutter / Dart : How to write tests in Flutter //sample(A),(UI and business logic are separated.)
import 'package:flutter/material.dart';
import 'dart:math';

import 'package:provider/provider.dart';

class IntNotifier extends ChangeNotifier{
  int finalContent = 0;
  int originalContent = 0;

  void setContent(){
    originalContent = Random().nextInt(10);
    finalContent = originalContent <5 ? 5 : originalContent;
    notifyListeners();
  }
}

void main() {
  runApp(
    ChangeNotifierProvider(
      create:(_)=>IntNotifier(),
      child: MaterialApp(
        home: MyApp(),
      ),
    ),
  );
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final intNotifier = Provider.of<IntNotifier>(context);
    return Scaffold(
      body: Container(
        color:Colors.lightBlueAccent[100],
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                '${intNotifier.finalContent}',
                style: TextStyle(
                  fontSize: 80.0,
                ),
              ),

              Text(
                '(${intNotifier.originalContent})',
                style: TextStyle(
                  fontSize: 30.0,
                  color: Colors.grey
                ),
              ),

            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed:intNotifier.setContent,
      ),
    );
  }
}

(1) I don't know exactly how to write tests.
For example, in the above code, how should I write a test code to check that the value of "finalContent" is greater than or equal to 5 when setContent is called?
For now, I wrote the following unit test code.
It seems to confirm what I want to confirm, but how is it usually written?
Since this is a test about IntNotifier, I think I probably need to use IntNotifier and setContent method, but I am not sure how exactly to use it.
import 'package:flutter_test/flutter_test.dart';

void main(){
  test('more than five',(){

    int finalContent = 0;
    int originalContent = 0;

    originalContent = -1;
    finalContent = originalContent <5 ? 5 : originalContent;
    expect(finalContent>=5,true);

    originalContent = 0;
    finalContent = originalContent <5 ? 5 : originalContent;
    expect(finalContent>=5,true);

    originalContent = 1;
    finalContent = originalContent <5 ? 5 : originalContent;
    expect(finalContent>=5,true);

    originalContent = 4;
    finalContent = originalContent <5 ? 5 : originalContent;
    expect(finalContent>=5,true);

    originalContent = 5;
    finalContent = originalContent <5 ? 5 : originalContent;
    expect(finalContent>=5,true);

    originalContent = 8;
    finalContent = originalContent <5 ? 5 : originalContent;
    expect(finalContent>=5,true);

  });
}

(2)
https://developer.android.com/jetpack/guide
On the above page and other pages as we talk about app architecture.
"Separating the 'UI code' from the 'business logic code' will make your app easier to test."
This has been said a lot.
However, I myself don't know how to write tests, so I don't know exactly why separating UI and business logic makes it easier to test.
An example where the UI and business logic are not separated would probably be the following code using StatefulWidget.
//sample(B),(UI and business logic are separated.))
import 'package:flutter/material.dart';
import 'dart:math';

void main() {
  runApp(MaterialApp(home: MyApp(),
      ),
  );
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int originalContent = 0;
  int finalContent = 0;

  void setContent(){
    setState((){
      originalContent = Random().nextInt(10);
      finalContent = originalContent <5 ? 5 : originalContent;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color:Colors.orangeAccent,
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                '${finalContent}',
                style: TextStyle(
                  fontSize: 80.0,
                ),
              ),

              Text(
                '(${originalContent})',
                style: TextStyle(
                    fontSize: 30.0,
                    color: Colors.grey
                ),
              ),

            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed:setContent,
      ),
    );
  }
}

"In sample(A), we can write the following test code.
But with sample(B), we have to write this kind of test code.
So sample(A) is better for us."
Please explain the above story using concrete test code.


text:
Q: C# Is there a way I can compile an exe When people download my project from GitHub, I launch a Setup Guide on Start Up that contains a button that reads 'Launch Connection String Builder'.
The problem is GitHub doesn't store the .exe, so I have to explain in every video or tutorial 'Open Connection String Builder Solution > Build' then either run Connection String Builder or click the button 'Launch Connection String Builder Button'.
If there is a way I can compile on demand the Connection String Builder project this would be my ideal solution.
I know I could move the form in the Connection String Builder project to inside of the main (DataTier.Net) project, but I don't want to do that if I don't have to since I keep a shortcut on my desktop to Connection String Builder.
The folder of ConnectionStringBuilder is in a tools folder which is a sub folder of the main project.
I was looking for a Rosylyn method to compile a project on demand, but couldn't find anything by Googling this (I did give up after a couple of pages I admit).  As illustrated by the code sample below, I know how to check if the .exe exists, and I would like to be able to something like RosylnCompiler.Compile(pathToProject); if the .exe does not exist.
string temp = "../../../Tools/ConnectionStringBuilder/ConnectionBuilder/bin/Debug/ConnectionBuilder.exe";
string path = Path.GetFullPath(temp);
if (File.Exists(path))
{
    string databaseName = ...;
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(path, databaseName);
    System.Diagnostics.Process.Start(startInfo);
}
else
{
    MessageBox.Show("Sorry we could not find DataTier.Net Connection String Builder.", "App Not Found", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

Is there anyway to do this? If not I can update my message boxes to be instructions or copy the form into my main project if I have to, but a compile on demand would be my ideal solution.

A: Assuming there are no errors, Visual Studio will ensure all projects in the current build configuration are built when 1) the Build Solution command is executed or 2) the current build configuration is started (e.g., when either the Start Debugging or Start Without Debugging command is executed).  In addition, assuming there are no errors, Visual Studio will build all projects in the current build configuration when the Rebuild Solution command is executed.
Thus, you should be able to ensure that the project for the Connection String Builder application is built by including it in all of the build configurations defined for the solution.
See Understand build configurations for more information regarding build configurations.
In addition, unless you only have a Debug configuration, you should not assume that the Debug version of the Connection String Builder application was built (i.e., ../../../Tools/ConnectionStringBuilder/ConnectionBuilder/bin/Debug/ConnectionBuilder.exe from your question).  If your solution only defines the default Debug and Release build configurations, you can determine the correct path as follows:
#if DEBUG
../../../Tools/ConnectionStringBuilder/ConnectionBuilder/bin/Debug/ConnectionBuilder.exe
#else
../../../Tools/ConnectionStringBuilder/ConnectionBuilder/bin/Release/ConnectionBuilder.exe
#endif


text:
Q: PHP fopen() increase the time out limit? I created script like this
<?php
$handle = fopen("list1.csv", "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {

$file = fopen("http://$urldhara1/app.php?name=$line","r");

 fclose($file);

    }
?>

it works fine.this code execute the process in my server.
sometimes it take 10 minutes to complete.
due to this before the one process complete the next process start.
i thinks because of the timeout limit i try
set_time_limit(0);
ignore_user_abort(true);

but it does not help.
so sir what should i do for increase the timeout of fopen.
or i am doing something wrong?
what should i do??
in my script the before completion of the one process the another preocess start what should i do please help me.


text:
Q: Unable to connect to certain hosts from an EC2 instance I am running Ubuntu on an EC2 instance and certain, very particular hosts fail to reply to POST. For example when I run
curl -v -L -I http://www.moneymanagement.com.au/
from my local machine, I receive an immediate reply. However, the same command, run from EC2 times out.

*

*About to connect() to www.moneymanagement.com.au port 80 (#0)

*Trying 61.14.142.150... Connection timed out

*couldn't connect to host

*Closing connection #0 curl: (7) couldn't connect to host

However the same POST to Google and others returns immediately. Additionally, circumventing the name server avoids this problem:
curl -v -L -I 141.101.124.53
Replies without failure. What might be causing this behavior?
Edit: Here are the traceroute results.
traceroute to www.moneymanagement.com.au (61.14.142.150), 30 hops max, 60 byte packets
 1  10.96.72.3 (10.96.72.3)  0.345 ms  0.444 ms  0.556 ms
 2  ip-10-1-16-41.ec2.internal (10.1.16.41)  0.540 ms ip-10-1-28-41.ec2.internal (10.1.28.41)  0.390 ms ip-10-1-18-41.ec2.internal (10.1.18.41)  0.499 ms
 3  ip-10-1-29-14.ec2.internal (10.1.29.14)  0.667 ms ip-10-1-13-14.ec2.internal (10.1.13.14)  0.755 ms ip-10-1-29-14.ec2.internal (10.1.29.14)  0.865 ms
 4  216.182.224.120 (216.182.224.120)  2.872 ms 216.182.232.50 (216.182.232.50)  2.732 ms 216.182.224.211 (216.182.224.211)  2.580 ms
 5  100.64.2.195 (100.64.2.195)  1.680 ms 100.64.2.235 (100.64.2.235)  1.885 ms 100.64.2.247 (100.64.2.247)  2.098 ms
 6  100.64.0.50 (100.64.0.50)  364.049 ms 100.64.0.6 (100.64.0.6)  383.689 ms 100.64.0.24 (100.64.0.24)  403.813 ms
 7  * * *
 8  72.21.220.225 (72.21.220.225)  0.526 ms 72.21.222.148 (72.21.222.148)  1.056 ms 72.21.220.225 (72.21.220.225)  0.718 ms
 9  72.21.222.148 (72.21.222.148)  0.815 ms 205.251.245.64 (205.251.245.64)  0.839 ms 72.21.222.148 (72.21.222.148)  47.064 ms
10  gw3.lax1.asianetcom.net (206.223.115.40)  65.325 ms  65.297 ms  65.291 ms
11  te0-1-0-0-983.cr1.syd5.asianetcom.net (203.192.174.133)  202.111 ms  201.326 ms  201.273 ms
12  gi0-1-0.gw16.syd5.asianetcom.net (203.192.174.170)  201.375 ms te0-1-0-0-983.cr1.syd5.asianetcom.net (203.192.174.133)  200.736 ms gi0-1-0.gw16.syd5.asianetcom.net (203.192.174.170)  200.682 ms
13  gi0-1-0.gw16.syd5.asianetcom.net (203.192.174.170)  200.504 ms  200.922 ms *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *

A: The connection timed out error is where you should concentrate (assuming the IP address is the correct one for the host you intend to connect to.)  In order to establish an HTTP connection you will need:

*

*a web server listening on port 80 on the server

*a security group associated with the host instance that allows traffic over port 80 from your IP (more likely from all IPs)

Check that the web server is running on the instance (log in and run ps -elf and check for your web server process (e.g. apache or nginx).  Or check the web server error log to ensure that it started correctly.  Unless you have a funky configuration, it's likely listening on port 80.
Check the security group associated with the instance through the AWS console.  Is it the same as other instances that are working?  If not, chances are that's the problem, or if this is the only instance, then you'll need to allow traffic on port 80.
If the IP address is wrong, check your DNS settings (Route 53 on AWS if that's where you do DNS for your domain), or the IP address associated with any elastic IP associated with the instance.


text:
Q: Unable to perform OneToOne Mapping Hibernate I was trying to implement OneToOne mapping using Hibernate. I am using Mysql as DB. I have Product as parent and ProductRestaurant as its child. Trying to get one to one maping between them but
While persisting, getting the following exception:
2015-12-13 00:06:24 [http-nio-8080-exec-1] DEBUG org.hibernate.jdbc.A`enter code here`bstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2015-12-13 00:06:24 [http-nio-8080-exec-1] DEBUG o.h.util.JDBCExceptionReporter - **Could not execute JDBC batch update [insert into myproduct (business_category, in_stock, merchant_id, productRestaurant, product_id) values (?, ?, ?, ?, ?)]
java.sql.BatchUpdateException: Data truncation: Data too long for column 'productRestaurant' at row 1**
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1809) ~[mysql-connector-java-5.1.36.jar:5.1.36]
    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1271) ~[mysql-connector-java-5.1.36.jar:5.1.36]
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268) [hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184) [hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) [hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) [hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216) [hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)

When i print the queries, i found this.
 insert
    into
        product
        (business_category, in_stock, merchant_id, productRestaurant, product_id)
    values
        (?, ?, ?, ?, ?)

Product Entity:
@Entity
@Table(name = "product")
public class Product implements IEntity {

    @Id
    @Column(name = "product_id")
    private String productId;

    @Column(name = "merchant_id")
    private String merchantId;

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(String merchantId) {
        this.merchantId = merchantId;
    }

    @Column(name = "business_category")
    private String businessCategory;

    @Column(name = "in_stock")
    private Boolean inStock;

    private ProductRestaurant productRestaurant;

    @OneToOne(fetch=FetchType.LAZY, mappedBy="product", cascade=CascadeType.ALL)
    public ProductRestaurant getProductRestaurant() {
        return productRestaurant;
    }

    public void setProductRestaurant(ProductRestaurant productRestaurant) {
        this.productRestaurant = productRestaurant;
    }
    public String getBusinessCategory() {
        return businessCategory;
    }

    public void setBusinessCategory(String businessCategory) {
        this.businessCategory = businessCategory;
    }

    public Boolean getInStock() {
        return inStock;
    }

    public void setInStock(Boolean inStock) {
        this.inStock = inStock;
    }

ProductRestaurant Entity
@Entity
@Table(name = "product_restaurant")
public class ProductRestaurant implements IEntity {

    @Id
    @Column(name="product_id")
    private String productId;

    /**
     * @return the productId
     */

    public String getProductId() {
        return productId;
    }
    public void setProductId(String productId) {
        this.productId = productId;
    }

    @Column(name = "category")
    private String category;

    @Column(name = "cuisine")
    private String cuisine;

    @Column(name = "title")
    private String title;

    @Column(name = "description")
    private String description;

    @Column(name = "price")
    private Double price;

    private Product product;

    @OneToOne(fetch = FetchType.LAZY)
    @PrimaryKeyJoinColumn
    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getCuisine() {
        return cuisine;
    }

    public void setCuisine(String cuisine) {
        this.cuisine = cuisine;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

Tables Created:
CREATE TABLE IF NOT EXISTS `product` (
  `product_id` varchar(30) NOT NULL,
  `merchant_id` varchar(30) NOT NULL,
  `business_category` varchar(50) NOT NULL,
  `in_stock` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `product_restraunt` (
  `product_id` varchar(30) NOT NULL,
  `category` varchar(50) NOT NULL,
  `cuisine` varchar(50) NOT NULL,
  `title` varchar(50) NOT NULL,
  `description` varchar(500) NOT NULL,
  `price` int(7) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `product_restraunt`
  ADD CONSTRAINT `PRODUCT_RESTRAUNT_FK` FOREIGN KEY (`product_id`) REFERENCES `product` (`product_id`);

What am i missing? Thanks in advance.

A: You should either set the annotations on the Property(getters or setters) or Fields, don't mix it.
In this case annotating the fields of the entity will cause the provider to use field access to get and set the state of the entity, if a property acess is present it will be ignored by the provider
Put the annotations of the bidirectional @OneToOne on the fields and remove it from the getters.
 @OneToOne(fetch = FetchType.LAZY)
 @PrimaryKeyJoinColumn
 private Product product;

public Product getProduct() {
    return product;
}

the same thing with the other entity.


text:
Q: How to configure and setup Xdebug in phpstorm for Magento? I want to use the debugger to debug my module but I don't know how to configure and set up  debugger in phpstorm, any hints or solutions?

A: Follow this step to configure xdebug.

1:Run this command in terminal

sudo apt install php7.4-xdebug

after that check PHP version by this command and we will configure according to that xdebug version
PHP -v

in my case, Xdebug version is given v3 so that I will set it up accordingly

2: now run this command

sudo nano /etc/php/7.4/mods-available/xdebug.ini

and paste the following code in that file
zend_extension=/usr/lib/php/20190902/xdebug.so
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.client_host = 127.0.0.1
xdebug.remote_log = /tmp/xdebug_remote.log
xdebug.remote_mode = req
xdebug.client_port = 9003
xdebug.mode = debug

and remember in the first line /usr/lib/php/"your folder name"/xdebug.so
go this path and check what the folder number is and paste it according to in some cases it is different but mostly it is the same.
Here are the settings if your Xdebug version is v2
zend_extension=/usr/lib/php/20190902/xdebug.so
 xdebug.remote_autostart = 1
 xdebug.remote_enable = 1
 xdebug.remote_handler = dbgp
 xdebug.remote_host = 127.0.0.1
 xdebug.remote_log = /tmp/xdebug_remote.log
 xdebug.remote_mode = req
 xdebug.remote_port = 9003

now restart apache
sudo systemctl restart apache2

so far half our work is done now let's do some settings in phpstorm
open PHPstorm got to
File>>Settings>>PHP>Xdebug
and click on the
validate
a new window will open and in that window type your URL accordingly
and hit Validate

so far your Xdebug is configured in phpstorm,
and you can use breakpoint and turn on debug listener and hit that file and start using xdebug
in case any issues let me know, Thanks in advance

A: You have to follow these steps :
Install X debug for the PHP version which you are using by this command :
sudo apt install php7.4-xdebug

In this file add these lines :
zend_extension=/usr/lib/php/20190902/xdebug.so
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.client_host = 127.0.0.1
xdebug.remote_log = /tmp/xdebug_remote.log
xdebug.remote_mode = req
xdebug.client_port = 9003
xdebug.mode = debug

Then install x debug extension from the google chrome.
Finally change the x debug port in the PHP storm in this way :
File>>Settings>>PHP>Xdebug

If you find any more problem then tell me we will resolve that also.
Thanks!

A: Sometimes When you try to validate it gives some error like invalid port or service not available etc
always make sure the port you set in that file and the port in your phpstorm is same, like in my case it is 90003
and always restart apache
and if your xdebug is validated but still not working then try to use a Xdebug Helper extension
thats all, thanks


text:
Q: How to populate new date column to existing CSV file I am working with CSV file (~20MB). It has three columns as shown below and the file name presents the start time i.e. timestamp of the first row (in this case file name is 20200325131010000.csv).
x;y;z
3;-132;976
3;-131;978
3;-130;975
4;-132;975
5;-131;976
3;-132;975

The difference between the timestamp of the consecutive row is 20 ms. How can I efficiently populate the new date column to the existing file? The final CSV file should look like this:
timestamp;x;y;z
20200325131010000;3;-132;976
20200325131010020;3;-131;978
20200325131010040;3;-130;975
20200325131010060;4;-132;975
20200325131010080;5;-131;976
20200325131010100;3;-132;975

So far I have tried the following code:
  const csv = require('csv-parser');
  const fs = require('fs');
  var json2csv = require('json2csv').parse;
  var dataArray = [];
    fs.createReadStream('C:/Users/Downloads/20200325131010000.csv')
      .pipe(csv())
      .on('data', (row) => {
        row.timestamp= "20200325131010000";
        dataArray.push(row);
      })
      .on('end', () => {
        var result = json2csv({ data: dataArray, fields: Object.keys(dataArray[0]) });
        fs.writeFileSync("test.csv", result);
      });

The above code generates the following output (all timestamp are the same which is not desirable):
timestamp;x;y;z
20200325131010000;3;-132;976
20200325131010000;3;-131;978
20200325131010000;3;-130;975
20200325131010000;4;-132;975
20200325131010000;5;-131;976
20200325131010000;3;-132;975

The problem with this code is that it adds the same timestamp (i.e. 20200325131010000) to all the rows. How can I correctly populate the timestamp column?
Kindly suggest me an efficient way to achieve this.

A: I think this code should work and solve your problem.
  const csv = require('csv-parser');
  const fs = require('fs');
  var json2csv = require('json2csv').parse;

  const filePath = 'C:/Users/Downloads/20200325131010000.csv';
  const fileName = (/^.+\/([^/]+)\.csv$/gi).exec(filePath)[1]; // extract file name from path
  const intialTimestamp = parseInt(fileName); // convert string to number
  let i = 0;
  var dataArray = [];
    fs.createReadStream(filePath)
      .pipe(csv())
      .on('data', (row) => {
        row.timestamp= (intialTimestamp + (i * 20)).toString(); // increase the number by 20 everytime
        dataArray.push(row);
        i++;
      })
      .on('end', () => {
        var result = json2csv({ data: dataArray, fields: Object.keys(dataArray[0]) });
        fs.writeFileSync("test.csv", result);
      });


text:
Q: mod_rewrite - error with 2 variables just a quick one, I'm using this rule and it works fine:
RewriteRule ^([^/.]+)$ /profile.php?id=$1

so whatever come to mysite.com/anything will be read as mysite.com/profile.php?id=anything
That's all good.
Then I need to add another variable so I used:
RewriteRule ^([^/.]+)/([^/.]+)$ /profile.php?id=$1&vid=$2

Which kind of works but it doesn't load any css, js, external php...
I guess that's why it's looking in a different folder, I don't know how to tell it get those other files from the root folder.
Any ideas?

A: That's because you are creating virutal folders using the htaccess. If you want to load your CSS and JS properly, either use absolute paths or add ../ before your relative path (which means "one folder up").
Another possibility is to add <base href="www.example.com">. Which will cause all new requests (for images, external files, etc) to be relative to that path, and not the current address.

A: You can add
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d

to do not rewrite URL if there are files with this URL

A: Add next 2 lines befor RewriteRule
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]


text:
Q: What resource does numpy "lock" across processes? So a friend noticed something curious about numpy. Here is a minimal example that runs the same script first serially, than two instances parallel each in their own process:
#!/bin/bash
# This is runner.sh

fl=/tmp/$(mktemp test_XXXXX.py)
trap "rm -fv '$fl'" EXIT
cat - > "$fl" <<-'EndOfHereDoc'
#!/usr/bin/env python
import numpy as np
import sys

if __name__ == '__main__':
    if len(sys.argv)>1: print(sys.argv[1] +' start: '+ str(datetime.datetime.now()))
    cube_size=100
    cube=np.zeros((cube_size,cube_size,cube_size))
    cube_ones=np.ones((cube_size,cube_size,cube_size))

    for x in range(10000):
        np.add(cube_ones,cube,out=cube)
    if len(sys.argv)>1: print(sys.argv[1] +' start: '+ str(datetime.datetime.now()))
EndOfHereDoc

echo "Serial"
time python "$fl" 0
echo

echo "Parallel"
time python "$fl" 1&
time python3 "$fl" 2&
wait

rm -fv "$fl"
trap '' EXIT

The output of which is:
$ runner.sh
Serial
0 start: 2018-09-19 15:46:52.540881
0 end: 2018-09-19 15:47:04.592280

real    0m12,105s
user    0m12,084s
sys 0m0,020s

Parallel
1 start: 2018-09-19 15:47:04.665260
2 start: 2018-09-19 15:47:04.780635
2 end: 2018-09-19 15:47:27.053261

real    0m22,480s
user    0m22,448s
sys 0m0,128s
1 end: 2018-09-19 15:47:27.097312

real    0m22,505s
user    0m22,409s
sys 0m0,040s
removed '/tmp/test_zWN0V.py'

No speedup. It is as if the processes where run one after the other. I assume numpy is using a resource exclusively and the other process waits for that resource to be freed. But what exactly is going on here? The GIL should only be an issue with multi-threading, not multiple processes, right? I find it especially weird, that p2 is not simply waiting for p1 to finish. Instead BOTH processes take ~22s to finish. I'd expect one to get the resource and finish in half the time. While the other waits until the first releases it and takes an additional ~12s.
Note that this also ocours when running the python code with python's own multiprocessing module in a Pool. It does however not occur, if you do something that doesn't involve some specific numpy functions like:
cube_size=25
cube=[0 for i in range(cube_size**3)]

for x in range(10000):
    cube = [ value + 1 for value in cube]

Edit:
I have a real 4-core CPU. I kept hyperthreading in mind, it's not the issue here. During the single process part, one CPU is at 100%, the rest idle. During the two process part, two are at 100%, the rest is idle (as per htop). I understand that numpy runs ATLAS, LAPACK and BLAS libraries in the background, which are not Python (in fact pure C or Fortran). These might utilize parallel techniques. My question here is, why doesn't that show up in CPU utilization?

A: Numpy is not restricted by the GIL as much as core Python is. This is because numpy only stores the array as a Python object. The actual data itself is stored as "primitive" types defined in C. This is also why iterating over a numpy array is much slower than iterating over a Python list. The numpy array has to build a Python object for each value it yields, whereas the Python list already has Python objects.
As numpy is not hampered by the GIL, it is able to use threaded math libraries where available. That is to say, your parallel processes took longer to run because each process was already maxing out your machine and so both processes were competing for the same resources.
Take a look at the output and see what's available in your machine (be warned it's quite verbose).
import numpy.distutils.system_info as sysinfo
sysinfo.show_all()


text:
Q: Android Studio error : Invalid content found from the 'base-extension' element I am trying to compile an Android Application on Android Studio and I get this error:
cvc-complex-type.2.4.a: Invalid content found from the 'base-extension' element. One of the values '{layoutlib}' is expected.
Do you know where this could come from?


text:
Q: How do you post an array field with Guzzle? How do you post an array field with Guzzle? I have tried the following but nothing is received in the fruits variable.
$fruits = ['apple', 'orange', 'banana'];
$client   = new \GuzzleHttp\Client();
$response = $client->post('http://example/post', [
   'form_params' => [ 'fruits' => $fruits ]
] );


text:
Q: Every Point on a Surface is a Boundary point or a Interior Point I would like to prove that any point on a (regular) surface of dimension $k$ is either a boundary point of the surface or an interior point. I have the definitions as follows:
A regular surface with boundary of dimension $k$ is a set $S$ where for each point p in $S$ we have an open neighborhood $V \subset \mathbb{R}^n$ containing $p$ and an open set $U$ with injective $C^1$ mapping $\phi:U \to \mathbb{R}^n$ ($U \subset \mathbb{R}^k$) such that one of the following is true:

*

*If $p$ is an interior point we have that $\phi(U) = S \cap V$

*If $p$ is a boundary point, we have that $\phi (U\cap \{u_k \geq 0\}) = S \cap V$ and that $p \in \phi(U \cap \{u_k = 0\})$

In the second line, the first part says that the image of $\phi$ under the half plane is equal to the intersection of some open ball with the manifold, and the second part says that our point lies on the very bottom of the half plane.
I was hoping that someone could help me prove that there are no points that are both boundary and interior points at once.


text:
Q: Discord channel category name not found even though it exists Im using the lastest Discord.js 14 and trying to create a new channel in the support category.
I manually created the category so I know it exists.
There are no channels in this category at present and this new channel the bot is trying to create will be the first one.
When I run this code console.log(supportCategory) the terminal shows undefined
Why?
// Require the necessary discord.js classes
const { Client, Events, GatewayIntentBits, ChannelTypes } = require('discord.js');
const { token } = require('./config.json');

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

// When the client is ready, run this code (only once)
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
client.once(Events.ClientReady, c => {
    console.log(`Ready! Logged in as ${c.user.tag}`);

});

client.on('ready', async () => {
  console.log(`Logged in as ${client.user.tag}!`);
  const guild = client.guilds.cache.first();
  const supportCategory = guild.channels.cache.find(channel => channel.type === 'GUILD_CATEGORY' && channel.name === 'Support');

  console.log(supportCategory) //this produces undefined

  try {
    const channel = await guild.channels.create('new-channel-name', {
      type: 'GUILD_TEXT',
      parent: supportCategory.id,
      permissionOverwrites: [
        {
          id: guild.roles.everyone.id,
          deny: ['VIEW_CHANNEL'],
        },
      ],
    });
    console.log(`Channel created: ${channel.name}`);
  } catch (error) {
    console.error(error);
  }
});

// Log in to Discord with your client's token
client.login(token);

A: You need to use the ChannelType enum to check a channel's category.
const supportCategory = guild.channels.cache.find(channel => channel.type === ChannelType.GuildCategory && channel.name === 'Support');


text:
Q: Assigning attributes to JRadio Buttons in Java Swing i am trying to link JRadioButton to an interface and a method that implements that interface. i have two modes which are the attacking and defensive mode and i want the user to be able to click the attack toggle button and have it enabled and when its unclicked then it activates the defensive mode
Code from the class
public class AttackMode implements GameBehaviour {

    public boolean behaviourMode(int numOfShips) {
        if(numOfShips < 3){
            return true;
        }
        return false;
    }

}

Code From Java Swing GUI

private JRadioButton getRdbtnDefensiveMode() {
        if (rdbtnDefensiveMode == null) {
            rdbtnDefensiveMode = new JRadioButton("Defensive Mode");
            rdbtnDefensiveMode.setEnabled();
            rdbtnDefensiveMode.addItemListener(new ItemListener() {

                public void itemStateChanged(ItemEvent arg0) {
                    if (arg0.getStateChange() == ItemEvent.SELECTED) {
                         theRules.theMasterShip.setBadAssBehaviour(new DefenceMode());
                         rdbtnAttackMode.setSelected(false);
                    }else if (arg0.getStateChange() == ItemEvent.DESELECTED) {

                         theRules.theMasterShip.setBadAssBehaviour(new AttackMode());
                         rdbtnAttackMode.setSelected(true);
                    }
                    return;
                }
            });
            rdbtnDefensiveMode.setFont(new Font("Trebuchet MS", Font.BOLD | Font.ITALIC, 11));
            rdbtnDefensiveMode.setBounds(658, 355, 109, 23);
        }
        return rdbtnDefensiveMode;
    }

private JRadioButton getRdbtnAttackMode() {
        if (rdbtnAttackMode == null) {
            rdbtnAttackMode = new JRadioButton("Attack Mode");
            rdbtnAttackMode.addItemListener(new ItemListener() {
                public void itemStateChanged(ItemEvent arg0) {
                    if (arg0.getStateChange() == ItemEvent.SELECTED) {
                         theRules.theMasterShip.setBadAssBehaviour(new AttackMode());
                         rdbtnDefensiveMode.setSelected(false);
                    }else if (arg0.getStateChange() == ItemEvent.DESELECTED) {

                         theRules.theMasterShip.setBadAssBehaviour(new DefenceMode());
                        rdbtnDefensiveMode.setSelected(true);
                    }
                }
            });
            rdbtnAttackMode.setFont(new Font("Trebuchet MS", Font.BOLD | Font.ITALIC, 11));
            rdbtnAttackMode.setBounds(658, 265, 109, 23);
        }
        return rdbtnAttackMode;
    }

i am expecting that if the attack button is clicked, it should implement the attack method and if unchecked themn it should activate the defence mode button. So one of the buttons must always be enabled

A: Add your buttons to button group
Like this:
ButtonGroup bgroup = new ButtonGroup();
bgroup.add(getRdbtnAttackMode());
bgroup.add(getRdbtnDefensiveMode());

For each button create an ActionListener, and you will be good


text:
Q: How can I rewrite ANY kind of string in htaccess? I'm working on a simple routing system, and I need to make a RewriteRule where EVERYTHING (no exception is being passed as a query parameter to my main php file.
However, ^(.+)$ and ^(.*)$ do not seem to work. The only thing that's being returned using them is '/index.php'.
The only thing that does seem to work is ^([a-zA-Z0-9/_-]*)$, etc., but the thing is: I want this expression to match all Unicode characters, and I assume that an expression which accomplishes this manually would be very slow and inelegant.
So... why do these allegedly obvious expressions not work properly?
Thanks in advance.
RewriteEngine on
RewriteRule ^(.*)$ index.php?path=$1 [L,QSA]

A: You can use this rule :
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php?path=%{REQUEST_URI} [L,QSA]


text:
Q: SQL Server PIVOT Table: Incorrect Syntax I need your help guys, I cant seem to figure out whats the problem with my pivot script in SQL Server

Error Message: Incorrect syntax near '20170615'. Severity 15

SELECT *
FROM rev_trans
PIVOT (SUM(ABS_AMT)
   FOR [BOOKING DATE] in ('20170614')) AS pvt

Thank You for your help


text:
Q: Flexible Search query to select entity based on dependent I have User with Orders. I want to select all users who:
1. Don't have orders at all
2. Do not have orders greater than x date (so if user have 10 orders, and one of them lesser than passed date - I still need this user.
3. Add more conditions to result
I've done this, but it's not working the way I need. First I join all orders with LEFT join, then check - if order greater than passed date - I do not pick an item. Last "or" check I already confused myself, not sure what it's doing (we can't have order without user)
select {c.pk}
from {User as c
left join Order as ord on {c.pk}={ord.user}}
where not exists
({{
  select {o.date} from {Order as o} where {o.date} >='24-Oct-2017'
}})
or {ord.user} is null

A: In your SubQuery the user check is missing. Add {o.user} = {c.pk} to it.


text:
Q: Codeigniter Download Helper corrupts .7z and .rar files help or alternative solutions? I am using Codeigniter's Download helper for "easy" downloading.
    $this->load->helper('download');
    $file = //get_file_name_from_db
    $data = file_get_contents( upload_path . $file);
    force_download($file, $data);

The problem that I have is that any .zip is downloading correctly while .7z and .rar are not. However when I check the uploaded files to see it they are corrupted or not they are fine (via FTP or in local by simply checking the folders).
To add to the confusion if a file is really small (like 5kb or so) then none of the types (7z and rar) will be corrupted.
For the reference here is the mime types I use in mime.php (that both upload and download helper use)
'zip'   =>  array('application/x-zip', 'application/zip', 'application/x-zip-compressed'),
'7z'    =>     array('application/x-7z-compressed','application/x-7z',      'application/7z', 'application/force-download', 'application/octet-stream'),
'rar'   =>  array('application/x-rar-compressed','application/x-rar', 'application/rar', 'application/octet-stream')

THe problem might be at two points, either the mime types (which it probably isn't since as noted, on very small file sizes it works). Or the file_get_contents() and the header("Content-Length: ".strlen($data)); which might not be so since regardless of size .zip will always download correctly.
Or might it be a sever config problem? I tested it both on a host and at localhost and they behave the same.
So does anybody knows what the problem is or can they suggest an alternative download script or method I should use?
UPDATE:
I uploaded a 7z file on the host with the size of 1.8 MB and when downloaded the file wasn't corrupted... I am having harder and harder time understanding what is the problem.
UPDATE:
Found the answer it was a value that was on top of the file form the some connected method where I have echoed a value in order to check it some time ago.
For more here:
What causes downloaded files to become corrupt?

A: I dont think there is inbuild library in PHP for generating 7z or rar files like zip/gzip. You might need to use external library for this if it is there.


text:
Q: No horizontal scrollbar when printing dataframe in jupyter When printing a pandas dataframe in jupyter, no horizontal scroll is created, instead columns that don't fit are printed after the columns that fit.
Toy example:
d = {'long_column_name1': [1, 2,3,4,5,6,7,8,9],
     'long_column_name2': [1, 2,3,4,5,6,7,8,9],
     'long_column_name3': [1, 2,3,4,5,6,7,8,9],
     'long_column_name4': [1, 2,3,4,5,6,7,8,9],
     'long_column_name5': [1, 2,3,4,5,6,7,8,9],
     'long_column_name6': [1, 2,3,4,5,6,7,8,9],
     'long_column_name7': [1, 2,3,4,5,6,7,8,9],
     'long_column_name8': [1, 2,3,4,5,6,7,8,9]}
df = pd.DataFrame(data=d)
print(df)

In this case there are only 9 rows, and 8 columns, which is still readable, but having more rows and columns will make it really hard to read.
Is there a way that all columns are printed horizontally, adding an horizontal scrollbar if needed?

A: You can try df instead of print(df). Which makes it scrollable.
And if you want the columns to be printed horizontal you could use df.transpose().

A: (in Jupyter without print() )
change the pandas option settings
like:
pd.set_option('display.max_columns', 70)

for printing all (string-)content in a cell:
pd.set_option('display.max_colwidth', None) # for pandas >= 1.x

or temporarily (in  with statement) :
with pd.option_context("display.max_rows", 8, "display.max_columns", 90):
     print(pd.get_option("display.max_rows")
     print(pd.get_option("display.max_columns"))
# back in general setting
print(pd.get_option("display.max_rows"))


text:
Q: Can an unbounded sequence have a convergent cesaro mean? I was wondering if an unbounded sequence may have a convergent cesaro mean ($\frac{1}{n}\sum_{k=1}^n a_n$). I was maybe thinking of $$a_n = (-n)^n$$
as a sequence having a convergent mean, but I might be wrong. Anyways, how would you proceed to prove such an intuition?

A: Here's an example where all $a_n$ are nonnegative. If $n = 2^m, m = 1,2, \dots ,$ define $a_n = m.$ For all other $n$ define $a_n =0.$  Then $(a_n)$ is unbounded. But if $2^m\le n < 2^{m+1},$ then
$$\frac{a_1 + \cdots + a_n}{n} \le \frac{1 + 2 + \cdots + m}{2^m} = \frac{m(m+1)/2}{2^m}.$$
The fraction on the right $\to 0$ as $m\to \infty,$ showing the Cesaro means $\to 0.$

A: Here is another example following the same basic idea that zhw gave, but with non-zero limit:
For a given $n$, determine the highest power of $2$ that divides $n$,  say $2^m$. Define $a_n:=m$. So we are talking about the sequence:
$$
\begin{array}{|c|c|}
\hline
n&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16&...\\
\hline
a_n&0&1&0&2&0&1&0&3&0&1&0&2&0&1&0&4&...\\
\hline
\end{array}
$$
The idea is that $1/2$ of the sequence is at least $1$, $1/4$ is at least $2$, $1/8$ is at least $3$ etc. so on average we have $1/2+1/4+1/8+...=1$ as the Cesaro mean in the limit, as I will show in detail below.

Then it turns out that
$$
\sum_{k=1}^n a_k=\sum_{m=1}^{\lfloor\log_2 n\rfloor}\lfloor n/2^m\rfloor
\approx n
$$
Each term in the last sum will differ less than $1$ from the content of the floor function
$$
\lfloor n/2^m\rfloor\in(n/2^m-1,n/2^m]
$$
and so
$$
\sum_{m=1}^{\lfloor\log_2 n\rfloor}\lfloor n/2^m\rfloor
>\sum_{m=1}^{\lfloor\log_2 n\rfloor} (n/2^m-1)
=\sum_{m=1}^{\lfloor\log_2 n\rfloor} n/2^m-\lfloor\log_2 n\rfloor
$$
and since
$$
\sum_{m=1}^t n/2^m=n-\frac{n}{2^t}
$$
we have
$$
\sum_{m=1}^{\lfloor\log_2 n\rfloor} n/2^m-\lfloor\log_2 n\rfloor=n-\frac{n}{2^{\lfloor\log_2 n\rfloor}}-\lfloor\log_2 n\rfloor
$$
On the other hand $\sum_{m=1}^\infty n/2^m=n$ is an upper bound on this sum from which it follows that
$$
n-\frac{n}{2^{\lfloor\log_2 n\rfloor}}-\lfloor\log_2 n\rfloor\leq\sum_{k=1}^n a_k\leq n
$$
Hence it should be evident that $\frac1n\sum_{k=1}^n a_k\to 1$. Finally, note that $a_{2^m}=m$ so $\{a_n\}$ is unbounded.

Multiplying the sequence from above by any $c\in\mathbb R$ we can construct a non-bounded sequence with Cesaro means converging to that $c$.

A: Take the following example
$u_{2n}=-\sqrt{n}$
and
$u_{2n+1}=\sqrt{n}$
then
$v_{2n}=0$
and
$v_{2n+1}=\frac{\sqrt{n}}{2n+1}$.
$(u_n)$ is unbounded.
$(v_n)$ goes to $0$.


text:
Q: 4 6v batteries, with one connected wrong way round? Today i was working on a machine with 4 6v batteries connected in series.
It was in a building that was very dark and the batteries were covered in dirt and i briefly accidently fitted one of the batteries the wrong way around.
After i corrected the mistake i couldnt get 24v across the four batteries, only 18v, from wherever that battery was out of the voltmeter circuit.
Yet the same battery measured 6v on the meter, and load tested ok.
Could the polarity have been reversed on that battery after connecting it the wrong way around?
If so, does charging the 4 batteries in series correct this reverse polarity.
Thanks


text:
Q: Trying to manipulate lines in a document with regex I have a text document that was poorly formatted for my purposes, and I had to make some changes. But now I have another problem, which is a lot of sentences "stranded" on their own, like this:
    \n
    [some text here, bla bla bla.]\n
    \n

Does anyone know of a way to represent a sentence with regular expressions? I want to join these sentences with the paragraph above or below.
I swear I searched both Google and this site before asking.
Edit:
Sorry, I lost access to my original post, and couldn't comment on Amber's answer. I'll register an account for future questions.
Plus, I neglected to mention the fact that I'm using Notepad++.

A: How about looking for any pair of newlines with only a single terminating punctuation mark between them? E.g.
\n([^\n.?!]+[.?!][^\n.?!]*)\n

and then just replace that with...
'\n\1 '


text:
Q: filling existing dataframe with rows from loop I tried going over How to build and fill pandas dataframe from for loop? but cant seem to write my values to my columns.
Ultimately I am getting data from a webpage and want to put it into a dataframe.
my headers are predefined as:
d1 = pd.DataFrame(columns=['col1', 'col2', 'col3', 'col4', 'col5', 'col6', 'col7', 'col8', 'col9',
        'col10', 'col11', 'col12', 'col13', 'col14', 'col15', 'col16', 'col17'])

now I have values I get in a for loop, how can I write these rows to each column then repeat back to column 1 to 17 and then next row?
row = soup.find_all('td', attrs = {'class': 'Table__TD'})
for data in row:
    print(data.get_text())

sample output row 1
Mon 11/11
SA
100
31
3-5
60.0
1-3
33.3
1-2
50.0
10
4
0
1
1
2
8

Sample output row 2
Wed 11/13
@CHA
W119-117
32
1-5
20.0
1-5
20.0
0-0
0.0
3
1
0
1
3
3
3

Expected output

Any help would be appreciated.

A: First we have list for column names:
cols = ['col1', 'col2', 'col3', 'col4', 'col5', 'col6', 'col7', 'col8', 'col9',
        'col10', 'col11', 'col12', 'col13', 'col14', 'col15', 'col16', 'col17']

Then list for values:
row = [x.get_text() for x in soup.find_all('td', attrs = {'class': 'Table__TD'})]
print(row)
# ['Mon 11/11', 'SA', '100', '31', '3-5', '60.0', '1-3', '33.3', '1-2', '50.0', '10', '4', '0', '1', '1', '2', '8']

Then we can zip the columns and the values together, then append to the dataframe:
d1 = d1.append(dict(zip(cols, row)), ignore_index=True)
print(d1)
#         col1 col2 col3 col4 col5  col6 col7  col8 col9 col10 col11 col12  \
# 0  Mon 11/11   SA  100   31  3-5  60.0  1-3  33.3  1-2  50.0    10     4
#
#   col13 col14 col15 col16 col17
# 0     0     1     1     2     8

A: You can try this,
import pandas as pd

columns = [
    'col1',
    'col2',
    'col3',
    'col4',
    'col5',
    'col6',
    'col7',
    'col8',
    'col9',
    'col10',
    'col11',
    'col12',
    'col13',
    'col14',
    'col15',
    'col16',
    'col17',
]

# create dataframe
d1 = pd.DataFrame(columns=columns)

full = []

for data in soup.find_all('td', attrs={'class': 'Table__TD'}):
    full.append(data.get_text())

# seperate full list into sub-lists with 17 elements
rows = [full[i: i+17] for i in range(0, len(full), 17)]

# append list of lists structure to dataframe
d1 = d1.append(pd.DataFrame(rows, columns=d1.columns))

A: Appending data to an existing DataFrame is really slow.
You better created a list of data from soup, creating a new dataframe, then concat the new data frame to your old one
This is a quick benchmark, using an empty df for each case. In your real code, df should be your existing dataframe:
# setup some sample data
headers = ['col1', 'col2', 'col3', 'col4', 'col5', 'col6', 'col7',
           'col8', 'col9', 'col10', 'col11', 'col12', 'col13', 'col14',
           'col15', 'col16', 'col17']
raw_data = 'Mon 11/11,SA,100,31,3-5,60.0,1-3,33.3,1-2,50.0,10,4,0,1,1,2,8'.split(",")
row_dict_data = dict(zip(headers, raw_data))

# append
%%time
df = pd.DataFrame(columns=headers)
for i in range(100):
    df = df.append([row_dict_data])

# CPU times: user 258 ms, sys: 4.82 ms, total: 263 ms
# Wall time: 261 ms

# new dataframe
%%time
df = pd.DataFrame(columns=headers)
df2 = pd.DataFrame([raw_data for i in range(100)], columns=headers)
df3 = pd.concat([df, df2], sort=False)

# CPU times: user 7.03 ms, sys: 1.16 ms, total: 8.2 ms
# Wall time: 7.19 ms


text:
Q: AngularJS : Expose ng-repeat scope to ng-transclude I'm having a template with the following structure (address-contact-info.html):

And a directive:
{
    templateUrl: 'address-contact-info.html',
    restrict: 'A',
    scope: {
        contactInfo: '='
    },
    transclude: true,
    link: function (scope, elem, attrs, ctrl, transclude) {
        scope.displayedItems = 1;
    }
};

I want to use the directive like this:

    {{contact.number}}

This means I want to access the ng-repeat scope inside my transcluded elements, but I don't know how to do that.
Do you have any idea how to achieve this, or is there a better way to do that?
Thanks for your help!
Update
Here a plunker: http://plnkr.co/edit/4DYEUhHAPuJOLyG9omCT
Update
I found a solution that works for me, though I still have one problem.
The elements I want to transclude in the template have their own directives which require a parent directive.
Now when I call the transcludeFn inside my linkFn, I get the following error:
Error: [$compile:ctreq] Controller 'editableGroup', required by directive 'editable', can't be found!

http://plnkr.co/edit/zriVyS7MzheSI8jcYM5d
In this plunker I haven't included the other directives, but I get a transcludeFb related error as well.
Cannot set property 'nodeValue' of undefined

A:

    {{contact.number}}

This snippet will be compiled with the scope of the controller which doesn't have a reference to contact.
Hence the ng-repeat is not able to display any data.
Even the transcluded content will be compiled with the controller's scope. Not with the scope of the directive.
A hack for this is:
http://plnkr.co/edit/clrchL1HLtFQLZ4fctZx?p=preview
This may not be the correct/proper solution.


text:
Q: node express - verify user deleting entry is the person who created it I am very new to coding in general a network person for 20 years+ but giving this a go as something to learn so please be gentle :-). This is my first time asking for help.
I am creating a node js with express back end and I am using VUE 3 for the front end.  I have user authentication setup and working as I want.
I am now trying to add a simple post feature.  Users can create posts and view other users posts.  An admin user can delete all posts but a normal user can't delete their own posts with the checks I am trying to put in place.
Post Controller
function _delete(req, res, next) {
    postService.getPost(req.params.id)
        .then(...post)
        .catch(next);

        if (Number(post)(post.accountId) !== req.user.id && req.user.role !== Role.Admin) {
        return res.status(401).json({ message: 'Unauthorized' });
    }

    postService.delete(req.params.id)
        .then(() => res.json({ message: 'Post deleted successfully' }))
        .catch(next);

Post Services
async function _delete(id) {
    const post = await getPost(id);
    await post.destroy();
}

async function getPost(id) {
    const post = await db.Post.findByPk(id);
    if (!post) throw 'Post not found';
    return post;
}

The bit I am struggling with is trying to get the return "post" from the getPost function and use that in the if statement in the delete function.
Would be grateful for some assistance.
Many Thanks
Steve


text:
Q: Does ArcPy (Standalone) have option like Spatial filter? I want to get the polyline features intersecting with a polygon geometry and having a particular field values in ArcPy standalone script.
There is another link for similar subject but it is not for standalone script.
Does ArcPy have a spatial search function for geometry?
Does ArcPy have a similar option for SearchCursor like Spatialfilter with whereclause, searchGeometry and relation?

A: Just create layers using arcpy.management.MakeFeatureLayer(). You can add an SQL attribute filter to each function. These are very fast because they don't actually copy the data.
Then you can use the function arcpy.Management.SelectByLocation()
There are endless combinations you can use by adding or subtracting layer sets. Each function can use the previous layer.
If the attributes are too complex for an SQL query then consider using a separate query and use an IN sql query with a list of key or OBJECTIDS. I use a SearchCursor inside a list comprehension that is converted to a tuple string. This can be used to create an expression line this
select_lay = arcpy.management.SelectByLocation('lay1', lay2, 'select_lay', 'NEW_SELECTION')
tuple = tuple([row[0] for row in arcpy.da.SearchCursor('select_lay', [key'])])
SQL_expr = """key IN {}""".format(tuple)
lay_2 = arcpy.management.MakeFeatureLayer('a_fc', ['field1'],SQL_expr)

A: Got the solution by doing similarly as suggested under "MakeFeatureLayer example 2 (stand-alone script)" in https://pro.arcgis.com/en/pro-app/tool-reference/data-management/make-feature-layer.htm
The below is the arcgis code sample:
import arcpy
arcpy.env.overwriteOutput = True
arcpy.MakeFeatureLayer_management("C:/data/mexico.gdb/cities","cities_lyr")
arcpy.SelectLayerByLocation_management("cities_lyr", "INTERSECT", "c:/data/mexico.gdb/chihuahua", "", "NEW_SELECTION")
arcpy.SelectLayerByAttribute_management("cities_lyr", "SUBSET_SELECTION", "POPULATION > 10000")
arcpy.CopyFeatures_management("cities_lyr", "c:/data/mexico.gdb/chihuahua_10000plus")


text:
Q: Spring Boot (or mvc), OSGI integration : Dynamically creating objects for dynamic OSGI modules I have a requirement to load dynamic modules on a Spring Boot Microservice. i.e Assume I have a MicroService called ProductService that will create different kind of products. And assume that I want to dynamically add products so there I use OSGI product modules.
So if I add ProductXYZ as a OSGI module and how can I call a method on that module via Spring boot REST API. i.e
/products/id/description?name=ProductXYZ
Here the issue is, in Spring Boot (even Spring web MVC) these rest calls are handle in the controller. And to get description of ProductXYZ I should create an object of ProductXYZ in the controller. But when coding the controller class it is impossible to call "new ProductXYZ()" as we don't have ProductXYZ when coding controller. We have ProductXYZ in later after we add osgi ProductXYZ module.
Thanks.


text:
Q: Calculating variance with large numbers I haven't really used variance calculation that much, and I don't know quite what to expect. Actually I'm not too good with math at all.
I have a an array of 1000000 random numeric values in the range 0-10000.
The array could grow even larger, so I use 64 bit int for sum.
I have tried to find code on how to calc variance, but I don't know if I get correct output.
The mean is 4692 and median is 4533. I get variance 1483780.469308 using the following code:
// size is the element count, in this case 1000000
// value_sum is __int64

double p2 = pow( (double)(value_sum - (value_sum/size)), (double)2.0 );
double variance = sqrt( (double)(p2 / (size-1)) );

Am I getting a reasonable value?
Is anything wrong with the calculation?

A: Note: It doesn't look like you're calculating the variance.
Variance is calculated by subtracting the mean from every element and calculating the weighted sum of these differences.
So what you need to do is:
// Get mean
double mean = static_cast<double>(value_sum)/size;

// Calculate variance
double variance = 0;
for(int i = 0;i<size;++i)
{
  variance += (MyArray[i]-mean)*(MyArray[i]-mean)/size;
}

// Display
cout<<variance;

Note that this is the sample variance, and is used when the underlying distribution is unknown (so we assume a uniform distribution).
Also, after some digging around, I found that this is not an unbiased estimator. Wolfram Alpha has something to say about this, but as an example, when MATLAB computes the variance, it returns the "bias-corrected sample variance".
The bias-corrected variance can be obtained by dividing by each element by size-1, or:
//Please check that size > 1
variance += (MyArray[i]-mean)*(MyArray[i]-mean)/(size-1);

Also note that, the value of mean remains the same.

A: First of all, if you're just looking to get a handle on what is a "reasonable" variance, keep in mind that variance is basically standard deviation squared. Standard deviation roughly measures the typical distance from a data point to its expected value.
So if your data has mean 4692, and your calculated variance is coming out to 1483780, that means your standard deviation is about 1218, which would suggest your numbers tend to be somewhere in the vicinity of the range 3474 - 5910. So that variance actually seems a bit low to me if the range of your numbers is 0 - 10000; but it obviously depends on the distribution of your data.
As for the calculation itself: You can calculate the variance using a running calculation as you're reading your data the first time around (you don't have to know the mean in advance) using Welford's Method:

Initialize M1 = x1 and S1 = 0.
For subsequent x's, use the recurrence
  formulas
Mk = Mk-1+ (xk - Mk-1)/k Sk = Sk-1 +
  (xk - Mk-1)*(xk - Mk).
For 2 ≤ k ≤ n, the kth estimate of the
  variance is s2 = Sk/(k - 1).

A: Just for fun, a slightly different route to the same result, using std::valarray instead of std::vector and (various) algorithms:
template <class T>
T const variance(std::valarray<T> const &v) {
    if (v.size() == 0)
        return T(0.0);
    T average = v.sum() / v.size();
    std::valarray<T> diffs = v-average;
    diffs *= diffs;
    return diffs.sum()/diffs.size();
}

As Jacob hinted, there are really two possible versions of a variance calculation. As it stands, this assumes your inputs are the "universe". If you've taken only a sample of the overall universe, the last line should use: (diffs.size()-1) instead of diffs.size().

A: Use a different formula maybe?
#include <functional>
#include <algorithm>
#include <iostream>
int main()
{
 using namespace std;

 vector<double> num( 3 );
 num[ 0 ] = 4000.9, num[ 1 ] = 11111.221, num[ 2 ] = -2;

 double mean = std::accumulate(num.begin(), num.end(), 0.0) / num.size();
 vector<double> diff(num.size());
 std::transform(num.begin(), num.end(), diff.begin(),
                std::bind2nd(std::minus<double>(), mean));
 double variance = std::inner_product(diff.begin(), diff.end(),
                                     diff.begin(), 0.0) / (num.size() - 1);
 cout << "mean = " << mean << endl
      << "variance = " << variance << endl;
}

Outputs:
    mean = 5036.71
    variance = 3.16806e+07

A: Sample Variance calculation:
#include <math.h>
#include <vector>

double Variance(std::vector<double>);

int main()
{
     std::vector<double> samples;
     samples.push_back(2.0);
     samples.push_back(3.0);
     samples.push_back(4.0);
     samples.push_back(5.0);
     samples.push_back(6.0);
     samples.push_back(7.0);

     double variance = Variance(samples);
     return 0;
}

double Variance(std::vector<double> samples)
{
     int size = samples.size();

     double variance = 0;
     double t = samples[0];
     for (int i = 1; i < size; i++)
     {
          t += samples[i];
          double diff = ((i + 1) * samples[i]) - t;
          variance += (diff * diff) / ((i + 1.0) *i);
     }

     return variance / (size - 1);
}

A: Since you're working with large numbers and then doing floating-point operations on them, you might want to do everything in doubles; that would save you a lot of casts.
Using pow .. 2 to calculate a square seems a bit awkward. You could calculate your number first, then multiply it by itself to get a square.
If you're doing division and feel the need to cast, cast the operands (i.e. the numerator and/or denominator) to double rather than the result. You're losing accuracy if you divide integers.
I'm not sure if your formula for variance is correct. You may want to look at the explanation in Wikipedia, for example. But I'm no math expert either, so I'm not sure you have a mistake.

A: Since variance is the square of the standard deviation, the answers to SO 1174984 should help out.  The short diagnosis is that you need to compute the sum of the squares of the values as well as the sum of the values, and you don't seem to be doing that.
Since you have 106 values, and the square of any value can be up to 108, you could end up with a sum of squares up to 1014; your 64-bit integers can store up to 1018, so you could still handle ten thousand times as many inputs, or values ranging up to one million instead of only ten thousand, without running into overflows.  There's no urgent need, therefore, to move to pure double computations.


text:
Q: How to Update this data using SQL?
Possible Duplicate:
How to replace string in SQLite?

I have a table column data as

/var/abc/23423423/Documents/apple.jpg
/var/sdg/64444223/Documents/Banana.jpg

I want to update this column so that anything preceding /Documents is removed.
So output should be:

/Documents/apple.jpg
/Documents/Banana.jpg

How do I achieve this using UPDATE Statement of SQL?

A: Something like this will work:
UPDATE yourtable
SET yourfield = MID(yourfield,INSTR(yourfield,"/Documents/"));

INSTR locates the position of the string /Documents/, and MID gets everything beginning from there.
Notes:

*

*This maybe won't work as you expect it when you have something like
/Documents/Documents/ in your path string.

*Depending on your RDBMS
MID and INSTR may not be available, but most RDBMS support them.

Updates:
After my reply you've updated that SQLite is the RDBMS of your choice - this makes things more difficult. There ain't no INSTR in SQLite, so most people will advise you to parse the result with a program, change it there and update the data then - for example in this SO post.
However... since your two examples both have a fixed directory name length (in total 18 characters), there is the tiny chance that in your case you could do it slightly easier:
UPDATE yourtable
SET yourfield = SUBSTR(yourfield,18);

I haven't tried this yet, but maybe this works for you.