Skip to main content

Posts

lit-html: issue w/ using change event to propagate changes back to data model

In the below code, i am looping through a list of my data model (this.panel), and generating an input box for each. I would like to propagate any changes made by the user back to the model. to do this i am storing the index of the item im rendering in the html element, and adding a change event handler which will update the model using that index. The problem im having is the @change event at run time is throwing an error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'updateModel')' What's odd is i have another event handler, updateToggleState in a check box lower down that works fine. Any thoughts on what is going on here? Here is the code: class Panel extends LitElement { static properties = { is_fetch_on_change: {}, }; constructor() { super(); this.panel = [ { "id": "ticker", "type": "s...

navigator.serviceWorker.ready never resolves

I've have witness a very strange behavior on Chrome today... It seems that navigator.serviceWorker.ready never resolves after a redirection from another website. After being redirected, run this on the console: navigator.serviceWorker.ready // Promise {<pending>} Doesn't matter how much time you wait... it never resolves. Now, reload the page and run it again, you will immediately get: // Promise {<fulfilled>: ServiceWorkerRegistration} Does anybody know a workaround on this? Via Active questions tagged javascript - Stack Overflow https://ift.tt/O3h1CvT

How to specify default value when constructing Pandas Dataframe from two series (index and columns)?

I'm trying to construct a boolean 2D array set to initial value of False. The following code sets it to True by default: import pandas as pd from datetime import date date_start = date(2022, 1, 1) date_end = date(2022, 8, 24) valid_dates = pd.bdate_range(date_start, date_end) cols = range(0,4) df = pd.DataFrame(index=valid_dates, columns=cols, dtype='bool') I know I can do the following to replace the values to False, but it takes significantly longer: df = df.replace(df, False) My actual columns is much larger e.g. ~500 columns. Is there a way to just initialize the dataframe to be False? source https://stackoverflow.com/questions/73478915/how-to-specify-default-value-when-constructing-pandas-dataframe-from-two-series

Keras Time Series Transformer

I have this code from Keras time series classification with a Transformer model: def transformer_encoder(inputs, head_size, num_heads, ff_dim, dropout=0): # Attention and Normalization x = layers.MultiHeadAttention( key_dim=head_size, num_heads=num_heads, dropout=dropout)(inputs, inputs) x = layers.Dropout(dropout)(x) x = layers.LayerNormalization(epsilon=1e-6)(x) res = x + inputs # Feed Forward Part x = layers.Conv1D(filters=ff_dim, kernel_size=1, activation="relu")(res) x = layers.Dropout(dropout)(x) x = layers.Conv1D(filters=inputs.shape[-1], kernel_size=1)(x) x = layers.LayerNormalization(epsilon=1e-6)(x) return x + res If I try to change the Conv1D to ConvLSTM1D layer, I get this error: Input 0 of layer "conv_lstm1d_27" is incompatible with the layer: expected ndim=4, found ndim=3. Full shape received: (None, 24, 4) I changed the shape of dataset to (1354, 4, 24, 10) but it doesn'...

Get complete list up to the last unique value using Python and Pandas

My goal is to get the complete list up until the last unique value. Ideally, I would like methods for performing this operation Pythonically and using Pandas, but a single method solution will work great. Also, I need to preserve the ordering of the list. Also, in my example shown below, the last unique value happens to be the largest value in the list. This is not necessarily true for my application. The last unique value in my list can take on any value; meaning, it could be the smallest, the largest, or any value in between. Below I show the progress I have made so far. import pandas as pd data_dict = {"RAW": [4000076160, 5354368, 4641792, 4641792, 4289860736, 982783232, 2122384768, 4136386944, 5440384, 4772864, 4772864, 4289881216, 4270354816, 4293477248, 4286243840, 4286243840, 3400832, 982783232, 2122384768], "ADC_TYPE": [3, 7, 8, 8, 9, 10, 11, 3, 7, 8, 8,...

vue-test-utils throws an error 'TypeError: inject is not a function'

I wrote a global plugin and used it in a component. plugins/passwordValidation.js: export default function ({ app }, inject) { inject('passwordValidation', (password, passwordForConfirming) => { const errors = [] ... return errors }) } ... <script> ... export default { ... watch: { password(newPassword, oldPassword) { this.passwordValidationWarnings = this.$passwordValidation( newPassword, this.passwordForConfirming ) }, ... } </script> Then after writing a test with reference to the documentation , I noticed an following error occurred. An error message: FAIL test/components/organisms/RegisterForm.spec.js ● Test suite failed to run TypeError: inject is not a function 1 | export default function ({ app }, inject) { > 2 | inject('passwordValidation', (password, passwordForConfirming) => { | ^ 3 | const errors = [] test/components/organisms/Regi...

Trying to make a function that automatically adds .strip().lower() to input() [duplicate]

I'm creating a choose your own adventure as a way to learn to code, and I've discovered that it's much easier to create a function for something than to type it over and over again. I created 2 new print functions to automatically add a pause and a space after some dialogue to break up the block of text, and that worked perfectly. Now I'm noticing that I keep typing "variable" = input().strip().lower() on all the choices, and I was trying to streamline that into a function. I tried: def Input1(): input().lower().strip() With the goal being to put "variable" = Input1() But that failed So I tried: def Input1(Variable): Variable = input().lower().strip() and that failed I feel like I'm missing something, I just can't figure out what. source https://stackoverflow.com/questions/73465098/trying-to-make-a-function-that-automatically-adds-strip-lower-to-input