samedi 1 mai 2021

How variable decrements work in recursive functions?

I want to understand this below recursion. Here times-1 is passed each time function is called. How it reaches to zero? I mean, when times-1 is compared by if(times===1) then the statments terminates and else is not executed. And how each time decremented value is passed.

function repeatStringNumTimes(string, times) {
  if(times < 0) 
    return "";
  if(times === 1) 
    return string;
  else 
    return string + repeatStringNumTimes(string, times - 1);
}
repeatStringNumTimes("abc", 3);



I wish to recieve only links that match a specific cliteria | Selenium Python

SELENIUM PYTHON CODE

driver.get("https://www.youtube.com/")

link_mix = driver.find_elements_by_tag_name('a')

for linked in link_mix:
    print(linked.get_attribute('href'))

i wish to get only links that are youtube.com/contentcodexxxxxx

and not include header links and every other hyperlink... how can i filter these links




Detect when back button is pressed on mobile

I have a Modal component on my React website say -

<Modal visible={this.state.visible} onClose={() => {some function..}}>
   <div>
     {renders something..}
   </div>
</Modal>

visible sets whether the Modal is visible or not and onClose handles when a cross button on the modal is clicked to close the modal.

Now on mobile, when this Modal is open and back button on the mobile is pressed or if any mobile gesture is used to go back, it goes to the previous window. What I want is to just close the Modal when back button is pressed.

I am unaware how to listen for a back event on mobile so that I can handle this case.

Any idea how can I achieve this? Thanks in advance.




Do google Ad show you how many every page in your site earn? [closed]

Use angle brackets to force linking

https://stackoverflow.com Create inline text links with Markdown

Text Add alt attributes to links by adding a double space and text after the URL

Text




What can we do in following situation?

I have three tables betsinfo,results,wallet

I have developed the app till the user bets and results are posted and the bets gets settled as win or lose in the betsinfo table.

But i m stuck as for logic on how can i settle the amount in the wallets table.??

The winning bets should be calculated with (to_win_amt) - (stake) = winning amouny

I have all the bets placed in the system in betsinfo table and i am settling the bets by matching the results table.

Now i want to find out the creator of the user and match it with wallet id of the user and settle all their unsettled bets .

How can i achieve this ..any logic help please ??




how to make pixi js mask filter respond to touch on mobile view as it does to pointer move in desktop view?

I want the flash light effect to follow mobile touch events in pixi js

I am trying to make the pixijs mask filter responsive as the flash light effect follows the mouse pointer , so i need to make it follow the touch events.Here's the link of the effect https://pixijs.io/examples/#/masks/filter.js

const app = new PIXI.Application();
document.querySelector('#landing').appendChild(app.view);

// Inner radius of the circle
const radius = 90;

// The blur amount
const blurSize = 52;

app.loader.add('landing', './imgs/bg.png');
app.loader.load(setup);

function setup(loader, resources) {
    const background = new PIXI.Sprite(resources.landing.texture);
    app.stage.addChild(background);
    background.width = app.screen.width;
    background.height = app.screen.height;

    const circle = new PIXI.Graphics()
        .beginFill(0xFF0000)
        .drawCircle(radius + blurSize, radius + blurSize, radius)
        .endFill();
    circle.filters = [new PIXI.filters.BlurFilter(blurSize)];

    const bounds = new PIXI.Rectangle(0, 0, (radius + blurSize) * 2, (radius + blurSize) * 2);
    const texture = app.renderer.generateTexture(circle, PIXI.SCALE_MODES.NEAREST, 1, bounds);
    const focus = new PIXI.Sprite(texture);

    app.stage.addChild(focus);
    background.mask = focus;

    app.stage.interactive = true;
    app.stage.on('mousemove', pointerMove);
    
    

    function pointerMove(event) {
        focus.position.x = event.data.global.x - focus.width / 2;
        focus.position.y = event.data.global.y - focus.height / 2;
    }

  
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/5.3.7/pixi.min.js"></script>



Akamai 403 acced denied

I'm trying to write a code that login into Zalando website. When I do login request AKAMAI GHOST server block me with error 403 access denied.

Below the code, someone can help me ?

import time
import requests
from bs4 import BeautifulSoup
import json
import logging

logging.basicConfig(level=logging.DEBUG)


# all cookies received will be stored in the session object
s = requests.Session()

url='https://www.zalando.it'

####### First request function ##################################################################
headers = {
    'authority': 'www.zalando.it',
    'pragma': 'no-cache',
    'cache-control': 'no-cache',
    'sec-ch-ua': '"Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"',
    'sec-ch-ua-mobile': '?0',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'sec-fetch-site': 'none',
    'sec-fetch-mode': 'navigate',
    'sec-fetch-user': '?1',
    'sec-fetch-dest': 'document',
    'accept-language': 'it',
}
response = s.get(url, headers=headers)
st_code=response.status_code
url_text=response.text
resp_header_fr=response.headers
ck=s.cookies
#print(ck)
#print(st_code)
##################################################################################################

######### extract token
cookies_dictionary = ck.get_dict()
json_object = json.dumps(cookies_dictionary)
d2 = json.loads(json_object)

#print('token....')
#print('lets go!')
token=(d2["frsx"])
#print(token)


########### extract il client-id
json_object = json.dumps(cookies_dictionary)
d2 = json.loads(json_object)

#print('Client-id....')
#print(d2["Zalando-Client-Id"])
#print('lets go!')
client_id=(d2["Zalando-Client-Id"])
##############################################################################

## Delay 2 sec
time.sleep(2)

##############################################################################

####### Login request function ###################################################################
headers = {
    'authority': 'www.zalando.it',
    'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
    'x-xsrf-token': token,
    'x-zalando-render-page-uri': '/login',
    'x-zalando-client-id': client_id,
    'content-type': 'application/json',
    'x-zalando-request-uri': '/login',
    'accept': 'application/json',
    'x-zalando-toggle-label': 'THE_LABEL_IS_ENABLED',
    'sec-ch-ua-mobile': '?0',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
    'origin': 'https://www.zalando.it',
    'sec-fetch-site': 'same-origin',
    'sec-fetch-mode': 'cors',
    'sec-fetch-dest': 'empty',
    'referer': 'https://www.zalando.it/login',
    'accept-language': 'en-GB,en;q=0.9',
}
data = '{"username":"Email@gmail.com","password":"Password!","wnaMode":"modal"}'
url_login = 'https://www.zalando.it/api/reef/login'
response2 = s.post(url_login, headers=headers, data=data)
st_code=response2.status_code
ck2=s.cookies
url02_text=response2.text
resp_header_login=response2.headers

#Print cookie and response code

#print(ck)
print(st_code)
print(url02_text)
#print(resp_header_login)

if I run the same code with cookie and token taken from chrome browser, it work. I thin that Akamai detect that its not a web chrome session and not allow me to login.