text:
Q: CriteriaBuilder query with sub-query, single column result, max function and generic types using metamodel My objective is to replace an old JPQL query with a generic type-safe helper method using javax.persistence.metamodel and javax.persitence.criteria.
The query is essentially
select * from table
    where field1 = arg1
        and field2 = arg2
        and field3 = (select max (field3)
                        from table
                        where field1 = arg1
                            and field2 = arg2
                            and field3 <= arg3
                     )

Admittedly this is maybe too specialized a query to generalize but I see the need for 2 or 3 other more generic helpers which I can model on this solution.
I have been googling the Criteria documentation (one problem is it's easy to surf a google search result list and mistakenly move from a javax.persitence page to a JBoss Hibernate page... and they are NOT the same).
I have obviously not found a one-stop shop that tells me all I need to know:

*

*how to select a single field in a CriteriaQuery

*how to structure a subquery in a CriteriaQuery Expression

*how to write a max aggregate function call using CriteriaBuilder

*how to properly use Static Metamodel attributes to specify generic classes in a CriteriaBuilder query, when the table being queried has a composite key which is mapped by composite key class (using @EmbeddedId)

A: OK. I already had the answer before I posted the question but I thought it might be useful to publish what I found.
The use case is a CHARGE table that provides CHG_NU values for ranges of product-option-level values. The appropriate
CHG_NU from the table is the one that matches a PROD_CD and OPTION_TYPE and does not exceed the OPTION_LEVEL.
Here's the method I ended up writing (the comments are specific to the above use-case but the code is generic):
public static <X, KT, PT, BT, NT extends Number> X findWithUpperLimit (Class<X> rootClass, Class<NT> numericClass,
                                                                SingularAttribute<X, KT> keyAttr,
                                                                SingularAttribute<KT, PT> arg1Attr, PT arg1Val,
                                                                SingularAttribute<KT, BT> arg2Attr, BT arg2Val,
                                                                SingularAttribute<KT, NT> numericAttr, NT number,
                                                                EntityManager em)
{
    List<X> results;

    CriteriaBuilder cb = em.getCriteriaBuilder ();

    // set up the query (returns a full record of the CHARGE table)...
    CriteriaQuery<X> cq = cb.createQuery (rootClass);
    // ... and the subquery (returns only the BigDecimal OPT_LEVEL)
    Subquery<NT> sq = cq.subquery (numericClass);

    // set up the root objects for the CHARGE table. Both the query and the subquery are on the same table
    Root<X> root = cq.from (rootClass);
    Root<X> sqRoot = sq.from (rootClass);

    // the query objects and the criteria builder are used to structure the query,
    // the root objects are used to get metadata from the table to assign table elements to the criteria

    // the subquery gets the closest optLevel to the passed-in number...
    sq.select (cb.max (sqRoot.get (keyAttr).get (numericAttr)))
                    .where (cb.and
                            (cb.equal (sqRoot.get (keyAttr).get (arg1Attr), arg1Val),
                             cb.equal (sqRoot.get (keyAttr).get (arg2Attr), arg2Val),
                             cb.le (sqRoot.get (keyAttr).get (numericAttr), number)
                ));

    // ...and the main query matches the passed-in prodCd, optType and the optLevel found by the subquery.
    cq.select (root).where (cb.and (cb.equal (root.get (keyAttr).get (arg1Attr), arg1Val),
                                    cb.equal (root.get (keyAttr).get (arg2Attr), arg2Val),
                                    cb.equal (root.get (keyAttr).get (numericAttr), sq)
                                   ));

    results = em.createQuery (cq).getResultList ();

    return results.size() == 0 ? null : results.get (0);
}

This is a code snippet that calls it:
Charge charge = DAOHelper.findWithUpperLimit (Charge.class, BigDecimal.class,
                                                Charge_.key,
                                                ChargeKey_.prodCd, invoice.getCharge().getChargeKey().getProdCd(),
                                                ChargeKey_.optType, invoice.getCharge().getChargeKey().getOptType(),
                                                ChargeKey_.optLevel, invoice.getCharge().getChargeKey().getOptType(),
                                                em);

and here's the SQL that it generates:
select charge0_.OPTION_TYPE_CD as OPTION_1_50_,
            charge0_.OPTION_LEVEL as OPTION_LEV2_50_,
            charge0_.PROD_CD as PROD_CD3_50_,
            charge0_.CHG_NU as CHG_NU4_50_
    from CHARGE charge0_
        where charge0_.PROD_CD=?
            and charge0_.OPTION_TYPE_CD=?
            and charge0_.OPTION_LEVEL=(select max(charge1_.OPTION_LEVEL)
                                            from CHARGE charge1_
                                            where charge1_.PROD_CD=?
                                                and charge1_.OPTION_TYPE_CD=?
                                                and charge1_.OPTION_LEVEL<=1358.00
                                          )


text:
Q: How do I make the "potions" have a limit of 5? I'm doing a battle simulator sort of thing, and I want the player to be able to use potions, which add health, a maximum of 5 times. I also want the player to be able to have the choice to choose different types of items, but those different items cannot be more than five. Here's what I have so far:
import random, sys, time
pokedex = {"Bulbasaur": [200,32,],
       "Ivysaur"  : [230,40],
       "Venusaur" : [270,50],
       "Charmander": [188,30],
       "Charmeleon": [226,40],
       "Charizard": [266,84],
       "Squirtle": [198,48],
       "Wartortle": [228,31],
       "Blatoise": [268,41],
       "Caterpie": [200,15],
       "Metapod": [210,10],
       "Butterfree": [230,22],
       "Weedle": [190,17],
       "Kakuna": [200,12],
       "Beedrill": [240,45],
       "Pidgey": [190,22],
       "Pidgeotto": [236,30],
       "Pidgeot": [276,40],
       "Rattata": [170,28],
       "Raticate": [220,40],
       "Spearow": [190,30],
       "Fearow": [240,45],
       "Ekans": [180,30],
       "Arbok": [230,42],
       "Pikachu": [180,27],
       "Raichu": [230,45],
       "Sandshrew": [210,37],
       "Sandslash": [260,50],
       "Nidoran♀": [220,23],
       "Nidorina": [250,32],
       "Nidoqueen": [290,46],
       "Nidoran♂": [202,28],
       "Nidorino": [232,36],
       "Nidoking": [272,51],
       "Clefairy": [250,22],
       "Clefable": [300,35],
       "Vulpix": [186,20],
       "Ninetales": [256,38],
       "Jigglypuff": [340,22],
       "Wigglytuff": [390,35],
       "Zubat": [190,22],
       "Golbat": [260,40],

       }
   enemy = random.choice(list(pokedex.keys()))
   enemy = [enemy, pokedex[enemy][0]]
   player = random.choice(list(pokedex.keys()))
   player = [player, pokedex[player][0]]
   print("Your pokemon is: %s" % (player[0]))
   print("The enemy's pokemon is: %s" % (enemy[0]))

   while(player[1] > 0 and enemy[1] > 0):
       if pokedex[player[0]][1] < enemy[1]:
           choice = input("What would you like to do?")
           if choice in ["Attack","attack","Kill","kill"]:
               print("The player has attacked the enemy's %s." % (enemy[0]))
               enemy[1] -= pokedex[player[0]][1]
               print("The enemy's %s has %d HP remaining!" % (enemy[0], enemy[1]))
           if choice in ["potion","Potion"]:
                player[1] = player[1]+20
       else:
           enemy[1] = 0
           print("The enemy's %s has %d HP remaining!" % (enemy[0], enemy[1]))
           print("The player's %s has won!" % (player[0]))
           break
    if pokedex[enemy[0]][1] < player[1]:
        print("The enemy has attacked the player's %s." % (player[0]))
        player[1] -= pokedex[enemy[0]][1]
        print("The player's %s has %d HP remaining!" % (player[0], player[1]))
    else:
        player[1] = 0
        print("The player's %s has %d HP remaining!" % (player[0], player[1]))
        print("The enemy's %s has won!" % (enemy[0]))
        break

The formatting is a little weird, but I assure you that it works on my end, and the only thing that need is the potion problem above. Any help is greatly appreciated!

A: The simple solution is to track how many potions have been used, and to use some sort of conditional (if/while) centered around comparing that value to 5. Something like:
     potions_used = 0

     if choice in ["potion","Potion"]:
         if (potions_used <= 5):
            player[1] = player[1]+20
            potions_used += 1

A: Create a player object which has a list of items that the player owns.
Create a method for adding items to that list. In this method, you can now check the number of items before adding them to the list.
class Player(object):
    __slots__ = ['items', 'potions']

    MAX_POTIONS = 5

    def __init__(self):
        self.items = []
        self.potions = Player.MAX_POTIONS

    def use_potion():
        # Here you can check if the number of potions you have
        # has reached zero
        pass

    def add_item(item):
        # Here you can check the number of items the player has
        pass

A: keep track of a variable, "potionsUsed" or something similar, increment it each time a potion is used, when it hits 5, don't allow the player to use potions.
if (choice in ["potion","Potion"]) && (potionsUsed < 5):
            player[1] = player[1]+20

Something like that

redpajama_set_name: RedPajamaStackExchange


text:
Q: Is it possible to share a variable between conftest and pytest_runtest_makereport in pytest I want to initialize a number and use it in pytest_runtest_makereport function.
When I initialize in my_dict = {"num": 1} and try to access in pytest_runtest_makereport I am not able to access this in pytest_runtest_makereport.
Is it possible How can I do it? and example would help


text:
Q: PHP pagination in php application I use the PHP-MVC (https://github.com/panique/mini) for small projects, mostly just for structure as I like the design pattern but I'm struggling to implement a pagination class I always use into it. I use the following: https://daveismyname.com/pagination-with-a-php-class-bp#.VNzLzZ2sWWA
I load the class via the application.php basically a bootstrap file to load the class and a few others. In my model I have the following:
    public function pagi()
{

    $pages = new Paginator('30','p');

    //get number of total records
    $sql = 'SELECT count(id) FROM albums';
    $query = $this->db->prepare($sql);
    $query->execute();
    $row = $query->fetch(PDO::FETCH_NUM);
    $total = $row[0];

    //pass number of records to
    $pages->set_total($total);

    $sql = 'SELECT * FROM albums '.$pages->get_limit();
    $query = $this->db->prepare($sql);
    $query->execute();
    $data = $query->fetchAll();

    //create the page links
    echo $pages->page_links();

    return $data;
}

In my controller I'm calling the following:
$albums_model = $this->loadModel('AlbumsModel');
$albums = $albums_model->pagi();

And in my view (for debug purposes) i'm simply looping over this:
<?php
print_r($albums);
?>

Now the part that's bugging me and I'm not sure how to do is this part in the model:
echo $pages->page_links();

Obviously I shouldn't be echoing output directly from a model anyway but I'm unsure of the best way to implement this into the views?

A: Its okay I've figured it out now, I just return a multidimensional array like so:
return array('pages' => $pages, 'data' => $data);

Then in the controller pick these arrays up and separate them into two variables which are passed to the view:
$arrays = $albums_model->pagi();
$albums = $arrays['data'];
$pages = $arrays['pages'];

And then simply loop over or echo out when needed.


text:
Q: Как выбрать запись, если запросом найдена только одна запись, если больше, вернуть 0 записей? Как запросом вернуть одну запись, если по условию выборки найдена только одна запись, если больше, то запрос должен вернуть 0 записей?
То есть, для следующего запроса ожидаю:
create table t (val) as
    select 1 from dual union all
    select 1 from dual union all
    select 2 from dual;

select * from t
where val = 1;

no rows selected

Свободный перевод вопроса How to select a record if the query returns one row, or select no record if the query returns more rows от участника @Stalin Gino

A: В SQL запросе можно сделать что-то вроде:
select *
from (
    select t.*, count(*) over () total
    from t
    where val = 1
    and rownum <= 2
) where total= 1;

no rows selected

Обратите внимание, что смысл предиката rownum <= 2 заключается в том, чтобы прервать выполнение запроса, если по условию выборки в промежуточном наборе результата будет более 2 записей. То есть, COUNT посчитает максимально две записи, иначе, если по условию выборки будет найдено миллионы строк, то БД сначалa посчитает их все, а затем отбросит, что разумеется крайне неэффективно.
Если запрос в PL/SQL, то при выборке в переменную с INTO var возникнет исключение TOO_MANY_ROWS, если найдено более одной записи:
declare
    var t%rowtype;
begin
    select * into  var
    from t
    where val = 1;
end;

Свободный перевод ответа от участника @Chris Saxon


text:
Q: Is it safe to use global variable to share objects between functions in Dart? I see that "Dart is a single-threaded programming language", so I think is it safe to use global variable to pass data between functions:
var g = 1;

main() {
   hello();
   world();
}

def hello() {
    g = 2;
}

def world() {
    print(g);
}

I also see that "Dart provides isolates" and which can run on multi-cores. That means it may be dangerous if different isolates visit the same global variable, right?
Is it safe? And if not, is there any way to share objects between functions without passing them as parameters?

Update:
Per "Florian Loitsch"'s answer, I just wrote a testing for the global variable with isolates:
import 'dart:isolate';

var g = 1;

echo() {
  port.receive((msg, reply) {
    reply.send('I received: $g');
  });
}

main() {
  var sendPort = spawnFunction(echo);

  void test() {
    g = 2;
    sendPort.call('Hello from main').then((reply) {
      print("I'm $g");
      print(reply);
      test();
    });
  }
  test();
}

You can see one isolate will set the global variable g to a new value, and another isolate will print the value of g.
The console it prints:
I'm 2
I received: 1
I'm 2
I received: 1
I'm 2
I received: 1
I'm 2
I received: 1
I'm 2
I received: 1
I'm 2
I received: 1
I'm 2
I received: 1
I'm 2
I received: 1
I'm 2
I received: 1
I'm 2
I received: 1

It's clear that they don't share memory, and global variable is safe.

A: Dart is single-threaded within one thread. It is hence safe (though bad style) to pass data in global variables.
Isolates have their separate heaps (memory) and don't interfere with each other. Global variables stay safe.
I don't think there is a way to pass variables between functions except for static variables and parameters.


text:
Q: How to use the QueryResult in Bluemix to get the BasicDocumentRevision public List<Task> allTasks() {
    int nDocs = this.mDatastore.getDocumentCount();
    List<BasicDocumentRevision> all = this.mDatastore.getAllDocuments(0, nDocs, true);
    List<Task> tasks = new ArrayList<Task>();

    // Filter all documents down to those of type Task.
    IndexManager im = new IndexManager(mDatastore);
    List<Object> indexFields = new ArrayList<Object>();
    indexFields.add("city");
    indexFields.add("price");
    indexFields.add("Area");
    indexFields.add("Information");
    indexFields.add("imagename");

// Create the index
    im.ensureIndexed(indexFields);
    Map<String, Object> query = new HashMap<String, Object>();
    query.put("desc", "RESIDENTIAL PROPERTY");
    QueryResult result = im.find(query);

    for(BasicDocumentRevision rev :all) {
        Task t = Task.fromRevision(rev);
        if (t != null) {

            tasks.add(t);

        }
    }

    return tasks;

How do you use queryresult to get it stored in a task class object? I want my query to only be listed in listview. I am working on Bluemix, which uses Cloudant syn.

A: You can get the document revision from the QueryResult by iterating over the QueryResult Object like :
for(DocumentRevision rev : result){
    Task t = Task.fromRevision(rev);
    if(task != null)
        tasks.add(t);
}


text:
Q: Store data in Android using Volley In application there is menu in menu user can choose one of them. All required data from server. Where should I make an request and store data?
So far I made request inside fragment, but I do not want to make request per activity/fragment.
Is the good idea to make request inside main activity (of course using other thread <>). And then keep data in static list in this activity? Or is there better way to store this data?

A: This is a very vague question, the answer can vary by a lot based on the precise requirements.
For example if its just a boolean returned by server, sure you can save as static boolean, if the list returned is small, sure save it as static, as long as you are comfortable with loosing the data when the app is killed.
If not you need to save the data somewhere, depending on the size, type there are multiple options you can use please read http://developer.android.com/training/basics/data-storage/index.html

A: If you ment using Volley as a Singleton class read more in the following link.


text:
Q: How to determine the threshold for neuron firings in neural networks? I have a simple task to classify people by their height and hair length to either MAN or WOMAN category using a neural network. Also teach it the pattern with some examples and then use it to classify on its own.
I have a basic understanding of neural networks but would really need some help here.
I know that each neuron divides the area to two subareas, basically that is why P = w0 + w1*x1 + w2*x2 + ... + wn*xn is being used here (weights are just moving the line if we consider geometric representation).
I do understand that each epoche should modify the weights to get closer to correct result, yet I have never program it and I am hopeless about how to start.
How should I proceed, meaning: How can I determine the threshold and how should I deal with the inputs?
It is not a homework rather than task for the ones who were interested. I am and I would like to understand it.

A: Looks like you are dealing with a simple Perceptron with a threshold activation function. Have a look at this question. Since you ARE using a bias neuron (w0), you would set the threshold to 0.
You then simply take the output of your network and compare it to 0, so you would e.g. output class 1 if x < 0 and class 2 if x > 0. You could model the case x=0 as "indistinct".
For learning the weights you need to apply the Delta Learning Rule which can be implemented very easily. But be careful: a perceptron with a simple threshold activation function can only be correct if your data are linearly separable. If you have more complex data you will need a Multilayer Perceptron and a nonlinear activation function like the Logistic Sigmoid Function.
Have a look at Geoffrey Hintons Coursera Course, Lecture 2 for details.

A: I've been working with machine learning lately (but I'm not an expert) but you should look at the Accord.NET framework. It contains all the common machine learning algorithme out of the box. So it's easy to take an existing samples and modify it instead of starting from scratch. Also, the developper of the framework is very helpful in the forum available on the same page.
With the available samples, you may also discover something better than neural network like the Kernel Support Vector Machine. If you stick to the neural network, have fun modifying all the different variables and by tryout and error you will understand how it work.
Have fun!

A: Since you said:

I know that each neuron divides the area to two subareas

&

weights are just moving the line if we consider geometric representation

I think you want to use perseptron or ADALINE neural networks. These neural networks can just classify linear separable patterns. since your input data is complicated, It's better to use a Multi layer Non-Linear Neural network. (my suggestion is a two layer neural network with tanh activation function) . For training these network you should use back propagation algorithm.
For answering to

how should I deal with the inputs?

I need to know more details about the inputs( Like: are they just height and hair length or there is more, what is their range and your resolution and etc.)
If you're dealing with just height and hair length I suggest that divide heights and length in some classes (for example 160cm-165cm, 165cm-170cm & etc.) and for each one of these classes set an On/Off input neuron. then put a hidden layer after all classes related to heights and another hidden layer after all classes related to hair length (tanh activation function). Number of neurons in these two hidden layer is determined based on number of training cases.
then take these two hidden layer output and send them to an aggregation layer with 1 output neuron.


text:
Q: Executing a simple stored procedure in SQL Server Management Studio This is a simple stored procedure written in SQL Server Management Studio.
It compiles great but I have problems invoking it :(
CREATE PROCEDURE [dbo].[DetermineVoltage]
   @itemDescription varchar(225) ,
   @voltageRating varchar(225) OUTPUT
AS
BEGIN
   SELECT
       @voltageRating = REVERSE(SUBSTRING(REVERSE(@itemDescription),
       charindex(' V', REVERSE(@itemDescription)) + 2,
    CHARINDEX(' ', REVERSE(@itemDescription), charindex(' V', REVERSE(@itemDescription)) + 1) - charindex(' V', REVERSE(@itemDescription)) - 2))
   RETURN
END

In SQL Server Management Studio, when I execute this stored procedure like this:
DECLARE  @voltageRating VARCHAR(225)
exec dbo.DetermineVoltage['test 20V', @voltageRating]

I get an error

Procedure or function 'DetermineVoltage' expects parameter '@voltageRating', which was not supplied.

There are many SO answers which discusses the same error message but when executed from a C# program.
But, in my case, how to execute a stored procedure within SQL Server Management Studio ?

A: declare @voltageRating varchar(225);
exec dbo.DetermineVoltage 'test 20V', @voltageRating output;

As a side note, you might want to convert this procedure to a function.


text:
Q: On firebase UI authentication example getting: Uncaught FirebaseError: No Firebase App '[DEFAULT] I am following the example of the firebase UI repo but I get the following error:

Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app-compat/no-app).

I've tried already several things, but they don't work. When I inspect the code it seems that it runs first the line containing var ui = new firebaseui.auth.AuthUI(firebase.auth()); before const app = initializeApp(firebaseConfig); even if it is afterwards.
This is my code, help will be welcomed:

<!DOCTYPE html>

    <meta charset="UTF-8" />
    <title>Sample FirebaseUI App</title>

    <link
      type="text/css"
      rel="stylesheet"
      href="https://www.gstatic.com/firebasejs/ui/6.0.2/firebase-ui-auth.css"
    />

Welcome to My Awesome App

A: As you are using compat SDKs, initialize Firebase SDK as shown below:
const app = firebase.initializeApp(firebaseConfig);
const auth = firebase.auth();

A: You should reorder the code:

<!DOCTYPE html>

    <meta charset="UTF-8" />
    <title>Sample FirebaseUI App</title>

    <link
      type="text/css"
      rel="stylesheet"
      href="https://www.gstatic.com/firebasejs/ui/6.0.2/firebase-ui-auth.css"
    />

Welcome to My Awesome App

You are using Firebase Compatibility Mode (the new API is different now, https://firebase.google.com/docs/web/modular-upgrade)
You should put your code before  tag, so when the DOM is ready the scripts outside a function are loaded (http://www.cev.washington.edu/lc/CLWEBCLB/jst/js_whereto.html)
Note that you are exposing the Firebase config if you put it inline, you should adopt another strategy https://medium.com/@devesu/how-to-secure-your-firebase-project-even-when-your- api -key-is-publicly-available-a462a2a58843. There are several strategies you can adopt.


text:
Q: How do I stub a view in rspec-2 I'm in the process of upgrading an app to Rails 3/Rspec 2.  I see that
stubbing a view helper method has changed in Rspec 2.  It looks like
instead of doing template.stub!, we're now supposed to do view.stub!,
but I can't seem to get this to work on beta 10.  I get an "undefined
local variable or method `view' for # < RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x106785fd0>"
error.
I see that in this commit David removed the view
method, but I can't figure out what it was replaced with.  Something
in ActionView::TestCase::Behavior?
I'm on rails 3.0.0.beta3.
Any idea what I'm missing?

A: This turned out to be a bug in rspec-rails after moving more of the functionality back to ActionView::TestCase::Behavior.  David re-exposed _view as view, so view.stub! is still the way to go.  It was just temporarily broken.


text:
Q: Spring Boot 2 integrate Brave MySQL-Integration into Zipkin I am trying to integrate the Brave MySql Instrumentation into my Spring Boot 2.x service to automatically let its interceptor enrich my traces with spans concerning MySql-Queries.
The current Gradle-Dependencies are the following
compile 'io.zipkin.zipkin2:zipkin:2.4.5'
compile('io.zipkin.reporter2:zipkin-sender-okhttp3:2.3.1')
compile('io.zipkin.brave:brave-instrumentation-mysql:4.14.3')
compile('org.springframework.cloud:spring-cloud-starter-zipkin:2.0.0.M5')

I already configured Sleuth successfully to send traces concerning HTTP-Request to my Zipkin-Server and now I wanted to add some spans for each MySql-Query the service does.
The TracingConfiguration it this:
@Configuration
public class TracingConfiguration {
    /** Configuration for how to send spans to Zipkin */
    @Bean
    Sender sender() {
        return OkHttpSender.create("https://myzipkinserver.com/api/v2/spans");
    }

    /** Configuration for how to buffer spans into messages for Zipkin */
    @Bean AsyncReporter<Span> spanReporter() {
        return AsyncReporter.create(sender());
    }

    @Bean Tracing tracing(Reporter<Span> spanListener) {
      return Tracing.newBuilder()
              .spanReporter(spanReporter())
              .build();
  }
}

The Query-Interceptor works properly, but my problem now is that the spans are not added to the existing trace but each are added to a new one.
I guess its because of the creation of a new sender/reporter in the configuration, but I have not been able to reuse the existing one created by the Spring Boot Autoconfiguration.
That would moreover remove the necessity to redundantly define the Zipkin-Url (because it is already defined for Zipkin in my application.yml).
I already tried autowiring the Zipkin-Reporter to my Bean, but all I got is a SpanReporter - but the Brave-Tracer-Builder requries a Reporter<Span>
Do you have any advice for me how to properly wire things up?

A: Please use latest snapshots. Sleuth in latest snapshots uses brave internally so integration will be extremely simple.


text:
Q: Spark join dataframes & datasets I have a DataFrame called Link with a dynamic amount of fields/columns in a Row.
Some fields however had the structure [ClassName]Id that contain an id
[ClassName]Id's are always of type String
I have a couple of Datasets each of a different type [ClassName]
Each Dataset has at least fields id (String) and typeName (String), which is always filled with the String value of the [ClassName]
e.g. If I would have 3 DataSets of type A, B and C
Link:
+----+-----+-----+-----+
 | id | AId | BId | CId |
 +----+-----+-----+-----+
 | XX | A01 | B02 | C04 |
 | XY | null| B05 | C07 |
A:
+-----+----------+-----+-----+
 | id  | typeName | ... | ... |
 +-----+----------+-----+-----+
 | A01 | A        | ... | ... |
B:
+-----+----------+-----+-----+
 | id  | typeName | ... | ... |
 +-----+----------+-----+-----+
 | B02 | B        | ... | ... |
The preferred end result would be the Link Dataframe where each Id is either replace or appended by a field called [ClassName] With the original object encapsulated.
Result:
+----+----------------+----------------+----------------+
 | id | A              | B              | C              |
 +----+----------------+----------------+----------------+
 | XX | A(A01, A, ...) | B(B02, B, ...) | C(C04, C, ...) |
 | XY | null           | B(B05, B, ...) | C(C07, C, ...) |
Things I've tried

*

*Recursive Call on joinWith.
The first call succeeds returning a tuple/Row where the first element is the original Row and the second the matched [ClassName]
However the second iteration starts nesting these results.
Trying to 'unnest' these results using map either results in Encoder hell (since the resulting Row is not a fixed type) or the Encoding is so complex that it results in a catalyst error

*join as RDD Can't work this one out yet.

Any ideas are welcome.

A: So I figured out how I could do what I want.
I made some changes for it to work for me, but it's a
For reference purpose I will show my steps, maybe it can be useful for someone in the future?

*

*First I declare a datatype that shares all properties of A, B, C, etc. that I'm Interested in and make the classes extend from this super type

case class Base(id: String, typeName: String)
case class A(override val id: String, override val typeName: String) extends Base(id, typeName)

*Next I load the link Dataframe
val linkDataFrame = spark.read.parquet("[path]")

*I want to convert this DataFrame in something joinable, this means creating a placeholder for the joined sources and a way to convert all the single Id fields (AId, BId, etc) into a Map of source -> id's. Spark has a sql map method that is useful. Also we need to convert the Base class to a StructType for use in the encoder. Tried multiple ways, but couldn't circumvent specific declaration (otherwise casting errors)

val linkDataFrame = spark.read.parquet("[path]")

case class LinkReformatted(ids: Map[String, Long], sources: Map[String, Base])

// Maps each column ending with Id into a Map of (columnname1 (-Id), value1, columnname2 (-Id), value2)
val mapper = linkDataFrame.columns.toList
  .filter(
    _.matches("(?i).*Id$")
  )
  .flatMap(
    c => List(lit(c.replaceAll("(?i)Id$", "")), col(c))
)

val baseStructType = ScalaReflection.schemaFor[Base].dataType.asInstanceOf[StructType]

*All these parts made it possible to create a new DataFrame with the Id's all in one field called ids and a placeholder for the sources in an empty Map[String, Base]
val linkDatasetReformatted = linkDataFrame.select(
    map(mapper: _*).alias("ids")
  )
  .withColumn("sources", lit(null).cast(MapType(StringType, baseStructType)))
  .as[LinkReformatted]

*The next step was to join all source Datasets (A,B, etc) to this reformatted Link dataset. A lot of stuff happens in this tailrecursive method

@tailrec
def recursiveJoinBases(sourceDataset: Dataset[LinkReformatted], datasets: List[Dataset[Base]]): Dataset[LinkReformatted] = datasets match {
  case Nil => sourceDataset // Nothing left to join, return it
  case baseDataset :: remainingDatasets => {

    val typeName = baseDataset.head.typeName // extract the type from base (each field hase same value)
    val masterName = "source" // something to name the source

    val joinedDataset = sourceDataset.as(masterName) // joining source
      .joinWith(
      baseDataset.as(typeName), // with a base A,B, etc
      col(s"$typeName.id") === col(s"$masterName.ids.$typeName"), // join on source.ids.[typeName]
      "left_outer"
    )
      .map {
        case (source, base) => {
          val newSources = if (source.sources == null) Map(typeName -> base) else source.sources + (typeName -> base) // append or create map of sources
          source.copy(sources = newSources)
        }
      }
      .as[LinkReformatted]
    recursiveJoinBases(joinedDataset, remainingDatasets)
  }
}

*You now end up with a Dataset of LinkReformatted records where for each corresponding typeName -> id in the ids field is a corresponding  typeName -> Base in the sources field.
For me that was enough. I could extract everything I needed using some map function over this final Dataset

I hope this somewhat helps. I understand it's not the exact solution I was asking about, nor is it all very straightforward.


text:
Q: How to use rclone on macOS with ssh-agent? I have ssh setup and working for passwordless access to my server, which basically consists in adding the following snipet to my ~/.ssh/config file (I use an ed25519 key):
Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_ed25519

Still, when I try rclone mount to my server I get this error:
$ rclone mount -vv server:~/ ~/server_home
2022/12/13 16:23:33 DEBUG : rclone: Version "v1.59.1" starting with parameters ["rclone" "mount" "-vv" "server:~/" "/Users/my_user/server_home"]
2022/12/13 16:23:33 DEBUG : Creating backend with remote "server:~/"
2022/12/13 16:23:33 DEBUG : Using config file from "/Users/my_user/.config/rclone/rclone.conf"
2022/12/13 16:23:33 Failed to create file system for "server:~/": failed to parse private key file: ssh: this private key is passphrase protected

I tried running ssh-add --apple-use-keychain ~/.ssh/id_ed25519 and eval "ssh-agent -s", before running rclone mount without success also.
How can one use rclone on macOS with ssh-agent?
References:
https://rclone.org/sftp/
https://medium.com/macoclock/set-up-ssh-on-macos-89e8354d8b63


text:
Q: Extract vectors from strsplit list without using a loop Considering the following vector:
[1] "1-1694429" "2-1546669" "3-928598"  "4-834486"  "5-802353"  "6-659439"  "7-552850"
"8-516804"  "9-364061"
[10] "10-354181" "11-335154" "12-257915" "13-251310" "14-232313" "15-217628" "16-216569"

I am trying to generate two vectors, each of them containing the values obtained by splitting each element of the vector by the delimiter "-".
I used:
f <- function(s) strsplit(s, "-")
cc<-sapply(names.reads, f)

head(cc)
      $1-1694429
      [1] "1"       "1694429"

$`2-1546669`

[1] "2"       "1546669"

I know I can access them like:
> cc[[1]][1]
[1] "1"

> cc[[1]][2]
[1] "1694429"

I would like to have two vectors , each one containing the values stored at  cc[[i]][1] and cc[[i]][2]...Can I do that without using a loop? (I have over 1 million elements )

A: Another approach:
names.reads <- c("1-1694429", "2-1546669", "3-928598", "4-834486", "5-802353",
              "6-659439",  "7-552850",  "8-516804", "9-364061", "10-354181",
              "11-335154", "12-257915", "13-251310", "14-232313", "15-217628",
              "16-216569")

library(reshape2)
colsplit(string=names.reads, pattern="-", names=c("Part1", "Part2"))

   Part1   Part2
1      1 1694429
2      2 1546669
3      3  928598
4      4  834486
5      5  802353
6      6  659439
7      7  552850
8      8  516804
9      9  364061
10    10  354181
11    11  335154
12    12  257915
13    13  251310
14    14  232313
15    15  217628
16    16  216569

A: Or with the purrr package:
Part 1:
> map(strsplit(names.reads, "-"), ~.x[1]) %>% unlist()
[1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13"
[14] "14" "15" "16"

Part 2:
> map(strsplit(names.reads, "-"), ~.x[2]) %>% unlist()
[1] "1694429" "1546669" "928598"  "834486"  "802353"  "659439"
[7] "552850"  "516804"  "364061"  "354181"  "335154"  "257915"
[13] "251310"  "232313"  "217628"  "216569"

A: Looking to solve a similar problem, came across this post. Adding my solution to this though I am far ahead in the future! (copying from Henry the code)
names.reads <- c("1-1694429", "2-1546669", "3-928598", "4-834486", "5-802353",
          "6-659439",  "7-552850",  "8-516804", "9-364061", "10-354181",
          "11-335154", "12-257915", "13-251310", "14-232313", "15-217628",
          "16-216569")

require(plyr)
cc <- ldply(strsplit(names.reads, '-'))
cc$V1;cc$V2

That produces a data frame from which the vectors pertaining to the nth element of each item in the list can be extracted.

A: Using mathematical.coffee's suggestion, the following code avoids loops or sapply
names.reads <- c("1-1694429", "2-1546669", "3-928598", "4-834486", "5-802353",
              "6-659439",  "7-552850",  "8-516804", "9-364061", "10-354181",
              "11-335154", "12-257915", "13-251310", "14-232313", "15-217628",
              "16-216569")

cc       <- strsplit(names.reads,'-')
part1    <- unlist(cc)[2*(1:length(names.reads))-1]
part2    <- unlist(cc)[2*(1:length(names.reads))  ]

produces
> part1
 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13" "14" "15"
[16] "16"
> part2
 [1] "1694429" "1546669" "928598"  "834486"  "802353"  "659439"  "552850"
 [8] "516804"  "364061"  "354181"  "335154"  "257915"  "251310"  "232313"
[15] "217628"  "216569"

though it does require each original value to be in the expected format.

A: Using sapply() (for completeness' sake):
y <- c("1-1694429", "2-1546669", "3-928598",  "4-834486",  "5-802353",  "6-659439",  "7-552850", "8-516804",  "9-364061",
"10-354181", "11-335154", "12-257915", "13-251310", "14-232313", "15-217628", "16-216569")
As @Bird pointed out in the comments, the USE.NAMES parameter can be used to avoid names in the resulting vector.
x <- sapply(y, function(x) strsplit(x, "-")[[1]], USE.NAMES=FALSE)
a <- x[1,]
b <- x[2,]


text:
Q: how to read xml file with multiple elements and write to temp-table using progress 4gl dom? Please help me read this xml file and write to temp-table using progress 4gl
MY xml file is shown below.
 <?xml version="1.0" encoding="UTF-8"?>

        <bookstore>
          <bookone>
            <title>Everyday Italian</title>
            <author>Giada De Laurentiis</author>
            <year>2005</year>
            <price>30.00</price>
          </bookone>

          <cars>
            <model>
            <plate>12345</plate>
            <purchase>04/03/2011</purchase>
            <insurence>yes</insurence>
            </model>

          <model>
          <plate>56789</plate>
          <purchase>04/03/2011</purchase>
          <insurence>no</insurence>
          </model>

        </cars>

        <booktwo>
            <title>XQuery Kick Start</title>
            <author>James McGovern</author>
            <author>Per Bothner</author>
            <author>Kurt Cagle</author>
            <author>James Linn</author>
            <author>Vaidyanathan Nagarajan</author>
            <year>2003</year>
            <date>02/05/2009</date>
          </booktwo>

        </bookstore>

I have tried a code with repeat statement but doesn't work.

A: Progress 4gl comes with inbuilt parsers for XML. There is Sax and Dom. The Sax parser will be more useful to you in reality, and there is a pretty good starting point on how to use it in the documentation, here: https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvxml/example-code-3a-reading-customer-data-and-writing.html


text:
Q: How to catch an exception if it's caused by a specific function Problem:
sklearn allows creating user-defined distance functions to be used in several algorithms (for example KNN). However, it tests the user-defined function by creating a random numpy array (__init__ of class PyFuncDistance(DistanceMetric) at the end of the page). My function is defined for categorical variables and to speed up the calculations I am passing a dictionary to the distance function that I build in advance. Naturally, when sklearn passes the float array for testing, it raises a KeyError because the dictionary only has attribute values as the keys.
Code:
import pandas as pd
import numpy as np
from sklearn import preprocessing
from sklearn.neighbors import KNeighborsClassifier
from sklearn import cross_validation

df = pd.DataFrame(np.random.choice(["a", "b", "c", "d"], (200, 4)))

for col in df:
    le = preprocessing.LabelEncoder()
    le.fit(df[col])
    df[col] = le.transform(df[col])

value_dict = df[0].value_counts().to_dict()

def custom_distance(point1, point2, value_dict):
    #this is not the actual distance function, just a simplified version for reproducibility
    distance = .0
    for i in range(1, len(point1)+1):
        distance += abs(value_dict[point1[i]] - value_dict[point2[i]])
    return distance

neigh_custom = KNeighborsClassifier(n_neighbors=10, metric=custom_distance,
                        metric_params = {"value_dict": value_dict})

scores = cross_validation.cross_val_score(neigh_custom, df.ix[:,1:], df.ix[:,0], cv=10)

Question:
To make sure the errors are not caused by the original data but by the test, can I catch that exception only if it is raised by __init__ of PyFuncDistance? Currently I am checking whether the number is between 0 and 1 to understand if it is produced randomly but I don't think it is a good practice.

A: import traceback
import sys

try:
    scores = cross_validation.cross_val_score(neigh_custom, df.ix[:,1:], df.ix[:,0], cv=10)
except Exception, err:
    exc_type, exc_value, exc_traceback = sys.exc_info()
    sam =  traceback.format_exception(exc_type, exc_value,
                                          exc_traceback)
    if 'PyFuncDistance.__init__' in sam[-3]:
        print 'I knew it'

If you want to raise exception for other issues you can use 'raise' and use sam to print traceback call issue
Hope this help!


text:
Q: Autocomplete is ignoring the minLength & delay setting I have the following script inside my razor view :-
$("#Technology2_Tag").autocomplete({
    source: function (request, response) {
        $.ajax({
            url: "/Switch/AutoComplete2",
            dataType: "json",
            minLength: 3, delay: 1000,
            data: {
                term: request.term,
                SearchBy: $("#ChoiceTag").prop("checked") ? $("#ChoiceTag").val() : $("#ChoiceName").val(),
            },
            success: function (data) {
                response(data);
            }
        });
    },
});

Currently the autocomplete is firing after typing the first character, instead of firing after typing at least 3 characters as mentioned in the minLength setting. Can anyone advise what might be the problem ?
Thanks

A: you are putting autocomplete properties in ajax properties, change it like this:
$("#Technology2_Tag").autocomplete({
             minLength: 3,
             delay: 1000,
            source: function (request, response) {
                $.ajax({
                    url: "/Switch/AutoComplete2",
                    dataType: "json",

                    data: {
                        term: request.term,
                        SearchBy: $("#ChoiceTag").prop("checked") ? $("#ChoiceTag").val() : $("#ChoiceName").val(),
                    },
                    success: function (data) {
                        response(data);
                    }
                });
            }

        });

A: I think the minLength and delay should be defined outside the definition of source :
$("#Technology2_Tag").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "/Switch/AutoComplete2",
                    dataType: "json",
                    data: {
                        term: request.term,
                        SearchBy: $("#ChoiceTag").prop("checked") ? $("#ChoiceTag").val() : $("#ChoiceName").val(),
                    },
                    success: function (data) {
                        response(data);
                    }
                });
            },
             minLength: 3,
             delay: 1000,

        });


text:
Q: ~500 NSZombie warnings on Xcode memory graph from iOS 13 application When I build a memory graph of my app I see ~500 memory warnings. When I look these are all in the Malloc Blocks category and are all (mostly) prefixed with NSZombie. I'm assuming this is what it normally looks like when running on device but I want to make sure.
Is this normal?

A: No, it isn't normal. You've got Zombies turned on.

That isn't normal; it's a special build mode for when you want to track down dangling pointers. A Zombie is a leak by definition, hence the warnings. None of your transient objects ever goes out of existence. And Cocoa makes lots and lots of transient objects (as you've just discovered)! There is certainly no point doing a memory graph with Zombies on, and there is no point turning Zombies on unless you are in the middle of tracking down a dangling pointer.
Turn zombie mode off!


text:
Q: RESTful API Auth flow I've been on stack overflow for the last hour researching this topic so I thought I'd just ask all my specific questions. I'm building a web app currently using Laravel (PHP) for the API and Angular for the front. I've looked at oAuth but it's a little daunting atm so I was hoping to implement a simpler solution and then rebuild it in when necessary.
The flow I'm currently implements goes as follows. Angular posts the user credentials (over https) to my rest backend and this simply returns a generated string (this will probably be random or crytographicaly generated). This string is then stored as a cookie or whatever browser state I find suitable and then attached to every API request along with a user id that angular makes as an extra parameter or request header or something. The API uses this to check if the user has access to the requested resource and responds accordingly. I'd probably also add a expiry time on the string which would be reset after every request.
My question is really if this is an acceptable flow? In terms of security what issues am I most likely to face with this? CSRF? Session fixation?
I know this is a question that's been asked a couple times before but I was just hoping for a fresh discussion and be pointed towards relevant information.

A: If I'm understanding you correctly, this is a model I've seen in plenty of APIs, especially in the stateless SOA world. The "string" you're talking about is most commonly referred to as an "auth token." And all non-public API methods require the token (and for it to be valid -- expiration is essential, else someone could grab an old token) to be included with every request (with or without username -- the token should be uniquely identifiable so as to make that unnecessary, but it doesn't hurt), which means before you do anything you have to call the Login API (which does not require a token, natch) to get one before you do anything.
You may want to have your token's expiration refresh on every use (idle timeout), or else you will need to have your clients know they may need to refresh the token (i.e get a new one) every once in a while (which is somewhat more secure than an idle timeout one).

A: What you describe is some kind of basic session implementation. Since REST have a stateless constraints which denies such things, I don't think that this is an acceptable solution. Afaik you have to send the username and password with every request from the trustable clients. If you have 3rd party clients, then you have to generate api keys and access tokens for them (OAuth can solve that part). If you want to know more about REST constraints, then read the Fielding dissertation.

A: Thanks for you input everyone. Ultimately I decided to have a look into OAuth 2 again as suggested. What I was trying to create was pretty much an OAuth flow anyway... Instead of trying to recreate the wheel I looked at other people's implementations of OAuth in PHP (and Laravel) and this practical implementation really helped me get the idea.
I used this package in the end
https://github.com/thephpleague/oauth2-server
Wrapped for laravel
https://github.com/lucadegasperi/oauth2-server-laravel
I was a bit unsure about how OAuth would be implemented for my use case as it was just for internal usage. I discovered that because I had a high trust of the client a great flow to use would be the Resource owner credentials grant.
The only real issue I face now is securing the client id and client secret. It being stored on client side is definitely an issue but form my understanding that's just one of the issues of OAuth. Fortunately if it's ever compromised I can revoke and reissue.
Anyone else that comes across this with a similar question should have a look at the following links:
http://alexbilbie.com/2013/02/a-guide-to-oauth-2-grants/
https://www.rfc-editor.org/rfc/rfc6749
They really helped me understand OAuth 2.


text:
Q: what's this red line in firebug's layout panel?

A: I'm not 100% certain of this because I've deduced it from experimentation rather than looking at Firebug's source, but the red dotted line seems to just always line up with the ruler.
For example:


text:
Q: Understanding multiple regression coefficients and calculations The following variables are in the regression below:

*

*earnings - yearly wages

*age

*educ - years of education

*woman - dummy

*married - dummy

*manager - dummy

What is the need/usefulness to have age squared in the regression?

I did another regression after this one, but I used ln(earn) instead of earn. All other variables remained the same. I would expect the R squared to be the same for both as the variables are the same but the R squared is higher for the second regression and I'm struggling to understand why?

A: This answer assumes that you have independent observations. If this is not the case (i.e. if you have repeated measurements, clustered data etc.) a multiple linear regression model is not appropriate since it does not take this dependence into account.
What is the need/usefulness to have age squared in the regression?
You have fitted the following multiple linear regression model:
$$\text{Earnings}_{i}=\beta_{0} + \beta_{1}\text{age}_i + \beta_{2}\text{age}{_i}^{2} + \beta_{3}\text{edu}_{i} + \beta_{4}\text{sex}_{i} + \beta_{5}\text{married}_{i} + \beta_{6}\text{manager}_{i} + \epsilon_{i},$$
where $\epsilon_{i} \sim \text{N}(0, \sigma^2)$.
Hence you assume that there is a nonlinear relationship between earnings and age.  In fact, holdning all other explanatory variables constant, you assume that this relationship follows the graph of a second degree polynomial (i.e. a parabola). Since the coefficient of the $\text{age}_{i}^{2}$ is negative, $\beta_{2}=-0.006$, the earnings will increase with age until a given age (the top point or vertex of the parabola), and decrease here after. If, however, you believe that the relationship is linear you could leave out the $\text{age}_{i}^{2}$-term of the model. This would mean that you assume that the difference in earnings between two persons is proportional to their age difference.
Also, is this the easiest/correct way to calculate the diff in earnings from age=35 to age=36?
The short answer is yes. You have calculated the education, sex, marriage and managerial postion adjusted difference between two persons aged 35 and 36 respectively. That is you have calculated the difference in earnings between two persons, A and B, who has the same years of schooling, the same sex, the same marital status and the same managerial postion but person A is 36 years old and person B is 35 years old. If, instead, you were interested in the difference between a man aged 36 and a woman aged 35 you should also take the coefficient of $\text{sex}$ into account.
R squared is higher for the second regression and I'm struggling to understand why?
$R^2$ depends on, among other things, the residual standard deviation $\sigma$, which is a measure of how far your observations are from the fitted values of the regression model on  average. The smaller $\sigma$ is, the higher $R^2$ becomes. Hence, if using $\ln(\text{earnings})$ as the dependendent variable makes $\sigma$ smaller (as compared to the when you use $\text{earnings}$ as the dependent variable), this will make $R^2$ bigger.

A: 1.What is the need/usefulness to have age squared in the regression?
When you add an interaction term, you assume that the effect of a variable on the outcome varies accordingly to different levels of another variable. When you add a squared term, you are basically interacting a variable with itself. In this case, that means that the marginal effect (one unit change effect) of age will vary accordingly to different ages. That is, the average effect of a change of age from 18 to 19 on income will be different from the average effect of age when it changes from 35 to 36.
So, basically, it is useful to have age squared because usually the effect of age on income varies depending on age itself. This phenomena was first documented by Jacob Mincer in the 1950s, and it is still widespread tested (and often confirmed) in economics and social science. So from a theoretical standpoint, it makes sense total sense to test age as a quadratic term. Of course you should also test for a model without a quadratic term, but probably the model with the quadratic term will have a better fit.
2. Also, is this the easiest/correct way to calculate the diff in earnings from age=35 to age=36?
It might be the easiest way, but it is not the right way. The way you calculated might give you a good estimate, but it depends on the convexity of the effect of age. Put it simpler: since you added the interaction term, you assumed that the marginal effect of age varies for different ages. Thus, the $\beta_2$ coefficient represents an average effect of age, that is not the same for all age levels. The correct way of doing such calculation is through the margins command (which you need to run after you ran your regression):
margins, at (age = (35(1)36))

You can also see how the marginal effect of age changes across the distribution of age itself. Assuming that age is coded between 18 and 64, you can execute:
margins, at (age = (18(1)64))
marginsplot

This will also plot the varying effect of age on the dependent variable for different age levels.
3. R squared is higher for the second regression and I'm struggling to understand why?
As Jens already answered to you the $R^2$ is dependent on your dependent variable. So if you do some sort of non-linear transformation of your dependent variable, as taking the log of it, your $R^2$ may change.


text:
Q: Route static IP to Google Cloud Function I have the following (python3.7) Cloud Function written that return "Hello":
https://us-central1-first-outlet-750.cloudfunctions.net/test
I would like to route a domain to this IP. So that someone can use our company URL instead of having to remember the long Google URL to enter in. For example, the a user to be able to enter in:
https://mycompany.com/test
And it to route to the Google URL. What would be the cleanest way to achieve this? For example, some options are:

*

*Set up some flask server and redirect to the GCF url (though sort of defeats the purpose of "auto-scale" as all the IP requests have to route through our own apache server.

*Set up some kind of API Gateway so that it routes traffic to that. Is it possible to do this in GCP? If so, how can I do that?

Here's a similar question, but is more in line with function egress rather than what I'm looking to do: Possible to get static IP address for Google Cloud Functions?

A: You can do this with Firebase Hosting integration with Cloud Functions.  You will have to connect your domain to Firebase Hosting, then set up a rewrite rule to proxy a URL pattern to your function.


text:
Q: Add Copyright header to all project files (.java, .xml, ...) I have several maven projects where I'd like to add a common header (copyright information, etc.). Is there a tool, or Eclipse plugin, to do this?
A simple shell script won't do the job, because some files already have such a header - and I don't just want to blindly append another header.
So some plugin with "sophisticated" logic would be appreciated ;-)

A: If your project supports Maven, you can use maven-license-plugin
There are instructions how to install and use it.


text:
Q: Understanding the construction for the topological cone $c(S^1) = (S^1 \times [0,1]) \ / \ (S^1 \times \{1\})$.
I have trouble understanding the construction for the topological cone $c(S^1) = (S^1 \times [0,1]) \ / \ (S^1 \times \{1\})$.

Isn't $(S^1 \times \{1\})$ just the unit sphere lifted along the $z-$axis by constant height of $1$? I get that this is supposed to represent the vertex of the cone, but don't understand how? Also what are the equivalence classes for this quotient space? This is very confusing, it seems that the notation $X/A$ is used indistinguishably for quotient spaces and when you deform a set to a point? Could someone help me with understanding this properly?

A: You start by considering the cylinder $S^1 \times [0,1]$. Now you ask yourself how you would write a horizontal slice of this cylinder. For example, if you slice the cylinder in half, you will have done so along the line $S^1 \times \{\frac12\}$. So indeed, you can think of $S^1 \times \{1\}$ as the unit circle at height 1 above the $xy$-plane. By taking the quotient over $S^1 \times \{1\}$, you're saying that you want to identify all points in $S^1 \times \{1\}$ with each other, i.e. you're treating all points in $S^1 \times \{1\}$ as one point. Since this is now one point, you can think of this point as the vertex of the cone. Let $\sim$ denote your equivalence relation
$$
x \sim y :\iff x,y \in S^1 \times \{1\}
$$
Then, the equivalence classes are the singleton sets $[x]$ if $x \in S^1 \times [0,1)$ and $[(1,1)] = \{ x \in S^1 \times [0,1] \mid x \sim (1,1) \} = S^1 \times \{1\}$, since $(1,1) \in S^1 \times \{1\}$ is a representative of this class. $[x]$ is a singleton if $x \in S^1 \times [0,1)$, because the equivalence relation $\sim$ does not act on these points in any way, so you can think of $[x]$ as just being equal to $x$ itself. I hope this was helpful.


text:
Q: Symfony: Property does not exist - 500 Internal Server Error - ReflectionException I removed $hearAboutIndustry from the entity and now getting error below only in production server, not on local and staging server! Any idea why or solution?
Property Tete\AdminBundle\Entity\Customer::$hearAboutIndustry does not exist
500 Internal Server Error - ReflectionException

config_prod.yml
doctrine:
    orm:
        metadata_cache_driver: apc
        result_cache_driver: apc
        query_cache_driver: apc

What I have do to solve it so far:

*

*Removed getter and setters from the entity.

*Deleted whole cache and logs folders and re-created back, inc 777.

*Just in case run cache:clear --env=prod

*Searched hearAboutIndustry in all directories/files of the project. No reference at all.

*Run doctrine:schema:update. DB is updated.

*Run doctrine:generate:entities. Entity is updated.

*app/console doctrine:cache:clear-metadata

*app/console doctrine:cache:clear-query

*app/console doctrine:cache:clear-result

A: As Adam suggested above in comment, we better restart apache if all the above solutions have been tried and getting no success. The solution is:
sudo apachectl graceful

A: *

*php app/console doctrine:cache:clear-query --env=prod

Clearing ALL Query cache entries

*

*php app/console doctrine:cache:clear-result --env=prod

Clearing ALL Result cache entries

*

*php app/console doctrine:cache:clear-metadata --env=prod

Clearing ALL Metadata cache entries

*

*php app/console cache:clear --env=prod

Clearing the cache for the prod environment with debug false
And don't forget to put --env=prod to your commands

A: "Old but still happens"
If none of the solutions mentioned above worked
try to delete the Entity cache file manually :
(e.g Entity costumer cache file path should be this one)
projectdirectory\projectname\var\cache{dev or prod}\jms_serializer\Tete-AdminBundle-Entity-Customer.cache.php

A: I had similar problem, I just used doctrine:mapping:import and that was it.
Cheers

A: We had the same issue and in our case (Nginx), the restart of Nginx didn't help.
But restart of memcache was the right solution:
sudo service memcached restart


text:
Q: Multiple teams for one project in Visual Studio - bad practice? Previously I have been using Bitbucket with git; and I might have a dozen or so repositories for each project.
Python modules work especially well with this layout; as you can add each dependant module into requirements.txt; and it additionally allows you to reduce merge issues when working in a team; and helps with decoupling and increasing cohesion.
Starting to use Visual Studio online with Azure (still git though); and I was wondering if this approach to software engineering is still viable.
Would you recommend setting up a "Visual Studio Online Project" for each of my Python modules?

A: With VSO there isn't a 1-1 relationship between projects and repositories; a project may contain more than 1 repo. I would suggest a single team project with multiple repositories would work better for you. If you want to logically contain work items to align with the repos, I'd use area paths.


text:
Q: Getting a 403 for static resources in spring boot without using spring security I have a spring boot application that is not using spring security at all, and when some requests come through for static resources, the server returns a 403.
The spring boot application is running in a tomcat 9 server (not embedded). A lot of the requests triggering the 403 come from mobile devices. I have read a lot of articles about this issue but they all refer to the spring security implementation which I am not using.
Has anyone experienced this? Any help/suggestions would be greatly appreciated.
Here's my pom file:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.valspar</groupId>
<artifactId>rest.valspar.com</artifactId>
<version>2.0</version>
<packaging>war</packaging>
<name>Valspar Web-Services</name>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.5.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <version.jdk>1.8</version.jdk>
    <ms.sql.version>1.0</ms.sql.version>
    <maven-git-code-format.version>1.31</maven-git-code-format.version>
</properties>

<dependencies>
    <!-- SpringBoot Dependencies -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>logback-classic</artifactId>
                <groupId>ch.qos.logback</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-oracle</artifactId>
        <version>1.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-discovery/commons-discovery -->
    <dependency>
        <groupId>commons-discovery</groupId>
        <artifactId>commons-discovery</artifactId>
        <version>0.5</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>6.4.0.jre8</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/wsdl4j/wsdl4j -->
    <dependency>
        <groupId>wsdl4j</groupId>
        <artifactId>wsdl4j</artifactId>
        <version>1.6.3</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.axis/axis -->
    <dependency>
        <groupId>org.apache.axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.4</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-log4j -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j</artifactId>
        <version>1.3.8.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc41 -->
    <dependency>
        <groupId>com.microsoft</groupId>
        <artifactId>sqljdbc4</artifactId>
        <version>${ms.sql.version}</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.oracle/classes12 <dependency>
        <groupId>oracle</groupId> <artifactId>ojdbc5</artifactId> <version>11.2.0.3</version>
        </dependency> -->

    <!-- Oracle JDBC driver -->
    <dependency>
        <groupId>com.oracle.database.jdbc</groupId>
        <artifactId>ojdbc8</artifactId>
        <version>12.2.0.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/javax.xml/jaxrpc -->
    <dependency>
        <groupId>javax.xml</groupId>
        <artifactId>jaxrpc</artifactId>
        <version>1.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.xml/serializer -->
    <dependency>
        <groupId>serializer</groupId>
        <artifactId>serializer</artifactId>
        <version>2.7.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.ldap</groupId>
        <artifactId>spring-ldap-core</artifactId>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.force.api/force-partner-api -->
    <dependency>
        <groupId>com.force.api</groupId>
        <artifactId>force-partner-api</artifactId>
        <version>44.0.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.smartystreets.api/smartystreets-java-sdk -->
    <dependency>
        <groupId>com.smartystreets.api</groupId>
        <artifactId>smartystreets-java-sdk</artifactId>
        <version>3.3.8</version>
        <exclusions>
            <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.mindscapehq</groupId>
        <artifactId>raygun4java</artifactId>
        <type>pom</type>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>com.mindscapehq</groupId>
        <artifactId>core</artifactId>
        <version>1.3.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.ws.security/wss4j -->
    <dependency>
        <groupId>org.apache.ws.security</groupId>
        <artifactId>wss4j</artifactId>
        <version>1.5.6</version>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.pojava/datetime -->
    <dependency>
        <groupId>org.pojava</groupId>
        <artifactId>datetime</artifactId>
        <version>3.0.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/struts/struts -->
    <dependency>
        <groupId>struts</groupId>
        <artifactId>struts</artifactId>
        <version>1.2.9</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>

</dependencies>

<build>
    <finalName>wservices</finalName>
    <sourceDirectory>src/main/java</sourceDirectory>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <filters>
        <filter>${basedir}/ci/profiles/build-${build.profile.id}.properties</filter>
    </filters>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${version.jdk}</source>
                <target>${version.jdk}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>com.cosium.code</groupId>
            <artifactId>maven-git-code-format</artifactId>
            <version>${maven-git-code-format.version}</version>
            <executions>
                <!-- On commit, format the modified java files -->
                <!-- Un-comment the following execution block for the first build of
                    the project. Revert to HEAD revision after project is built successfully
                    for the first time. -->
                <!-- <execution> <id>install-formatter-hook</id> <goals> <goal>install-hooks</goal>
                    </goals> </execution> -->
                <!-- On Maven verify phase, fail if any file (including unmodified)
                    is badly formatted -->
                <execution>
                    <id>validate-code-format</id>
                    <goals>
                        <goal>validate-code-format</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I ran the application as standalone (without external Tomcat) and the problem does not seem to occur. This is pointing more to an interaction between the two or tomcat 9 configuration issue.

A: The problem was a tomcat 9 mis-configuration with a security realm and had nothing to do with Spring. The security real was not connecting to the user database so it was blocking anything static.


text:
Q: Flutter : Why is the exception not caught? I want to show a snackbar when an error occurs.
The Exception is working but is not caught in the main.dart.
Can you see what is the problem? I am new to Flutter so I may not be good. Thank you.
main.dart
Future<void> _signInWithPhoneNumber() async {
    try {
      postPhoneInfo(
          tokenValue,
          _packageInfo.appName,
          _packageInfo.version,
          Theme.of(context).platform.toString().substring(15),
          "phone number");
      print("debug : try");
    } catch (e) {
      print("debug : catch");
      // print(e);
      ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("${e.toString()}")));
    }
  }

this is postPhoneInfo()
Future<phoneInfo> postPhoneInfo(String token, String appName, String appVersion,
    String platform, String phone) async {
  var queryParameters = {
    'param1': token,
    'param2': appName,
    'param3': appVersion,
    'param4': platform,
    'param5': phone
  };
  var uri =
      Uri.http('~~', '~~', queryParameters);
  final response = await http.post(uri, headers: <String, String>{
    'Content-Type': 'application/json; charset=UTF-8',
  });

  if (response.statusCode == 200) {
    final parsedJson = jsonDecode(response.body);

    if (parsedJson["Res"] == "1") {
      print("user is registered");
      return phoneInfo.fromJson(jsonDecode(response.body));
    } else {
      print("user is not registered");
      throw Exception("user is not registered");
    }
  } else {
    print(response.statusCode);
    throw Exception('not connected');
  }
}

A: You need to await the postPhoneInfo function call in _signInWithPhoneNumber. Otherwise, the exception is thrown in an async context.
You would have to use runZoned to catch those.
Documentation: https://api.flutter.dev/flutter/dart-async/runZoned.html

A: ScaffoldMessenger.of(context) must be called in a Scaffold widget. Check the context where it comes from.


text:
Q: ElasticSearch Slow Query Response on ISCSI Disk on Oracle Cloud I'm doing a migration from Elastic version 7.1 from AWS to Oracle Cloud using elastic 8,
I made the snapshot the index was restored successfully, but the elastic is taking a long time to return the answer when it has many simultaneous connections.
These machine on AWS are perfect and working properly, here is her information
AWS 3x Nodes Machine
8gb RAM 2 CPUS Disk SSD NVME JVM heapsize 5gb
Elastic version 7.1 *Query Time 500ms*
iowait (AWS 15,92% Disk: SSD NVME)

AWS DISK SSD NVME (PHYSIC)
[root@es-4-node-1_subnet-1 ec2-user]# fio --name TEST --eta-newline=5s --filename=temp.file --rw=read --size=2g --io_size=10g --blocksize=1024k --ioengine=libaio --fsync=10000 --iodepth=32 --direct=1 --numjobs=1 --runtime=60 --group_reporting
TEST: (g=0): rw=read, bs=1M-1M/1M-1M/1M-1M, ioengine=libaio, iodepth=32
fio-2.14
Starting 1 process
Jobs: 1 (f=1): [R(1)] [18.4% done] [246.0MB/0KB/0KB /s] [246/0/0 iops] [eta 00m:31s]
Jobs: 1 (f=1): [R(1)] [30.0% done] [246.0MB/0KB/0KB /s] [246/0/0 iops] [eta 00m:28s]
Jobs: 1 (f=1): [R(1)] [41.5% done] [245.0MB/0KB/0KB /s] [245/0/0 iops] [eta 00m:24s]
Jobs: 1 (f=1): [R(1)] [53.7% done] [239.0MB/0KB/0KB /s] [239/0/0 iops] [eta 00m:19s]
Jobs: 1 (f=1): [R(1)] [65.9% done] [247.0MB/0KB/0KB /s] [247/0/0 iops] [eta 00m:14s]
Jobs: 1 (f=1): [R(1)] [78.0% done] [242.0MB/0KB/0KB /s] [242/0/0 iops] [eta 00m:09s]
Jobs: 1 (f=1): [R(1)] [88.1% done] [241.0MB/0KB/0KB /s] [241/0/0 iops] [eta 00m:05s]
Jobs: 1 (f=1): [R(1)] [100.0% done] [251.0MB/0KB/0KB /s] [251/0/0 iops] [eta 00m:00s]
TEST: (groupid=0, jobs=1): err= 0: pid=29174: Thu Apr 14 04:52:41 2022
  read : io=10240MB, bw=255246KB/s, iops=249, runt= 41081msec
    slat (usec): min=26, max=41738, avg=3994.68, stdev=6172.41
    clat (msec): min=9, max=181, avg=123.92, stdev=22.70
     lat (msec): min=9, max=189, avg=127.91, stdev=23.31
    clat percentiles (msec):
     |  1.00th=[   13],  5.00th=[   99], 10.00th=[  106], 20.00th=[  116],
     | 30.00th=[  123], 40.00th=[  126], 50.00th=[  128], 60.00th=[  129],
     | 70.00th=[  131], 80.00th=[  137], 90.00th=[  145], 95.00th=[  151],
     | 99.00th=[  159], 99.50th=[  167], 99.90th=[  180], 99.95th=[  180],
     | 99.99th=[  182]
    lat (msec) : 10=0.02%, 20=2.03%, 50=0.87%, 100=2.49%, 250=94.59%
  cpu          : usr=0.11%, sys=1.15%, ctx=9640, majf=0, minf=8204
  IO depths    : 1=0.1%, 2=0.1%, 4=0.2%, 8=0.4%, 16=0.8%, 32=98.5%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.1%, 64=0.0%, >=64=0.0%
     issued    : total=r=10240/w=0/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=32

Run status group 0 (all jobs):
   READ: io=10240MB, aggrb=255245KB/s, minb=255245KB/s, maxb=255245KB/s, mint=41081msec, maxt=41081msec

Disk stats (read/write):
  nvme0n1: ios=46378/222, merge=0/30, ticks=1544352/5552, in_queue=1500556, util=99.15%

And my problem is on this machine the elastic snapshot from 7.1 to this on OCI with elastic 8, but the request response time is too long i dont know if the problem is that kind of virtualized disk that OCI uses, with slow R/W my ElasticSearch has 2TB of size. +5 Billions of Documents
Oracle 3x Nodes Machine
16gb RAM 4 CPUS Disk ISCSI - JVM heapsize 10gb
Elastic version 8 *Query time up to 10 seconds / 20 seconds / 30 seconds / +1 minute*
(It only increases the time and does not return the answer or take too long)
iowait (Oracle 39,71% Disk: ISCSI "network storage")

Oracle ISCSI (Network Storage Disk)
root@es-master-1:/home# fio --name TEST --eta-newline=5s --filename=temp.file --rw=read --size=2g --io_size=10g --blocksize=1024k --ioengine=libaio --fsync=10000 --iodepth=32 --direct=1 --numjobs=1 --runtime=60 --group_reporting
TEST: (g=0): rw=read, bs=(R) 1024KiB-1024KiB, (W) 1024KiB-1024KiB, (T) 1024KiB-1024KiB, ioengine=libaio, iodepth=32
fio-3.16
Starting 1 process

Jobs: 1 (f=1): [R(1)][16.7%][r=239MiB/s][r=239 IOPS][eta 00m:35s]
Jobs: 1 (f=1): [R(1)][31.0%][r=234MiB/s][r=234 IOPS][eta 00m:29s]
Jobs: 1 (f=1): [R(1)][45.2%][r=196MiB/s][r=196 IOPS][eta 00m:23s]
Jobs: 1 (f=1): [R(1)][59.5%][r=237MiB/s][r=237 IOPS][eta 00m:17s]
Jobs: 1 (f=1): [R(1)][73.8%][r=264MiB/s][r=264 IOPS][eta 00m:11s]
Jobs: 1 (f=1): [R(1)][88.1%][r=251MiB/s][r=251 IOPS][eta 00m:05s]
Jobs: 1 (f=1): [R(1)][100.0%][r=190MiB/s][r=190 IOPS][eta 00m:00s]
TEST: (groupid=0, jobs=1): err= 0: pid=14554: Thu Apr 14 04:52:48 2022
  read: IOPS=238, BW=239MiB/s (250MB/s)(10.0GiB/42923msec)
    slat (usec): min=12, max=275, avg=26.39, stdev=12.34
    clat (msec): min=15, max=350, avg=134.02, stdev=99.43
     lat (msec): min=15, max=350, avg=134.05, stdev=99.43
    clat percentiles (msec):
     |  1.00th=[   24],  5.00th=[   40], 10.00th=[   51], 20.00th=[   53],
     | 30.00th=[   55], 40.00th=[   58], 50.00th=[   73], 60.00th=[   94],
     | 70.00th=[  245], 80.00th=[  259], 90.00th=[  266], 95.00th=[  288],
     | 99.00th=[  313], 99.50th=[  330], 99.90th=[  347], 99.95th=[  347],
     | 99.99th=[  351]
   bw (  KiB/s): min=151552, max=417792, per=99.70%, avg=243557.27, stdev=53597.76, samples=85
   iops        : min=  148, max=  408, avg=237.84, stdev=52.35, samples=85
  lat (msec)   : 20=0.31%, 50=10.01%, 100=51.48%, 250=10.07%, 500=28.12%
  cpu          : usr=0.14%, sys=0.88%, ctx=8661, majf=0, minf=8203
  IO depths    : 1=0.1%, 2=0.1%, 4=0.2%, 8=0.4%, 16=0.8%, 32=98.5%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.1%, 64=0.0%, >=64=0.0%
     issued rwts: total=10240,0,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=32

Run status group 0 (all jobs):
   READ: bw=239MiB/s (250MB/s), 239MiB/s-239MiB/s (250MB/s-250MB/s), io=10.0GiB (10.7GB), run=42923-42923msec

Disk stats (read/write):
  sda: ios=10521/236, merge=0/544, ticks=1399849/35181, in_queue=1435030, util=96.10%

What could be causing me these slowdowns, is the problem in the OCI due to a low speed disk? The response time only increases according to the number of connections, however the AWS machine is inferior but it returns the information very fast and in the OCI it is taking forever, How can I determine the problem is there any configuration for elastic, or is the problem with the machine?
On OCI my benchmark runs fine with multiple connections but when I redirect traffic from the old version on AWS to OCI the application starts to take a long time to respond until the elastic is totally frozen and it takes up to 10 minutes to return the answer
This is the result from Rally Benchmark, i dont know if this is a good.
Rally Benchmark ElasticSearch
https://pastebin.com/vjhDEtR4


text:
Q: Update con nomeros tipos float mysql hola compañeros estoy tratando de hacer un discount mediante una consulta a la base de datos pero no logro conseguir lo que quiero.
aqui les explico que en mi base de datos hago una consulta que tiene que ir restando segun el usuario vaya haciendo click, la cosa es que en mi tabla tengo un campo tipo entero con un numero determinado 17 por ejemplo.
lo que nececito es que ese numero se le vaya restando 1.50 por cada consuta que haga el usuario eso equivale a 11 consultas en total, quiero decir que 17/1.50 serian 11 consultas para que el numero 17 llegue a cero.
lo he intentado cambiando ese campo a tipo FLOAT y DOUBLE pero no me funciona , aqui les dejo mi codigo
    $id=$_SESSION["user_id"];//user id
    $door_cost=1.50;//variable que obtiene el numero flotante

      $discount_my_coins=$con->prepare("UPDATE users SET ID_coins=ID_coins-? WHERE id=?");
      $discount_my_coins->bind_param("ii",$door_cost,$id);
      $discount_my_coins->execute();

como resultado esto se va restando de uno en uno pero lo que yo quiero
  es que el numero 17 llegue a cero en 11 clicks por ejemplo

alguna idea de que sucede aqui o que estoy haciendo mal?

A:
Aclarando que 17 puntos entre 1.50 que se le va a restar por cada click dado, no da 11 sino 11.33 que sería una cantidad con un número decimal periódico que es la parte del .33333..... por lo que no va a dar exactamente 0 en los clicks mencionados; dado eso deberás implementar una solución que muestre la cantidad cerrada a 2 o 0 decimales

Tu tipo de dato con el que esta almacenado el valor a decrementar no coincide con el valor que deseas restar, pues uno es de tipo INT y el otro de tipo DECIMAL por eso al momento de llevar a cabo el UPDATE solo le quita la unidad 1
Lo primero que debes hacer es un ALTER de la tabla para después con un MODIFY alterar la estructura original de dicha columna, con algo como esto
ALTER TABLE users MODIFY COLUMN ID_coins DECIMAL(4, 2);

Para que de este modo si por ejemplo tenías almacenado un valor de 17 ahora aparezca como 17.00 con lo que después ya puedes dejar tu consulta de este modo
UPDATE users SET ID_coins  = ID_coins - 1.50;

Nota importante
Por otro lado la columna ID_coins no quedará en 0 dando 11 clicks, pues eso equivale a un total restado de 16.50 entonces requerirías de un docéavo click mas donde restes .50 para llegar al resultado esperado
Aquí te dejo un enlace con algunas pruebas hechas en SQL


text:
Q: Replacing stock dnsmasq with optware dnsmasq This question if for DD-WRT installed on e3000 with optware.
I have replaced the stock dnsmasq to get logging, using this: http://www.dd-wrt.com/phpBB2/viewtopic.php?p=660694
I installed optware on my 16gb usb and installed dnsmasq.
Runs fine when service started, but have two problems:

*

*"ps aux | grep dnsmasq" shows two processes

 nobody   29791  0.0  0.8   1284   520 ?        S    12:03   0:01 /opt/sbin/dnsmasq
 root     29792  0.0  0.4   1268   256 ?        S    12:03   0:00 /opt/sbin/dnsmasq

*

*On device reboot, the dnsmasq service does not load up. I have to manually load it using "service dnsmasq start" and loads up to processes like the ps grep above.

A: I found the answers to my problems. May be useful to someone else:

*

*"There are always 2 processes running for each dhcp network. The subprocess is because dnsmasq setuids to nobody to run the external script specified in --dhcp-script. This is expected behavior." src: answers.launchpad.net/nova/+question/181398

*As one of the processes was nobody; during boot up, user 'nobody' was not initialized. Added these two lines to /opt/etc/init.d/S56dnsmasq:

grep -q nobody /etc/group || echo "nobody:x:99:" >> /etc/group
grep -q nobody     /etc/passwd || echo "nobody:x:99:99:nobody:/var:/bin/false" >> /etc/passwd

Works like a charm!


text:
Q: seeElement doesnt find object even tho it is there I have this bit of code:
        $I->wait(2);
        $I->amOnPage('/ASTechOLE/exam-form-ng.php');
        $I->wait(2);

        $I->seeElement("//*[@id='oleWaitMessage']");

My problem is that it's giving me an error saying that it doesn't find the object but it actually is on the page.
I'm not sure (that's why I'm asking) but I think it may be something about the sessions? Before getting to that point, my code logs in, but this part doesn't actually give me any errors and goes as expected. Does codeception keep the session alive through the script?
This is the error:
1) FirstCest: Login successfully
 Test  tests\acceptance\FirstCest.php:loginSuccessfully
 Step  See element "//*[@id='oleWaitMessage']"
 Fail  Element located either by name, CSS or XPath element with '//*[@id='oleWaitMessage']' was not found.

Scenario Steps:

 12. $I->seeElement("//*[@id='oleWaitMessage']") at tests\acceptance\FirstCest.php:34
 11. $I->amOnPage("/ASTechOLE/exam-form-ng.php") at tests\acceptance\FirstCest.php:30
 10. $I->click("Proceed") at tests\acceptance\FirstCest.php:26
 9. $I->click("Proceed") at tests\acceptance\FirstCest.php:24
 8. $I->click("Proceed") at tests\acceptance\FirstCest.php:21
 7. $I->click("Proceed") at tests\acceptance\FirstCest.php:19

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

Thanks in advance.


text:
Q: How to replace nan values in read_csv? I'm reading a flat file with read_csv and flat file as some NaN values because of which it is changing the datatype to float instead of integer which I dont want.
Is there any way to replace the NaN values with 0 in the read_csv method?
I know I can do df.fillna(value=0) but my question is how can I replace these nan values in the read_csv.
decop=pd.read_csv("C:\\Users\\mnk044\\Downloads\\amna_decp_part-m-00000", sep="\x01", names=clist)

A: Filling NaN values while loading data is currently not supported (see the read_csv docs for information on all the supported functionality).
Your only option is to first read, and then call fillna.
df = pd.read_csv(filepath)
df.fillna(0, inplace=True)

Next, if you want to convert your float columns to integers, then filter on df.dtypes.
c = df.columns[df.dtypes == float]
df[c] = df[c].astype(int)


text:
Q: Train keras ResNet50V2 with 16-bit images? I have 3-channel tif-images (16-bit).
Now, I would like to use them as training images on the pretrained ResNet50V2 from keras. I understood, that I should call the tf.keras.applications.resnet_v2.preprocess_input as preprocessing function when using ImageDataGenerators. I looked up the documentation of the function (preprocess_input) and it tells me at least that it expects 8-bit data.
Is there any way to give the 16-bit images to the ImageDataGenerator?
Or do I have to convert my images to 8-bit before feeding them to the ImageDataGenerator?
I'm happy for any advice!

A: I see no reference to 8-bit data in the documentation you linked.
And yes, it can accept 16-bit:
import tensorflow as tf
import numpy as np

x = np.random.randint(0, 256, (1, 224, 224, 3), dtype=np.uint16)

tf.keras.applications.resnet_v2.preprocess_input(x)

array([[[[ 0.43529415, -0.24705881, -0.23137254],
         [-0.81960785,  0.3411765 , -0.5921569 ],
         [-0.7882353 ,  0.58431375,  0.0196079 ],
         ...,
         [-0.60784316, -0.4980392 ,  1.        ],
         [-0.654902  ,  0.99215686, -0.38039213],
         [ 0.03529418, -0.7411765 , -0.8901961 ]]]], dtype=float32)


text:
Q: Как подключить css и js в битрикс? На локальном сервере(Open Server) сайт выглядит так как нужно, но когда я подключаю html шаблон к bitrix(через WinSCP), то все стили пропадают.
Как это исправить?

A: А как Вы сейчас подключаете? Можете дать ссылку на сайт чтобы посмотреть ?
Вообще вот так:
use Bitrix\Main\Page\Asset;

Asset::getInstance()->addJs(SITE_TEMPLATE_PATH . "/js/fix.js");
Asset::getInstance()->addCss(SITE_TEMPLATE_PATH . "/styles/fix.css");
Asset::getInstance()->addString("<link href='http://fonts.googleapis.com/css?family=PT+Sans:400&subset=cyrillic' rel='stylesheet' type='text/css'>");

Прописывается в header или footer шаблона.


text:
Q: How do you mount an NFS Share in Windows 7? I have FreeNAS exposing an NFS. How do I access this from Windows 7? I have enabled the "Services for NFS" within Windows Features.

A: Map a drive as normal, only instead of \\server\share format you use server:/share format (don't forget the colon).
Here's a nice post from the Ubuntu forums, but should be the same for NFS served by others.


text:
Q: Is python copy(another_obj) equivalent to object().__dict__.update(antoher_obj.__dict__)? Looks like both copy function and object().__dict__.update() would make a same shallow copy of attributes within another object.
Can I think the both approaches are equivalent in python?
obj = copy(another_obj)

Is equivalent to code below?:
obj = object().__dict__.update(another_obj.__dict__)

Edit:
The second command above does not work actually.
It should be revised as below:
class Foo(object):
    pass

another_obj = Foo()
another_obj.att1 = "value1"

duplicate with copy():
obj1 = copy(another_obj)

duplicate with __dict__.update()
obj2 = Foo()
obj2.__dict__.update(another_obj.__dict__)

The content of both obj1 and obj2 are same:
>>> dir(obj1) == dir(obj2)
True

Does it mean obj1 is equivalent to obj2?

A: I don't think so
obj = copy(another_obj)

Creates a new object to copy new attributes to.
from bs4 import BeautifulSoup
soup = BeautifulSoup('
hi
')
soup2 = copy(soup)
print(soup2.__dict__)

prints lots of stuff

But with
obj = object().__dict__.update(another_obj.__dict__)

You'd need to do some extra work to get the copy done
from bs4 import BeautifulSoup
soup = BeautifulSoup('
hi
')
blank_object = BeautifulSoup()
soup2 = blank_object.__dict__.update(soup.__dict__)
print(soup2.__dict__)

'NoneType' object has no attribute 'dict'

Got me wondering though


text:
Q: Android - onClickListener NullPointerException Hello Stackoverflow Members,
I am trying to create an Intent when a button is pressed to change my activity in my Android App which I develop in Java. However I just get a     NullPointerException:
Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference at .onCreate(MainActivity.java:32) - Line 32 is the Line with  "button_get_started.setOnClickListener(new View.OnClickListener(){"

Does somebody know how to fix this issue or how to bypass it?
Thanks for your help :)
Main Code:
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

//Splash Activity
public class MainActivity extends AppCompatActivity {

    //Attributes
    ImageView imageView_thisfit;
    ImageView imageView_logo;
    public Button button_get_started;

    //Methods

    //This method is executed while creating an instance of the Activity
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        imageView_thisfit = findViewById(R.id.imageView_thisfit);
        imageView_logo = findViewById (R.id.imageView_logo);
        button_get_started = findViewById(R.id.button_get_started);
        button_get_started.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openRegistrationActivity();
            }
        });

        setContentView(R.layout.activity_splash);
    } //onCreate

    public void openRegistrationActivity(){
        Intent intent = new Intent(MainActivity.this, RegistrationActivity.class);
        startActivity(intent);
    }

And here is my XML File:
    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    tools:context=".MainActivity">

    <!-- thisFIT -->
    <ImageView
        android:id="@+id/imageView_thisfit"
        android:layout_width="205dp"
        android:layout_height="101dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.18"
        app:srcCompat="@drawable/thisfit" />

    <!-- Logo -->
    <ImageView
        android:id="@+id/imageView_logo"
        android:layout_width="218dp"
        android:layout_height="246dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView_thisfit"
        app:srcCompat="@drawable/logo" />

    <!-- GET STARTED -->
    <Button
        android:id="@+id/button_get_started"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:background="@drawable/bg"
        android:text="GET STARTED"
        android:textSize="20sp"
        android:textColor="#FFFFFFFF"
        android:fontFamily="@font/dosis"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.495"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView_logo"
        app:layout_constraintVertical_bias="0.23000002" />

</androidx.constraintlayout.widget.ConstraintLayout>

A: Just move this line
setContentView(R.layout.activity_splash);

at the starting of the onCreate() method.
Like this:-
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    imageView_thisfit = findViewById(R.id.imageView_thisfit);
    imageView_logo = findViewById (R.id.imageView_logo);
    button_get_started = findViewById(R.id.button_get_started);
    button_get_started.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openRegistrationActivity();
        }
    });
}

A: Move the line setContentView(R.layout.activity_splash); below  super.onCreate(savedInstanceState);
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        imageView_thisfit = findViewById(R.id.imageView_thisfit);
        imageView_logo = findViewById (R.id.imageView_logo);
        button_get_started = findViewById(R.id.button_get_started);
        button_get_started.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openRegistrationActivity();
            }
        });

    }


text:
Q: Java: Why could base class method call a non-exist method? class BaseClass {
    private void f() {
        System.out.println("Baseclass f()");
    }

    public static void main(String[] args) {
        BaseClass dc = new DerivedClass();
        dc.f();
    }
}

class DerivedClass extends BaseClass {
    public void f() {
        System.out.println("DerivedClass f()");
    }
}

In my opinion, the object dc refers to should have only one non-override method - public void f() method,which make it(the public method) invisible when refered to with BaseClass reference.Since the object dc referes to does not have the private void f() method either because the DeriverClass could not inherit the private method,how could the object dc refers to call method f()?
thanks.

A: A common(ish) misconception is that private is per instance rather than per class.
For example:
class Foo
{
    private int a;

    public bar(final Foo other)
    {
        other.a = 5;
    }
}

Some people are under the impression that the code above should not work because "a" is "private".  That is not the case, any Foo instance can access the private variables/methods of any other Foo instance.  "private" just means that instances of other classes (other than Foo in this case) cannot access the private members.

A: Just to keep things straight, DerivedClass (DC) DOES inherit private void f() from BaseClass (BC). This inherited method is not accessible to DC but it is there because any method called in the BC part of DC has to have access to all of BC. So when you cast DC to a BC the inherited method becomes available. Now because you are running the code inside of the BC class it can access all of the private members of BC. If you moved the main to DC it shouldn't compile let alone run.

A: The main method is inside BaseClass and the private methods are visible to it. If main is in some other class, it will not compile.

A: Four points:
(1) To elaborate on what vivyzer wrote, the code compiles because the main method in BaseClass has access to the class's own private methods. If you wrote the code as:
class BaseClass {
  private void f() { }
}

class DerivedClass {
  public void f() { }
}

class Bystander {
  public static void main() {
    BaseClass inst = new DerivedClass();
    inst.f();
  }
}

Then the code would not compile.
(2) This is allowed by the language to support the usecase where the author of a base class can add a new private method without worrying about other authors' derived types.
(3) You won't see this if the method was not private. If the base class's f() had package or protected visibility, then the method would be a virtual method.
(4) The reverse of point #2 is not supported by Java. Specifically, if a derived class has a private method, and a new version of the base type introduces a non-private method with the same signature, the derived class and new base class cannot be used together. There are other languages (for example C#) that addresses these sorts of modular, generational development questions more completely. If you are interested in this aspect, this is a good read on Artima: Versioning, Virtual, and Override