Friday, September 3, 2021

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow


How to focus with keyboard on autocomplete box with position absolute in React?

Posted: 03 Sep 2021 08:07 AM PDT

I can't figure out how to make focus on autocomplete box. Could you help me with that?

At first I click on first input, then press tab and focus is on second input. Then I start typing and want to choose the needed option from an autocomplete box with tab, arrow up/down and enter...but when I press tab to focus on autocompelete the focus moves to the last field.enter image description here

Form.js layout

     <div className={styles.formWrapper}>            <form className={styles.form} onSubmit={handleSubmit}>              <label className={styles.inputLabel}>                <input                  className={styles.input}                  placeholder='ФИО полностью'                  type='text'                  onChange={handleNameChange}                  value={name}                  onBlur={handleAcronym}                />                <span className={styles.error}>Ошибка</span>              </label>              <label className={styles.inputLabel}>                <input                  className={styles.input}                  placeholder='Адрес'                  onChange={handleAdressChange}                  value={addressInput}                  onBlur={() => setTimeout(() => setSuggestions([]), 200)}                />                {suggestions.length > 0 && (                  <Suggestions suggestions={suggestions} onSuggestionClick={onSuggestionClick} />                )}                <span className={styles.error}>Здесь текст ошибки какой-то</span>              </label>                    <label className={styles.inputLabel}>                <input                  type='date'                  className={styles.input}                  min={minDate}                  max={maxDate}                  value={inputDate || minDate}                  onChange={handleDateChange}                />                <span className={styles.error}>Здесь текст ошибки какой-то</span>              </label>                    <button type='submit' className={styles.button}>                Вызвать врача              </button>            </form>          </div>    CSS  .formWrapper {    background-color: #f2f6fe;    max-width: 600px;    border-radius: 10px;    margin: 0 auto;  }    .form {    display: flex;    flex-direction: column;    max-width: 500px;    padding: 30px 10px;    margin: 0 auto;  }    .input {    padding: 15px;    border-radius: 10px;    border: 1px solid #ddd;    outline: none;  }    .input:focus {    background: lightyellow;  }    .inputLabel {    display: flex;    flex-direction: column;    position: relative;  }    .inputDate {    margin-bottom: 20px;  }    .error {    font-size: 14px;    padding: 10px 15px 0;    margin-bottom: 20px;    color: #ee3465;  }  .button {    padding: 15px;    border-radius: 10px;    border: none;    background-color: #5ec343;    color: #fff;    outline: none;    cursor: pointer;  }  

Autocomplete layout

    function Suggestions({ suggestions, onSuggestionClick }) {              return (          <ul className={styles.list}>            {suggestions.map((item, idx) => (              <li key={item.data.fias_id + idx} className={styles.listItem} onClick={() => onSuggestionClick(item)} tabindex='1'>                {item.value}              </li>            ))}          </ul>        );      }            export default Suggestions;    CSS  .list {    list-style: none;    padding: 0;    box-sizing: border-box;    background-color: #fff;    border: 1px solid #ddd;    border-bottom-left-radius: 15px;    border-bottom-right-radius: 15px;    position: absolute;    width: 100%;    top: 43px;    left: 0;    margin: 0;    box-shadow: 0 5px 5px 5px #999;    z-index: 1;  }    .listItem {    padding: 15px;    border-bottom: 1px solid #ddd;  }    .listItem:focus {    border: 2px solid red;  }    .listItem:hover {    transition: background-color 0.3s linear;    background: lightgreen;  }    .listItem:last-of-type:hover {    border-bottom-left-radius: 15px;    border-bottom-right-radius: 15px;  }    .listItem:last-of-type {    border-bottom: none;  }  

Creating the Shared Library File from a C File

Posted: 03 Sep 2021 08:06 AM PDT

I'm trying to create a shared library file (.so extension) from my C file to call my C function from Python. I found several websites saying that we can use the following command to do so:

 cc -fPIC -shared -o my_functions.so my_functions.c  

but I am not sure where I need to run this command. I tried running this on the terminal of Visual Studio code but got the following error:

> PS C:\Users\me\Documents\CProgramming\0903_> cc -fPIC -shared -o my_functions.so my_functions.c  cc : The term 'cc' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is  correct and try again.  At line:1 char:1   + cc -fPIC -shared -o my_functions.so my_functions.c  + ~~      + CategoryInfo          : ObjectNotFound: (cc:String) [], CommandNotFoundException      + FullyQualifiedErrorId : CommandNotFoundException  

Does anyone know what is the correct way or correct platform to run this command? I am using Windows. This is the website I referred to: https://www.journaldev.com/31907/calling-c-functions-from-python

Thank you.

How to return an InputStream as a file in Spring Boot?

Posted: 03 Sep 2021 08:06 AM PDT

I have an InputStream to a file obtained from a server through SSH using JSch. I want to return it as a file in my Spring Boot application.

Try using ResponseEntity as I read on many forums but it doesn't work

Why casting double to double emits conv.r8 IL instruction

Posted: 03 Sep 2021 08:06 AM PDT

Is there any reason for the C# compiler to emit a conv.r8 when casting from double -> double ?

This looks to be completely unnecessary (casting from int -> int, char -> char, etc) does not emit equivalent conversion instructions (see this example).

Is there a way to create a container for elements in itextpdf 7

Posted: 03 Sep 2021 08:06 AM PDT

I want to create a kind of container, so that I can evaluate a page break for the document in itext for multiple elements. This is what I would do in HTML:

<div style={{page-break-inside: avoid}}>     <p>Row 1</p>     <p>Row 2</p>  </div>  

How would I do that in itextpdf?

Python Update csv to google sheets. Problem with format

Posted: 03 Sep 2021 08:06 AM PDT

I have a csv file from import business and i try to copy the data of this file in my google sheets. The problem is with the format of the csv file. I try several times and i have an error with NA y use NA FILTER for solve that.But the first column disappeared maybe because maybe it has a NA. That column is critical to me because it has the names of the companies. I'm lost, can you think of any help?

Azulejos = pd.read_csv('IMPORTACIONES-2021-01-01-2021-08-31--6907.23.00.000E (2).csv',sep=";",encoding="latin-1",na_filter= False)    print(Azulejos)    Importador (prob.)     Cuit  ... Código.1 Detalle  CERAMICA MAJA SRL             30707457003  01-2021  ...                   LEMO BALTASAR BRUM            20925092852  01-2021  ...                   LEMO BALTASAR BRUM            20925092852  01-2021  ...                   BALCARCE 54 S.A.              30680857209  01-2021  ...                   BALCARCE 54 S.A.              30680857209  01-2021  ...                   ...                                   ...      ...  ...      ...     ...  BODEN CERAMICS S.R.L.         30716000385  07-2021  ...                   BODEN CERAMICS S.R.L.         30716000385  07-2021  ...                   BODEN CERAMICS S.R.L.         30716000385  07-2021  ...                   BODEN CERAMICS S.R.L.         30716000385  07-2021  ...                   BODEN CERAMICS S.R.L.         30716000385  07-2021  ...                     [574 rows x 59 columns]      [Image from googlesheets][1]                                 #spreadsheet  gc = gspread.service_account(filename='spreadsheet-323416-3a7c20722874.json')  sh = gc.open_by_key('1vL3R_5Fcvo7MPzXNuaGNYr4yG03ie4VCaCRhZUeQhhU')  worksheet = sh.get_worksheet(0)  worksheet.update([Azulejos.columns.values.tolist()] + Azulejos.values.tolist())  

No module named 'statsmodels.tsa.arima' in Colab but not in Pycharm

Posted: 03 Sep 2021 08:06 AM PDT

# ARIMA example  from statsmodels.tsa.arima.model import ARIMA  data = [200,30,30,35,30,20,26,35,30,33,40,29,29,30,30,30,30,20,26,35,30,33,40,29,29,30,30,30]  # fit model  model = ARIMA(data, order=(10, 1, 10))  model_fit = model.fit()  # make prediction  yhat = model_fit.predict(len(data), len(data), typ='levels')  print(yhat)  

The import matplotlib.pyplot as plt is wokring perfectly in pycharm but while running the same code in colab it throws enter image description here There are very few supports there on internet for this library, so I would appreciate any sort of help or any workaround please.

Calculating the value of a field based on the difference between the values of another field in two adjacent positions using haskell

Posted: 03 Sep 2021 08:05 AM PDT

I have a list of custom data objects which track an increasing total value on a daily basis using one field total. Another field in the custom data type is the value new. Using a csv file I have read in the values for date and total and am trying to calculate and set the values for new from these values.

data item = Item{      date :: Day,      total :: Int,      new :: Int  }  

Before

date total new
01/01/2021 0 0
02/01/2021 2 0
03/01/2021 6 0
04/01/2021 15 0

After

date total new
01/01/2021 0 0
02/01/2021 2 2
03/01/2021 6 4
04/01/2021 15 9

My understanding is that in haskell I should be trying to avoid the use of for loops which iterate over a list until the final row is reached, for example using a loop control which terminates upon reaching a value equal to the length of the list.

Instead I have tried to create a function which assigns the value of new which can used with map to update each item in the list. My problem is that such a function requires access to both the item being updated, as well as the previous item's value for total and I'm unsure how to implement this in haskell.

--Set daily values by mapping single update function across list  calcNew:: [Item] -> Int -> [Item]  calcNew items = map updateOneItem items     -- takes an item and a value to fill the new field  updateOneItem :: Item -> Int -> Item  updateOneItem item x = Item date item total item x  

Is it possible to populate that value while using map? If not, is a recursive solution required?

Finding a value in an array of arrays in excel

Posted: 03 Sep 2021 08:05 AM PDT

I'm trying to indicate if an ID from one table is listed in another, using the following formula I almost get what I want except I get false negatives when an item in Table1 has multiple links listed. I thought FIND might help but can't work it out. =NOT(ISERROR(MATCH([@ID],Table1[LINKS],0)))

Table1 |ID|LINKS| |--|-----| |01| | |02| 01 | |03| 01 \n 02| |04| 03 |

Table2 |ID|LINKED| |--|------| |01| TRUE | |02| FALSE| |03| TRUE | |04| FALSE|

Flutter how to stop listening single firestore doc file (flutter 2.2 null safety)

Posted: 03 Sep 2021 08:05 AM PDT

I'm listening doc changes on a single document. But I have no luck to stop listening the file. It's keep listening even after Get.offNamedUntil('/', (route) => false);

@override      void initState() {        super.initState();        var listeningNumbers = FirebaseFirestore.instance.collection('numbers').doc(myID).snapshots();              listeningNumbers.listen((docSnapshot) {          ...        });      }  }  

How can I remove listener?

How to add mobile number validater in Django model?

Posted: 03 Sep 2021 08:05 AM PDT

def validate_mobile_number(value): if not str(value).isdigit(): raise ValidationError("Please Enter Valid Mobile Number") class ModelA(AbstractUser):
mobile = models.CharField(_("Mobile"), unique=True, max_length=10,validators[validate_mobile_number,validators.MinLengthValidator(limit_value=10)])

Cannot open sever.jar file

Posted: 03 Sep 2021 08:05 AM PDT

So I was trying to make a 1.17.1 minecraft server on my mac. I couldn't open my 1.17.1_server.jar with Java 8 so I download Java 16.0.2.

Unfortunately, everytime I was opening the 1.17.1_server.jar file, I got "The Java JAR file "1.17._server.jar" could not be launched." .

error image

I first thought that it was because the file was launch by Java 8 instead of 16. So I went into the terminal and run :<path to java> -jar 1.17.1_server.jar

I then got this : Error: Unable to access jarfile 1.17.1_server.jar

Finally i tried to put the path of the jar file in the command... So I've run : path to java -jar path to server and got this :

[main/ERROR]: Failed to load properties from file: server.properties

[15:57:35] [main/WARN]: Failed to load eula.txt

[15:57:35] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.

So why I have to agreed Eula if i've never launched it ? Does it think that he already been launched ? thx in advance for the help. Hope someone will find the source of the problem.

How to increment a key in the dictionary?

Posted: 03 Sep 2021 08:06 AM PDT

I'm new to javascript and I'm trying to increment a key in the dictionary

var dic = {}  for (let i = 0; i < 100; i++) {      dic['key']++          }  console.log(dic)

I don't get the incremented number, where am I going wrong?

Query doesn't work and I don't understand why [duplicate]

Posted: 03 Sep 2021 08:06 AM PDT

I have a php file and I should get the information of two tables from my database. To do this I wrote two queries. The tables name are "key_test" and "form". More specifically, the "form" table is structured as follows: "form (name, type, username, category)" where type, username and category are primary keys. The query I wrote is the following:

    $campi_form=mysqli_query($db, "SELECT *                                      FROM form                                      WHERE form.type='text' OR form.type='int' OR form.type='varchar' OR form.type='date'                                      AND form.username = $username AND form.category = $categoria");      $num = mysqli_num_rows($campi_form);      $row_due=mysqli_fetch_assoc($campi_form);      var_dump($num);  

The problem is this query doesn't work and I don't understand why. I tried to remove the AND condition in the WHERE clause and it works. But I also need to check the "username" and "category" fields. Where am I doing wrong? I state that the $category and $username variables contain the correct values, and correspond to the values ​​I find in the "form" table

How to ignore a Regex match, if there is a specific prefix

Posted: 03 Sep 2021 08:06 AM PDT

I am using this expression to find paths.

([^\s\&\=\;\,\<\<\>\"\'\(\)]+\/[\w\/])([^\"\'\n\;\}\)\s]*)  

Current matches are:

Location: /user/login.php xx... /user/login xx... text/html abcd type text/html hey abc/def

I want to ignore match which has "type " prefix

So It should be like this.

Location: /user/login.php xx... /user/login xx... text/html abcd type text/html hey abc/def

TOMEEE - Can't lookup ejb

Posted: 03 Sep 2021 08:06 AM PDT

I have implemented a basic EJB Object in my code. Then I created a jar for this ejb. The jar file contains:

  1. package containing the ejb classes (home interface/remote bean interface/bean implementaion)
  2. META-INF folder containing the ejb-jar.xml

ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>  <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">  <ejb-jar>    <display-name>NewTransactionEjb</display-name>    <enterprise-beans>      <session>        <display-name>NewTransactionEjb</display-name>        <ejb-name>NewTransactionEjb</ejb-name>        <home>gr.cosmote.mdb.NewTransactionEjb.NewTransactionEjbHome</home>        <remote>gr.cosmote.mdb.NewTransactionEjb.NewTransactionEjb</remote>        <ejb-class>gr.cosmote.mdb.NewTransactionEjb.NewTransactionEjbBean</ejb-class>        <session-type>Stateless</session-type>        <transaction-type>Container</transaction-type>      </session>    </enterprise-beans>    <assembly-descriptor>      <container-transaction>        <method>          <ejb-name>NewTransactionEjb</ejb-name>          <method-name>*</method-name>        </method>        <trans-attribute>NotSupported</trans-attribute>      </container-transaction>    </assembly-descriptor>  </ejb-jar>    

Then I deployed the EJB by placing the jar in webapps folder and from the server logs it seems to have been deployed successfully. But when I try to reference the ejb from my code I get error. Code:

Properties p = new Properties();                     p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");                     InitialContext context = new InitialContext(p);                     ejbHome = (EJBHome) context.lookup("java:global/NewTransactionEjb/NewTransactionEjb");  

I have used "java:global/NewTransactionEjb/NewTransactionEjb" because upon ejb deployment I see this line in the server logs:

03-Sep-2021 17:31:23.628 INFO [Catalina-utility-1] org.apache.openejb.assembler.classic.JndiBuilder.bind Jndi(name=global/NewTransactionEjb/NewTransactionEjb!gr.cosmote.mdb.NewTransactionEjb.NewTransactionEjbHome)   --> Ejb(deployment-id=NewTransactionEjb)  

In the execution it seems the the above code is working and it retrieves the EJBHome, but when I try to cast it to my own home interface class it fails with the following error:

java.lang.ClassCastException: com.sun.proxy.$Proxy362 cannot be cast to  gr.cosmote.mdb.NewTransactionEjb.NewTransactionEjbHome  

What am I doing wrong?

New dict filtered by item

Posted: 03 Sep 2021 08:06 AM PDT

Could you help me with this simple stuff, unfortunately I don't get it.

I have this a list with two another lists with lists of dicts (but it can be more lists).

a = [      [          {'DESCRIP': '', 'INTF': 'Vl77', 'PROTOCOL': 'up', 'STATUS': 'up'},          {'DESCRIP': '', 'INTF': 'Fa0', 'PROTOCOL': 'down', 'STATUS': 'admin down'}      ],      [          {'INBOUND_ACL': '', 'INTF': 'Vlan77', 'IPADDR': ['192.168.77.11/24'], 'IP_HELPER': [], 'LINK_STATUS': 'up', 'MTU': '1500', 'OUTGOING_ACL': '', 'PROTOCOL_STATUS': 'up', 'VRF': ''},          {'INBOUND_ACL': '', 'INTF': 'FastEthernet0', 'IPADDR': [], 'IP_HELPER': [], 'LINK_STATUS': 'administratively down', 'MTU': '', 'OUTGOING_ACL': '', 'PROTOCOL_STATUS': 'down', 'VRF': ''}      ]  ]  

My goal is to get a final list of merged dicts, derived by a rule ('merge all dicts that contain the 'INTF' field with the same number, in this case 77 or 0 , in other words to filter by interface number').

boostrap 3 + datatables buttons: misalignment

Posted: 03 Sep 2021 08:06 AM PDT

I'm experiencing misalignment when using boostrap 3 and datatables buttons (https://datatables.net/extensions/buttons/). How to align them propery? enter image description here

everything works fine when on div.dt-buttons margin is set margin-top:2px;, don't know why, but it feels wrong is there any "standard way"?

$(document).ready(function(myApp) {    myApp.myDataTable = $('.my-table').DataTable({      fixedHeader: true,      paging: true,      buttons: {        dom: {          button: {            className: ''          }        },        buttons: [{          extend: 'colvis',          tag: 'button',          className: 'btn btn-default'        }]      }    });    }(window.myApp = window.myApp || {}));
<html>  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"/>  <!-- Latest compiled and minified CSS -->  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">      <!-- Optional theme -->      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">          <!-- Latest compiled and minified JavaScript -->          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"/>          <script src="https://cdn.datatables.net/1.11.0/js/jquery.dataTables.min.js"/>          <script src="https://cdn.datatables.net/1.11.0/js/dataTables.bootstrap.min.js"/>          <link rel="stylesheet" href="https://cdn.datatables.net/1.11.0/css/dataTables.bootstrap.min.css"/>     <body>      <div class="col-xs-12">              <div class="panel">                  <div class="panel-heading">                      <h3 class="panel-title">test</h3>                  </div>                  <!--Data Table-->                  <!--===================================================-->                  <div class="panel-body">                      <div class="table-responsive">                          <table class="my-table table table-striped">                              <thead>                                  <tr>                                      <th>told</th>                                      <th>disease</th>                                      <th>led</th>                                      <th>running</th>                                      <th>importance</th>                                  </tr>                              </thead>                              <tr>                                  <td>told</td>                                  <td>disease</td>                                  <td>led</td>                                  <td>running</td>                                  <td>importance</td>                              </tr>                              <tr>                                  <td>bush</td>                                  <td>continent</td>                                  <td>fruit</td>                                  <td>policeman</td>                                  <td>this</td>                              </tr>                              <tr>                                  <td>person</td>                                  <td>uncle</td>                                  <td>saddle</td>                                  <td>pilot</td>                                  <td>special</td>                              </tr>                              <tr>                                  <td>duty</td>                                  <td>onlinetools</td>                                  <td>thing</td>                                  <td>unknown</td>                                  <td>browserling</td>                              </tr>                              <tr>                                  <td>return</td>                                  <td>little</td>                                  <td>grade</td>                                  <td>factory</td>                                  <td>involved</td>                              </tr>                              <tr>                                  <td>major</td>                                  <td>kids</td>                                  <td>flight</td>                                  <td>sink</td>                                  <td>port</td>                              </tr>                          </table>                      </div>                  </div>                  <!--===================================================--      >                  <!--End Data Table-->              </div>          </div>      </body>      </html>          

Update NO.1 Why I'm using boostrap-3?

working with an old template, can't upgrade it

Linked list Interview question - Find building view in O(n)

Posted: 03 Sep 2021 08:06 AM PDT

There's a linked-list that represents building with view towards the sea. Each building has some height I the goal is to find what you see from the top of the building Another building or if nothing stand in the way - the sea.

for example - visual representation of the buildings

For the input above(from left to right), the output will be the - 0 1 0 0 4 4 4 7

If the building is looking towards the sea the output for it is 0. The time complexity needed is O(n)

How to handle two extracted elements respecting the order they appear - Python Selenium

Posted: 03 Sep 2021 08:06 AM PDT

I have two elements that need to be extracted in the same hierarchy order. 'Name' repeats across the page 20 times but the 'URL' only exists in 5 of them. However, I need to know that the 'URL' identified in order 2 refers to the 'Name' identified in order 10, for example.

The problem is the structure. When there is no 'URL', there is no tag 'a' with 'href'.

Structure:

When I have 'URL'=

<div class="middle">     <h5>        <p>           <a href="www.example.com" target="_blank" class="entry-name clickable">              <span class>NAME</span>           </a>        </p>     </h5>  </div>

When I don't have URL:

<div class="middle">     <h5>        <p>           <span class>NAME</span>        </p>     </h5>  </div>

My code is working in this way:

name = driver.find_elements_by_xpath("//*[@class='middle']/h5/p")    name_list = []  for n in name:      name = n.text      name_list.append(name)    url = driver.find_elements_by_xpath("//*[@class='middle']/h5/p/a")    url_list = []  for n in url:  url = n.get_attribute('href')  url_list.append(url)

In 'name_list' I have 20 results and in url_list I have only 5 results. The problem is I don't know which URL represents which name.

Ideally, in this example 'url' would return 20 elements with null values where there is no URL.

SQL alphanumerical sorting with non specific format

Posted: 03 Sep 2021 08:05 AM PDT

I got to sort strings that do not share the same format and I got trouble finding a solution for this one. Tried several options on stackoverflow for this but it does not work for me because they are for specific formatted data.

Here are an example of data i must sort.

12-ABC  1-ABC  ABC-10  ABC-11  ABC-100  2-ABCD  ABC-100A  

I got results like this with ORDER BY

1-ABC  12-ABC  2-ABCD  ABC-10  ABC-100  ABC-100A  ABC-11  

But i would like to have this

1-ABC  2-ABCD  12-ABC  ABC-10  ABC-11  ABC-100  ABC-100A  

How would you do it?

Spring boot tasks not completed

Posted: 03 Sep 2021 08:06 AM PDT

I am working on a spring boot application (deployed on aws elastic beanstalk) where there are some long running tasks that sometimes do not complete. I know they don't because I have a log before starting and after ending. For example a task is getting a zip file with images and posting them on aws S3. Sometimes it stops before uploading all the images. Another task is getting a csv or json file and updating data in the database, same problem.

I am wondering if this is due to some aws operations (auto scaling for example) or a performance of the vm issue

Example of code posting images to S3

for(int i = 0; i < images.size(); i++) {  saveLog("uploading " + (i+1) + ".JPG");  try {      uploadedAutres += doUploadOneOfMultipleImages(product,              ImageIO.read(zipFile.getInputStream(images.get(i))), i , false); //i + product.getNombreImagesAutre()  } catch (Throwable e) {      saveLog("failed uploading " + (i+1) + ".JPG\n" + e.getMessage());      e.printStackTrace();      break;  }  }    public int doUploadOneOfMultipleImages(Product product, BufferedImage image, int i, boolean threeSixty) {          ByteArrayOutputStream largeByteArray = new ByteArrayOutputStream();          ByteArrayOutputStream mediumByteArray = new ByteArrayOutputStream();            try {              ImageIO.write(image, "png", largeByteArray);              ImageIO.write(resizeImageExample.resize(image, 434, 650), "png", mediumByteArray);              largeByteArray.close();              mediumByteArray.close();                String largeFileName = threeSixty ? "" : "autre/";              String newFileName = threeSixty ? "" : "autre/";              newFileName += product.getReference() + "/";              largeFileName += product.getReference() + "/large_";              if(i+1 <= 9) {                  newFileName += "0";                  largeFileName += "0";              }              newFileName += i+1;              newFileName += ".jpg";              largeFileName += i+1;              largeFileName += ".jpg";              objectOperations.upload(bucketName, newFileName, mediumByteArray.toByteArray(), "image/jpeg");              objectOperations.upload(bucketName, largeFileName, largeByteArray.toByteArray(), "image/jpeg");              return 1;          } catch (Exception e) {              return 0;          }      }    public void upload(String bucketName, String objectKey, byte[] objectBytes, String contentType) throws Exception {            String result = putS3Object(s3Client, bucketName, objectKey, objectBytes, contentType);        }      public String putS3Object(S3Client s3, String bucketName, String objectKey, byte[] objectBytes, String contentType) throws Exception {              PutObjectResponse response = s3.putObject(PutObjectRequest.builder()                              .bucket(bucketName)                              .key(objectKey)                              .contentType(contentType)                              .build(),                      RequestBody.fromBytes(objectBytes));              return response.eTag();      }    

When it stops it's in the middle of the loop (for(int i = 0; i < images.size(); i++)) and no exception is thrown

PostgreSQL recursive query for calculation parent value

Posted: 03 Sep 2021 08:05 AM PDT


Here is entry's hierarchy.
             _________Milky Way (30)________              /               |               \      Alpha(10)           Beta(20)            Delta(null)       /  \                                       |  Mars(7) Jupiter(3)                          Delta-child(44)  

Parents value is a sum of it's children's values. Ex.

Alpha = Mars + Jupiter = 7 + 3 = 10  Milky Way = Alpha + Beta + Delta = 10 + 20 + null = 30   

The task: recalculate parents up to the root in case any child is updated. Let's even simplify the task: select all entries up to the root with recalculated values.
Imagine that Mars is updated. Now Mars value is 2.

             _________Milky Way (?)________              /               |               \      Alpha(?)            Beta(20)            Delta(null)       /  \                                       |  Mars(2) Jupiter(3)                          Delta-child(44)  

It means that all parents should be updated:

Alpha = Mars + Jupiter = 2 + 3 = 5  Milky Way = Alpha + Beta + Delta = 5 + 20 + null =  25.  

Note: Delta -> Delta-child coupling is broken and it's fine. It can happen lets leave it out of scope here. 've added this sample just to be sure that it won't be counted during calculation as hierarchy can be huge enough and tehre is no task to recalculate all children leaf, just parents up to the root.

As a result of some "select .. from hierarchy.." I'd like to receive recalculated parents' values.
Ex.

id name value
1 Milky Way 25
2 Alpha 5

Code samples with already updated Mars (sqlfiddle links are below):
Schema

CREATE TABLE hierarchy          (          id int4,          parent_id int4,          name varchar(255),          value int4          );            

Values

insert into hierarchy  values  (1, null, 'Milky Way', 30),  (2, 1, 'Alpha', 10),  (3, 1, 'Beta', 20),  (4, 1, 'Delta', null),  (5, 2, 'Mars', 2),  (6, 2, 'Jupiter', 3),  (7, 4, 'Delta-child', 44);  

What I have tried:

  1. I was able to list all leafs which should be used in calculation
    sqlfiddle 1

    WITH RECURSIVE cte AS (     SELECT h1.id,  h1.parent_id, h1.name , h1.value from hierarchy h1    where h1.id = 5       UNION   SELECT h2.id,  h2.parent_id, h2.name , h2.value from hierarchy h2   JOIN cte cte ON (cte.parent_id = h2.parent_id or cte.parent_id = h2.id )    where cte.id != h2.id   ) select * from cte  order by id  
  2. When I tried to sum values, query goes in infinite loop for some reason
    sqlfiddle 2

     WITH RECURSIVE cte AS (     SELECT h1.id,  h1.parent_id, h1.name , h1.value from hierarchy h1    where h1.id = 5       UNION   SELECT h2.id,  h2.parent_id, h2.name , (h2.value + cte.value) as value from hierarchy h2   JOIN cte cte ON (cte.parent_id = h2.parent_id or cte.parent_id = h2.id )    where cte.id != h2.id   ) select * from cte  order by id  
  3. There is one more query that I have tried, unfortunately it doesn't count sibling of parents.
    sqlfiddle 3

                WITH RECURSIVE cte AS (            SELECT h1.id,  h1.parent_id, h1.name , h1.value from hierarchy h1            where h1.parent_id = (select parent_id from hierarchy where id = 5)                 UNION           SELECT h2.id,  h2.parent_id, h2.name , cte.value as value from hierarchy h2           JOIN cte cte ON (cte.parent_id = h2.parent_id or cte.parent_id = h2.id )            where cte.id != h2.id           ) select id, parent_id, name, sum(value) from cte          group by id, parent_id, name          order by id  

I'd appreciate any assistance. :-)

SVG animation logo

Posted: 03 Sep 2021 08:06 AM PDT

I have an SVG logo with two lines, one on top and the other on bottom.

I am trying to get both of the lines to expand from the middle all the way to the end.

https://codepen.io/christos_karol/pen/BaZzOmO?editors=1100

.line3, .line2 {    stroke-dasharray:2300;      stroke-dashoffset:2300;      animation: dash 5s linear forwards;  }    @keyframes dash {      to {      stroke-dashoffset:0;    }  }
<svg width="324" height="51" viewBox="0 0 324 51" fill="none" xmlns="http://www.w3.org/2000/svg">        <path id="DENNIS PRESTON" d="M0.104 12.8H10.364C13.028 12.8 15.38 13.34 17.42 14.42C19.46 15.476 21.044 16.964 22.172 18.884C23.3 20.78 23.864 22.952 23.864 25.4C23.864 27.848 23.3 30.032 22.172 31.952C21.044 33.848 19.46 35.336 17.42 36.416C15.38 37.472 13.028 38 10.364 38H0.104V12.8ZM10.22 35.696C12.428 35.696 14.36 35.264 16.016 34.4C17.672 33.512 18.956 32.3 19.868 30.764C20.78 29.204 21.236 27.416 21.236 25.4C21.236 23.384 20.78 21.608 19.868 20.072C18.956 18.512 17.672 17.3 16.016 16.436C14.36 15.548 12.428 15.104 10.22 15.104H2.768V35.696H10.22ZM47.6662 35.696V38H29.8462V12.8H47.1262V15.104H32.5102V24.068H45.5422V26.336H32.5102V35.696H47.6662ZM74.9882 12.8V38H72.7922L56.5922 17.552V38H53.9282V12.8H56.1242L72.3602 33.248V12.8H74.9882ZM104.273 12.8V38H102.077L85.8774 17.552V38H83.2134V12.8H85.4094L101.645 33.248V12.8H104.273ZM112.499 12.8H115.163V38H112.499V12.8ZM130.31 38.216C128.438 38.216 126.638 37.916 124.91 37.316C123.206 36.716 121.886 35.924 120.95 34.94L121.994 32.888C122.906 33.8 124.118 34.544 125.63 35.12C127.142 35.672 128.702 35.948 130.31 35.948C132.566 35.948 134.258 35.54 135.386 34.724C136.514 33.884 137.078 32.804 137.078 31.484C137.078 30.476 136.766 29.672 136.142 29.072C135.542 28.472 134.798 28.016 133.91 27.704C133.022 27.368 131.786 27.008 130.202 26.624C128.306 26.144 126.794 25.688 125.666 25.256C124.538 24.8 123.566 24.116 122.75 23.204C121.958 22.292 121.562 21.056 121.562 19.496C121.562 18.224 121.898 17.072 122.57 16.04C123.242 14.984 124.274 14.144 125.666 13.52C127.058 12.896 128.786 12.584 130.85 12.584C132.29 12.584 133.694 12.788 135.062 13.196C136.454 13.58 137.654 14.12 138.662 14.816L137.762 16.94C136.706 16.244 135.578 15.728 134.378 15.392C133.178 15.032 132.002 14.852 130.85 14.852C128.642 14.852 126.974 15.284 125.846 16.148C124.742 16.988 124.19 18.08 124.19 19.424C124.19 20.432 124.49 21.248 125.09 21.872C125.714 22.472 126.482 22.94 127.394 23.276C128.33 23.588 129.578 23.936 131.138 24.32C132.986 24.776 134.474 25.232 135.602 25.688C136.754 26.12 137.726 26.792 138.518 27.704C139.31 28.592 139.706 29.804 139.706 31.34C139.706 32.612 139.358 33.776 138.662 34.832C137.99 35.864 136.946 36.692 135.53 37.316C134.114 37.916 132.374 38.216 130.31 38.216ZM164.364 12.8C167.58 12.8 170.1 13.568 171.924 15.104C173.748 16.64 174.66 18.752 174.66 21.44C174.66 24.128 173.748 26.24 171.924 27.776C170.1 29.288 167.58 30.044 164.364 30.044H157.596V38H154.932V12.8H164.364ZM164.292 27.704C166.788 27.704 168.696 27.164 170.016 26.084C171.336 24.98 171.996 23.432 171.996 21.44C171.996 19.4 171.336 17.84 170.016 16.76C168.696 15.656 166.788 15.104 164.292 15.104H157.596V27.704H164.292ZM197.628 38L191.868 29.9C191.22 29.972 190.548 30.008 189.852 30.008H183.084V38H180.42V12.8H189.852C193.068 12.8 195.588 13.568 197.412 15.104C199.236 16.64 200.148 18.752 200.148 21.44C200.148 23.408 199.644 25.076 198.636 26.444C197.652 27.788 196.236 28.76 194.388 29.36L200.544 38H197.628ZM189.78 27.74C192.276 27.74 194.184 27.188 195.504 26.084C196.824 24.98 197.484 23.432 197.484 21.44C197.484 19.4 196.824 17.84 195.504 16.76C194.184 15.656 192.276 15.104 189.78 15.104H183.084V27.74H189.78ZM224.256 35.696V38H206.436V12.8H223.716V15.104H209.1V24.068H222.132V26.336H209.1V35.696H224.256ZM237.466 38.216C235.594 38.216 233.794 37.916 232.066 37.316C230.362 36.716 229.042 35.924 228.106 34.94L229.15 32.888C230.062 33.8 231.274 34.544 232.786 35.12C234.298 35.672 235.858 35.948 237.466 35.948C239.722 35.948 241.414 35.54 242.542 34.724C243.67 33.884 244.234 32.804 244.234 31.484C244.234 30.476 243.922 29.672 243.298 29.072C242.698 28.472 241.954 28.016 241.066 27.704C240.178 27.368 238.942 27.008 237.358 26.624C235.462 26.144 233.95 25.688 232.822 25.256C231.694 24.8 230.722 24.116 229.906 23.204C229.114 22.292 228.718 21.056 228.718 19.496C228.718 18.224 229.054 17.072 229.726 16.04C230.398 14.984 231.43 14.144 232.822 13.52C234.214 12.896 235.942 12.584 238.006 12.584C239.446 12.584 240.85 12.788 242.218 13.196C243.61 13.58 244.81 14.12 245.818 14.816L244.918 16.94C243.862 16.244 242.734 15.728 241.534 15.392C240.334 15.032 239.158 14.852 238.006 14.852C235.798 14.852 234.13 15.284 233.002 16.148C231.898 16.988 231.346 18.08 231.346 19.424C231.346 20.432 231.646 21.248 232.246 21.872C232.87 22.472 233.638 22.94 234.55 23.276C235.486 23.588 236.734 23.936 238.294 24.32C240.142 24.776 241.63 25.232 242.758 25.688C243.91 26.12 244.882 26.792 245.674 27.704C246.466 28.592 246.862 29.804 246.862 31.34C246.862 32.612 246.514 33.776 245.818 34.832C245.146 35.864 244.102 36.692 242.686 37.316C241.27 37.916 239.53 38.216 237.466 38.216ZM257.211 15.104H248.355V12.8H268.731V15.104H259.875V38H257.211V15.104ZM283.651 38.216C281.155 38.216 278.887 37.664 276.847 36.56C274.831 35.432 273.247 33.896 272.095 31.952C270.967 30.008 270.403 27.824 270.403 25.4C270.403 22.976 270.967 20.792 272.095 18.848C273.247 16.904 274.831 15.38 276.847 14.276C278.887 13.148 281.155 12.584 283.651 12.584C286.147 12.584 288.391 13.136 290.383 14.24C292.399 15.344 293.983 16.88 295.135 18.848C296.287 20.792 296.863 22.976 296.863 25.4C296.863 27.824 296.287 30.02 295.135 31.988C293.983 33.932 292.399 35.456 290.383 36.56C288.391 37.664 286.147 38.216 283.651 38.216ZM283.651 35.84C285.643 35.84 287.443 35.396 289.051 34.508C290.659 33.596 291.919 32.348 292.831 30.764C293.743 29.156 294.199 27.368 294.199 25.4C294.199 23.432 293.743 21.656 292.831 20.072C291.919 18.464 290.659 17.216 289.051 16.328C287.443 15.416 285.643 14.96 283.651 14.96C281.659 14.96 279.847 15.416 278.215 16.328C276.607 17.216 275.335 18.464 274.399 20.072C273.487 21.656 273.031 23.432 273.031 25.4C273.031 27.368 273.487 29.156 274.399 30.764C275.335 32.348 276.607 33.596 278.215 34.508C279.847 35.396 281.659 35.84 283.651 35.84ZM323.894 12.8V38H321.698L305.498 17.552V38H302.834V12.8H305.03L321.266 33.248V12.8H323.894Z" fill="#efefec"/>        <path class="line2" d="M321.11 49L4.60998 49" stroke="#efefec" stroke-width="2.89" stroke-linecap="square"/>        <line class="line3" x1="4.445" y1="1.555" x2="320.665" y2="1.555" stroke="#efefec" stroke-width="2.89" stroke-linecap="square"/>      </svg>

Cache MySQL DB with Apache Ignite

Posted: 03 Sep 2021 08:05 AM PDT

I have some application written in JAVA. We are using MySQL DB. It is possible to integrate that MySQL DB with Apache Ignite as In Memory cache and use that configuration without any updates in JAVA application (of course some DB connection details should be changed)?

So my application do the same staff but only difference will be connection with Apache Ignite instead of MySQL?

It is possible this kind of configuration?

Golang Static folder path returns all files

Posted: 03 Sep 2021 08:05 AM PDT

i have a this code to open static folder

fs := http.FileServer(http.Dir("./static/"))  router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fs))  

but when i'm going to /static path it returns a list of files in this folder

eg

license.txt  logo.png  

but i want to return a blank page

How can you programmatically lock a Chromebook?

Posted: 03 Sep 2021 08:05 AM PDT

I have a Chrome OS device, and I want to programmatically lock the screen when a timer has expired (when a child has used up their available screen time). The Chromebook supports Android apps, but I can't find much information about how to do this specific to Chrome OS. I have found information about using the DevicePolicyManager LockNow Android function, which I really thought would do it - but it doesn't. It locks my Android phone just fine, but when I deploy it to my Chromebook (an Acer R 13), the line hits, continues without issue, but does nothing. I get the proper security prompt the first time to set the app as a device admin, but the LockNow code appears to do absolutely nothing despite working perfectly on my Samsung Note 9.

Does anyone know of some documentation or able to point me in the right direction? Thanks

Convert apk to aab

Posted: 03 Sep 2021 08:06 AM PDT

I have compiled my app as an apk, but Google Play rejected the format saying that I need to optimize it. Now I know I have to upload an aab file. How can I convert my apk file into an aab one?

Warning message

Create refresh and access token jwt using java

Posted: 03 Sep 2021 08:06 AM PDT

I am using jjwt to create token using the documentation on github https://github.com/jwtk/jjwt#specification-compliant

I understood that I have to create a refresh token store it on my database and use it to create an access token for the user. But I don't find a simple example to help me to understand how to code it. I am able to create a token following the github documentation but i don"t know how to create a refresh token and then an access token using my refresh one.

I am using java on android studio and as back up api using App Engine Java servlet module

Can I apply CSS filters ONLY on image sections?

Posted: 03 Sep 2021 08:05 AM PDT

I have a full screen background-image

.bg {       left: 0;      min-height: 100%;       min-width: 100%;       position: fixed;       top: 0;       z-index: -1;   }  

and want to apply a CSS filter, personally I would like to use a blur effect, at the same position as my body

.container {      margin: 0 auto;       width: 1000px;  }  

Here's an example:

screenshot

I want to write text over the blurred container.

No comments:

Post a Comment