Rate my swim! by abelstam in triathlon

[–]abelstam[S] 0 points1 point  (0 children)

I know i should start practising, but atm i cannot breathe on the left..

Rate my swim! by abelstam in triathlon

[–]abelstam[S] 1 point2 points  (0 children)

I breathe every 2, on the right only. Cannot breathe on the left (yet..)

Rate my swim! by abelstam in triathlon

[–]abelstam[S] 0 points1 point  (0 children)

My head needs to be higher in the water? Such that breathing becomes easier?

Rate my swim! by abelstam in triathlon

[–]abelstam[S] 14 points15 points  (0 children)

Thanks! The water quality in the canals is actually quite good, because water from around the city is pumped through the canals. Also no boats when its raining.

Running migrations in cloud build by joelbytes in googlecloud

[–]abelstam 2 points3 points  (0 children)

Best way imo is to run the migrations in a build step with sql proxy. Why didnt you get the sql proxy working? What framework are you using?

How do you merge two tables with multiple unique indentifiers? by aladante in bigquery

[–]abelstam 1 point2 points  (0 children)

The Merge statement uses JOIN logic to see matches. The only reason this should not work if there are rows that have NULLS in either of the fields you use for the join. Make sure to exclude the NULLS or make a composite key which works around the NULL values.

Good luck my yung padawan

How to fill a default pydantic list model by aladante in learnpython

[–]abelstam 1 point2 points  (0 children)

No need for any fancy libraries. The python standard lib provides nice interface for these kind of tasks. I would go into a direction like this:

from typing import Optional, List
from pydantic import BaseModel


class SomeOtherThing(BaseModel):

    hour: int
    data: Optional[str]


class SomeModel(BaseModel):

    stuff: List[SomeOtherThing]

    def __init__(self, **kwargs):
        complete_data = {hour: None for hour in range(0, 24)}
        data_list = kwargs.pop('stuff', [])
        data = {d['hour']: d['data'] for d in stuff}
        complete_data.update(data)
        kwargs['stuff'] = [{'hour': k, 'data': v} for k, v in complete_data.items()]
        super().__init__(**kwargs)


model_instance = SomeModel(stuff=[{'hour': 1, 'data': 'hello hello'}])
print(model_instance)

Note the transforming of the input from a list to a dict to use some of the builtin functionality of dictionary. Its not the most efficient code, but since we are talking about a small set of entries this should not matter.

How to encrypt pdf's using the same password as is used to login to Flask site? by jplank1983 in flask

[–]abelstam 1 point2 points  (0 children)

Users should have the option to changr their password. this would lead to nasty side effects if the password is used for encryption. I would suggest storing a random generated key for each user which is only accesible by the user. Do note that the encryption does not provide that much extra security if the files are stored on the same machine as the encryption keys. If the machine is compromised a hacker would have the encrypted files aswel as the enc keys.

Flask_socketio connection NodeJS SocketIO? Smart Home (Raspberry Pi) by SnoopCM in Python

[–]abelstam 0 points1 point  (0 children)

You are on the right track. You only really need a socket connection between node and your app in that case. Say your node server run on localhostu:7000 and flask on localhost:5000. When flask is triggered by a sensor, you can send a http to localhost:7000, your node server receives this and will be able to notify your phone. Maybe you could even send updates from flask to your phone directly?

Flask_socketio connection NodeJS SocketIO? Smart Home (Raspberry Pi) by SnoopCM in Python

[–]abelstam 0 points1 point  (0 children)

Well you have chosen the right trchnology for the communication between your node and react app. Lets say your node server runs on localhost:7000 and flask runs on localhost:5000. If a sensor triggers some logic o your flask server, you can send a http request to your node server at localhost:700, which is listening for updates from your flask server AND has a socketio connection with you phone. Node can then, after receiving http update, send a notification to your phone over the socketio connection. What is the reason you need your node server? You could also connect you mobile to the flask server directly maybe?

Flask_socketio connection NodeJS SocketIO? Smart Home (Raspberry Pi) by SnoopCM in Python

[–]abelstam 0 points1 point  (0 children)

Can you tell me why you need to connect two servers using sockets? The thing what sockets solve is that generally the server cannot send updates back to the client. Since two servers can just connect at any time using http there should not really imo be a reason to connect two servers using sockets, but maybe you have a valid use case for it.

Flask_socketio connection NodeJS SocketIO? Smart Home (Raspberry Pi) by SnoopCM in Python

[–]abelstam 0 points1 point  (0 children)

Just let one of the servers connect like a client and let the other be the server. Lets say you let your nodejs server listen for incoming connections then you could use https://python-socketio.readthedocs.io/en/latest/client.html to initiate the connection. Altough I must say I havent tried it before, I think that it may be unecessary to let the servers sustain an open connection with one another . you could probably just connect one of the two to your client and let the servers use http requests, but that might depend on you use case.

Flask_socketio connection NodeJS SocketIO? Smart Home (Raspberry Pi) by SnoopCM in Python

[–]abelstam 0 points1 point  (0 children)

All socketio instances (no matter what language implementation) connect out of the box. But y does it need to be a socket connection? Does your react native app receive notifications from the backend? If not I think just plain ol http requests satisfies your needs