StackOverflow.com

VN:F [1.9.22_1171]
Rating: 9.3/10 (9 votes cast)

Random snippets of all sorts of code, mixed with a selection of help and advice.

Updating DigitalOcean Droplet user_data metadata field after the droplet is already created via API

15 July 2020 @ 4:54 pm

When using the digital ocean api endpoint /v2/droplets to create a new droplet you can pass for example user_data (a string that can be used to configure the Droplet on first boot). My question, is if I want to create a droplet without the user_data initially and then later add the user_data string to the already booted droplet. It appears this is not possible. The only thing I can think would be to maybe create a tag with the string I want to pass and then associate that new tag to the existing droplet. Is this a viable option for this scenario? Finally, is there any way to create a DO droplet so the entire VM builds but does not boot. It seems with the API that whenever you issue a request to create droplet it will always boot. I'm trying to evaluate if you can simply build the VM, and have it sit powered off until when ready to issue a power cycle on request. Thank you! 🙏

How to Make Jenkin Pipeline wait for after each parallel job

15 July 2020 @ 4:54 pm

because of the blue ocean view I want to do parallel steps. Is therethere a way to force QA to wait for DEV to stop and then start. Only solution I found was using sleep, but I'm not sure how much first job will continue. Any advice would be nice ! pipeline { agent any stages { stage("Test") { steps { script { parallel( DEV: { sleep 5 echo 'DEV' }, QA: { sleep 6 echo 'QA' } ) } } } } }

Next Greater Node In Linked List (JavaScript)

15 July 2020 @ 4:54 pm

I'm trying too implement this algorithm in JavaScript. We are given a linked list with head as the first node. Let's number the nodes in the list: node_1, node_2, node_3, ... etc. Each node may have a next larger value: for node_i, next_larger(node_i) is the node_j.val such that j > i, node_j.val > node_i.val, and j is the smallest possible choice. If such a j does not exist, the next larger value is 0. Return an array of integers answer, where answer[i] = next_larger(node_{i+1}). Note that in the example inputs (not outputs) below, arrays such as [2,1,5] represent the serialization of a linked list with a head node value of 2, second node value of 1, and third node value of 5. Example: Input: [1,7,5,1,9,2,5,1] Output: [7,9,9,9,0,5,0,0] My solution: /** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val===undefined ? 0 : val) * this.next = (next=

Obtain Access Token for the connection to PostgreSQL in Azure Functions

15 July 2020 @ 4:54 pm

I have created some Azure Functions, and I would like to connect to Postgres database using an Access Token (for the connection of the user is doing the request to the endpoint of Azure Function). I've been following this page: https://docs.microsoft.com/en-us/azure/postgresql/howto-configure-sign-in-aad-authentication For Authentication/Authorization in my functions I have created an Azure Active Directory app (in App registrarions). In this app, (not sure if this is useful) I have given permissions to the API of OSSRDBMS: enter image description here Then, I get the Access Token of the next endpoint of my App Service (where are my Functions): MYAPP_SERVICE.azurewebsites.net/.auth/me

Does runpy or importlib have more support going into the future of Python?

15 July 2020 @ 4:54 pm

I am trying to decide whether or not to use the module runpy or importlib for reading files and the main argument point will be which module will be supported longer? I would like to not have to adapt my files too much in the next 5-10 years so that is my motive I guess. Also, just as a general question- I was not sure where to find this type of information about Python modules (e.g. Is this module still supported and if so is there any way to know if it will become deprecated or obsolete in the future?) Looking for a point in the right direction thanks!

How to fix "ValueError: setting an array element with a sequence" when calling pad_sequences in keras

15 July 2020 @ 4:54 pm

I haven't posted on stack overflow in a long time so if I am missing something please let me know. I am just confused why the code below is giving me a value error and saying that setting a pad_sequences parameter to a sequence gives of an error when the documentation says that a sequence is indeed required. train_df2 is formatted like this (shows only one row) Label [0,0,0,0,1,0,0] Sentence (glove embedded) [[1,2,3,4,5,6,7,8,9],......, [3,4,5,6,2,3,4,6,4]] train_df2 = train_df2.sample(frac = 1).reset_index(drop = True) inputList = np.asarray(train_df2.iloc[:,1].tolist()) labelList = np.asarray(train_df2.iloc[:,0].tolist()) input_padding = tf.keras.preprocessing.sequence.pad_sequences([i for i in inputList], maxlen = 100, dtype='float32', padding='post') stopper = tf.keras.callbacks.EarlyStopping(monitor='loss', patience=3)

How do we pass dynamic variable into JavaScript dictionary

15 July 2020 @ 4:54 pm

i have mentioned bellow code i want that when user put amount in input field i want this amount to be add in java script amount key form <form id="payment-form"> <input type="number" name="amount" id="amount"> </form> script <script> SpreedlyExpress.init("C7cRfNJGODKh4Iu5Ox3PToKjniY", { "amount": "$9.83", "company_name": "AA crypto hedge" }); </script> actually i want to change amount dynamicaly in $9.00 when user enter amount in input field

How do we make cases Client Calls (visible to Client) like we used to do in legacy HD

15 July 2020 @ 4:54 pm

In Legacy HD, when we raise a new case, it was my default internal and we had to specifically make it "Client Call" to make it visible to Clients. How do we do the same in new interface for raising cases as well, or is it by default visible to Client when we open a new case?

Calculate interval period between two non zero demands in R

15 July 2020 @ 4:50 pm

I've below data time series data - with the columns Model Month Year Quantity, and I would like to create a column/new variable in a dataframe called DemandInterval(as shown below ) which calculates the demand interval between two non zero quantities using R code. Model Month Year Quantity DemandInterval Model-A 7 2017 0 0 Model-A 8 2017 1 1 Model-A 9 2017 1 1 Model-A 10 2017 1 1 Model-A 11 2017 0 0 Model-A 12 2017 0 0 Model-A 1 2018 0 0 Model-A 2 2018 0 0 Model-A 3 2018 0 0 Model-A 4 2018 1 6 Model-A 5 2018 5 1 Model-A 6 2018 0 0 Model-A 7 2018 0 0 Model-A 8 2018 0 0

Convert html table to json nice format

15 July 2020 @ 4:49 pm

I'm trying to read the table with with pandas to get all results but i had no success. This is what i've got so far. import requests import pandas as pd url = 'http://www.fundamentus.com.br/resultado.php' headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"} fundamentus = requests.get(url, headers=headers) dfs = pd.read_html(fundamentus.text) print(type(dfs)) table = dfs[0] table.to_json('table.json') But the json keys have been generated per column and not per row. I'm new with python but this is making me get crazy. I also tried to make a dictorinary using beautiful soup, but found pandas more easy which gave me the table, but the json export is totally messed.