Skip to content

Instantly share code, notes, and snippets.

View okanyenigun's full-sized avatar

Okan Yenigün okanyenigun

View GitHub Profile
@okanyenigun
okanyenigun / thompsonsampling.py
Last active November 14, 2022 09:57
multi armed bandit thompson
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
class Pub:
def __init__(self, mu: float, sigma: float):
self.mu = mu
self.sigma = sigma
self.n = 0
self.total_score = 0
@okanyenigun
okanyenigun / logging.conf
Created October 25, 2022 15:10
logging conf file
[loggers]
keys=root, alogger
[handlers]
keys=stream_handler
[formatters]
keys=formatter
[logger_root]
@okanyenigun
okanyenigun / test_rest.py
Created October 20, 2022 21:46
pytest unit test rest example
import uuid
import requests
ENDPOINT = "https://todo.pixegami.io"
class TaskUtility:
@staticmethod
def new_task_payload():
user_id = f"test_user_{uuid.uuid4().hex}"
@okanyenigun
okanyenigun / test_unittest_example.py
Last active October 20, 2022 20:38
pytest unittest example 2
import pytest
from unittest.mock import Mock
from unittest_examples import Flight, CustomerDb
@pytest.fixture
def app():
plane = Flight(5, 10)
plane.add_passenger("Cristiano Ronaldo")
plane.add_passenger("Ten Hag")
plane.add_passenger("Harry Maguire")
@okanyenigun
okanyenigun / unittest_examples.py
Created October 20, 2022 20:22
pytest unitytest example 1
from typing import List
class CustomerDb:
def __init__(self):
print("Connected to db")
def get_customer_membership(self, name: str) -> int:
if name == "Cristiano Ronaldo":
return 2
@okanyenigun
okanyenigun / asyncio.py
Created September 26, 2022 18:24
asyncio example
import asyncio
async def get_data_from_db():
print("connecting to database...")
await asyncio.sleep(3)
print('data is retrieved.')
return {'data': 'myData'}
async def counter():
@okanyenigun
okanyenigun / memento.py
Created September 25, 2022 14:48
memento design pattern
class Memento():
def __init__(self, state):
self.state = state
print(f"I am a Memento and my state is {self.state}")
class Originator():
def __init__(self):
self._state = ""
@okanyenigun
okanyenigun / transformation.scala
Created September 22, 2022 21:23
feature transformation and pca scala code
import org.apache.spark.sql.SparkSession
import org.apache.log4j._
Logger.getLogger("org").setLevel(Level.ERROR)
//start a spark session
val spark = SparkSession.builder().getOrCreate()
//read data
val logregdata = spark.read.option("header","true").option("inferSchema","true").format("csv").load("titanic.csv")
val data = logregdata.na.drop()
@okanyenigun
okanyenigun / voxelgridwellington.py
Created September 22, 2022 14:02
voxel grid wellington
import laspy as lp
import numpy as np
import open3d as o3d
path = "NZ19_Wellington.las"
#read point cloud data
point_cloud=lp.read(path)
#convert to o3d
import numpy as np
import open3d as o3d
#get point cloud data
armadillo = o3d.data.ArmadilloMesh()
mesh = o3d.io.read_triangle_mesh(armadillo.path)
N = 2000 #point
pcd = mesh.sample_points_poisson_disk(N)
# fit to unit cube
pcd.scale(1 / np.max(pcd.get_max_bound() - pcd.get_min_bound()),