Skip to content

Instantly share code, notes, and snippets.

View freelancing-solutions's full-sized avatar
💯
Available

mobius-crypt freelancing-solutions

💯
Available
View GitHub Profile
@freelancing-solutions
freelancing-solutions / data.py
Created May 1, 2021 00:55
eodhistoricaldata - historical stock exchange data fetchers
import typing
import requests
import pandas as pd
from io import StringIO
from ._utils import (_init_session, _format_date,
_sanitize_dates, _url, RemoteDataError, _handle_request_errors, EnvironNotSet,
_handle_environ_error, sentinel, api_key_not_authorized)
from config.config import Config
config_data: Config = Config()
@freelancing-solutions
freelancing-solutions / memberships.py
Created May 1, 2021 02:07
using tasklets to write asynchronous action validators with python-ndb
# TODO Create Test Cases for Memberships & Documentations
class Validators(UserValid, PlanValid, MemberValid, CouponValid):
def __init__(self):
super(Validators, self).__init__()
self._max_retries = current_app.config.get('DATASTORE_RETRIES')
self._max_timeout = current_app.config.get('DATASTORE_TIMEOUT')
@ndb.tasklet
def can_add_member(self, uid: str, plan_id: str, start_date: date) -> any:
@freelancing-solutions
freelancing-solutions / test_buy_volume.py
Created May 2, 2021 19:40
writing test cases for a stock buy volume class
import datetime
from google.cloud.ndb.exceptions import BadValueError
from pytest import raises
from data_service.store.stocks import BuyVolumeModel
from data_service.utils.utils import create_id, today
from .. import app
buy_volume_instance: BuyVolumeModel = BuyVolumeModel()
def test_buy_volume_instance():
@freelancing-solutions
freelancing-solutions / test_affiliate_view.py
Created May 7, 2021 21:33
mocking ndb.Model.query and ndb.Model.put with pytest_mock
class AffiliateQueryMock:
affiliate_instance = Affiliates()
def __init__(self):
pass
def fetch(self) -> list:
return [self.affiliate_instance]
def get(self) -> Affiliates:
// this listens for page load event
self.addEventListener('load', e => {
//you need to attach the event handler to submit-button after the page has loaded
document.getElementById('submit-button').addEventListener(e => {
e.preventDefault();
// obtain form elements here
const value1 = document.getElementById('elementid').value
@freelancing-solutions
freelancing-solutions / Dockerfile
Created May 23, 2021 11:34
Docker for a React App
FROM node:16.2-alpine3.11
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install app dependencies
COPY package.json ./
@freelancing-solutions
freelancing-solutions / cloudrunexample.py
Created August 24, 2021 15:12
deploying projects to google cloud run sample application
import os
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
name = os.environ.get("NAME", "World")
@freelancing-solutions
freelancing-solutions / Dockerfile
Created August 24, 2021 15:22
example dockerfile
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.9-slim
# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True
COPY ./requirements.txt /app/requirements.txt
# Copy local code to the container image.
ENV APP_HOME /app
@freelancing-solutions
freelancing-solutions / basemodel.py
Created August 24, 2021 16:49
creating base models for ndb datastore
"""
**ndb BaseModel **
used as a superclass to define data models
"""
__author__ = "mobius-crypt"
__email__ = "mobiusndou@gmail.com"
__twitter__ = "@blueitserver"
__github_repo__ = "https://github.com/freelancing-solutions/memberships-and-affiliate-api"
__github_profile__ = "https://github.com/freelancing-solutions/"
"""
**Exchange Data Model
"""
from google.cloud import ndb
from src.models.basemodel import BaseModel
class Exchange(BaseModel):
exchange_id: str = ndb.StringProperty(required=True, indexed=True)
name: str = ndb.StringProperty(required=True, indexed=True)