Skip to main content

Posts

Convert/annotate the throttle function into its type-safe TypeScript equivalent

The best outcome is that we enforce that the function which is returned by the throttle function has exactly the same signature as func, regardless of how many parameters func takes. Using incorrect types or the wrong number of parameters when calling the wrapped function should result in a compiler error. function throttle(func: Function, timeout: any) { let ready = true; return (...args: any) => { if (!ready) { return; } ready = false; func(...args); setTimeout(() => { ready = true; }, timeout); }; } function sayHello(name: string): void { console.log(`Hello ${name}`); } const throttledSayHello = throttle(sayHello, 1000); // this should result in compilation failure throttledSayHello(1337); // so should this const throttledSayHello2 = throttle(sayHello, "breakstuff"); Via Active questions tagged javascript - Stack Overflow https://ift.tt/8E9s0g2

how to use active class in vue js

i'm trying to change the text-color when a component is active here's my template <div v-if="enabled2FAs.includes('phoneOtp')" @click="otpType = 'phoneOtp'" > <div :class="[isActive ? activeClass: 'red',]"> Phone OTP </div> </div> <div v-if="enabled2FAs.includes('authenticatorApp')" @click="otpType = 'authenticatorApp'" > <div :class="[isActive ? activeClass: 'red',]"> Phone OTP </div> </div> my sxript tag <script> export default { data() { return { isActive: true, }; }, }; </script> pleaase how can i go about this Via Active questions tagged jav

Is it possible to download the photos from the weathercams on the FAA's website?

I am having difficulties scraping data off of this website. I have relatively minimal experience scraping data with python. If possible, I'd like to download the photos for each airport from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Edge() driver.get('https://ift.tt/8u9jcn2) airport = driver.find_elements_by_xpath('/html/body/div/div/div[2]/div[2]/div/div[4]/div[2]/a') airport.click() I've tried the above code to click on each airport with no success. source https://stackoverflow.com/questions/75203189/is-it-possible-to-download-the-photos-from-the-weathercams-on-the-faas-website

VBA & Selenium | Access iframe within HTML containing #document

I am trying to access the HTML within two iframes using Selenium Basic in VBA, as IE has been blocked on our machines, and Python, etc. are not available to us. Previously I could access the html with this: Dim IE As InternetExplorerMedium Set IE = New InternetExplorerMedium ' actual website excluded as it is a work hosted website which requires login, etc. website = "..." IE.navigate (website) Dim IEDocument As HTMLDocument Set IEDocument = IE.document.getElementById(id1).contentDocument.getElementById(id2).contentDocument From there I would have access to all the HTML elements which I could work with. Now I am trying the following with Selenium Basic: Set cd = New Selenium.ChromeDriver website = "..." cd.Start baseUrl:=website cd.Get "/" Dim af1 As Selenium.WebElement, af2 As Selenium.WebElement Set af1 = cd.FindElementById("CRMApplicationFrame") Set af2 = af1.FindElementById("WorkAreaFrame1") It works up to the last lin

Regex : split on '.' but not in substrings like "J.K. Rowling"

I am looking for names of books and authors in a bunch of texts, like: my_text = """ My favorites books of all time are: Harry potter by J. K. Rowling, Dune (first book) by Frank Herbert; and Le Petit Prince by Antoine de Saint Exupery (I read it many times). That's it by the way. """ Right now I am using the following code to split the text on separators like this: pattern = r" *(.+) by ((?: ?\w+)+)" matches = re.findall(pattern, my_text) res = [] for match in matches: res.append((match[0], match[1])) print(res) # [('Harry potter', 'J'), ('K. Rowling, Dune (first book)', 'Frank Herbert'), ('and Le Petit Prince', 'Antoine de Saint Exupery '), ("I read it many times). That's it", 'the way')] Even if there are false positive (like 'that's it by the way') my main problem is with authors that are cut when written as initials, which is pretty c

JSON data is refused by Lightweight Charts

I want to use LightWeight Charts by TradingView. I process data with Python and serve it via Flask to JSON: from flask import Flask, jsonify, render_template from datetime import datetime app = Flask(__name__) @app.route('/') def home(name=None): return render_template('index.html', name=name) @app.route('/data') def data(): ind_df = d.request_data(...) # dummy method ind_df['Date'] = ind_df['Date'].map(lambda t: int(t.timestamp())) ind_df = ind_df.set_index('Date') return jsonify(ind_df.to_dict()) then I have index.json: // Create the Lightweight Chart within the container element const chart = LightweightCharts.createChart( document.getElementById('container') ); // Create the Main Series (Candlesticks) const mainSeries = chart.addCandlestickSeries(); fetch('/data') .then(response => response.json()) .then(data => { // use the data to create a visualization console.log(da

How to click on cookie popup using webdriver chrome to access the actual webpage

I am struggling to make selenium click on the cookie popup and access the website. I have the following code: from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By import pandas as pd from datetime import datetime import os import sys web = 'https://www.thesun.co.uk/sport/football/' path = '/Users/cc/Documents/Documents/IT/1. Python/WebCrawler/chromedriver' driver_service = Service(executable_path=path) driver = webdriver.Chrome(service=driver_service) driver.get(web) WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH,'//*.[@id="notice"]/div[4]/button[2]'))).click() here is the webpage: enter image description here here is the htlm button element: enter image description here here