Posts

Showing posts from 2020

App with fastapi, Arangodb and Graphql

Image
Configuring fastapi, arangodb and graphql with authentication: It uses fastapi graphene, graphene-pydantic, python-arango and fastapi-jwt-auth mkdir fastapi_learn_project cd fastapi_learn_project virtualenv -p python3 env source env/bin/activate pip3 install fastapi uvicorn graphene graphene-pydantic==0.1.0 python-arango fastapi-jwt-auth Setup database database.py 1 2 3 4 5 6 7 from arango import ArangoClient # Initialize the ArangoDB client. client = ArangoClient(hosts= 'http://localhost:8529' ) # Connect to "test" database as root user. db = client.db( 'fastapidemo' , username= 'root' , password= '****' ) You can find how to set up arangodb at: serializers.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 from typing import List, Optional from graphene_pydantic import PydanticInputObjectType, PydanticObjectType from pydantic import BaseModel class UserModel (BaseModel): _id: str name...

Generating UUID4 from custom random number generator (RNG) using rust

First you need to generate random seed: It can be from any RNG generator, for example in near protocol sdk,  https://docs.rs/near-sdk/0.11.0/near_sdk/env/fn.random_seed.html pub fn random_seed() -> Vec<u8> use rand::Rng; fn main () { let mut rng = rand::thread_rng(); let mut randvec: Vec < u8 > = Vec ::new(); let mut counter = 0 ; let result = loop { counter += 1 ; let n1: u8 = rng.gen(); randvec.push(n1); if counter == 32 { break randvec; } }; println! ( "{:?}" , result); } Its generate vector, but you need an array to feed into from_seed function. This is the complete code. use rand::{rngs::StdRng, RngCore, SeedableRng, Rng}; use uuid::{Builder, Variant, Version}; fn main () { let mut rng = rand::thread_rng(); let mut randvec: Vec < u8 > = Vec ::new(); let mut counter = 0 ; let result_vec = loop { counter ...