Skip to content

Instantly share code, notes, and snippets.

View ozgurozkok's full-sized avatar
🎯
Focusing

ozgur ozgurozkok

🎯
Focusing
View GitHub Profile
@ozgurozkok
ozgurozkok / csv_files_python.py
Created June 3, 2023 12:34
Code Samples for Processing CSV Files
#Read a CSV file
import csv
with open('data.csv', 'r') as f: reader = csv.reader(f) for row in reader: print(row)
#Write a CSV file
import csv
import pygame
from pygame.locals import *
# Create a Navmesh object
navmesh = pygame.nav.NavMesh()
# Load the Navmesh from a file
navmesh.load("navmesh.nav")
# Create a start and end point
@ozgurozkok
ozgurozkok / dbscansample.py
Created March 24, 2023 22:05
clustering with dbscan
from sklearn.cluster import DBSCAN
from sklearn.datasets import make_blobs
# Generate sample data
X, y = make_blobs(n_samples=1000, centers=3, random_state=42)
# Perform clustering
dbscan = DBSCAN(eps=0.5, min_samples=5)
dbscan.fit(X)
@ozgurozkok
ozgurozkok / properties.py
Created March 24, 2023 20:49
getters, setters and properties in Python
class Person:
def init(self, name, age):
self.name = name
self._age = age # Use a private attribute to store the age
@property
def age(self): # This is a getter method for the age property
print("Getting age")
return self._age
def add_numbers(a, b):
return a + b
def test_add_numbers():
assert add_numbers(2, 3) == 5
assert add_numbers(5, 7) == 12
assert add_numbers(10, -3) == 7
//file 1
import React from 'react';
function MyMicrofrontend() {
return (
<div>
<h1>Welcome to my micro frontend!</h1>
<p>This is a simple micro frontend implemented with ReactJS.</p>
</div>
#sample 1
#Here's an example of creating a tuple
my_tuple = (1, 2, 3, "four", 5.0)
#sample 2
#Tuples can also be created without using parentheses, using just commas:
another_tuple = "one", "two", "three"
#sample 3
#Here's an example that could produce this error message:
@ozgurozkok
ozgurozkok / clustering.py
Created January 30, 2023 17:18
clustering locations using Python, MySQL, and KMeans from the scikit-learn library with a condition that two points with the same title and within 100m of each other should be in the same cluster
import mysql.connector
import numpy as np
from sklearn.cluster import KMeans
from scipy.spatial import distance
def haversine_distance(lat1, lon1, lat2, lon2):
"""
Calculate the haversine distance between two points on the earth (specified in decimal degrees)
"""
lat1, lon1, lat2, lon2 = map(np.deg2rad, [lat1, lon1, lat2, lon2])
@ozgurozkok
ozgurozkok / SRIDSAMPLE.PY
Created January 30, 2023 16:23
example of how to use SRID in Python with the GEOS library
from django.contrib.gis.geos import Point
point = Point(1, 1, srid=4326)
point.transform(3857)
@ozgurozkok
ozgurozkok / SRIDSQL1
Created January 30, 2023 16:21
SRID example in MYSQL
CREATE TABLE places (
id INT PRIMARY KEY,
name VARCHAR(100),
location POINT,
SRID INT
);
INSERT INTO places (id, name, location, SRID)
VALUES (1, 'Place A', ST_GeomFromText('POINT(1 1)', 4326), 4326);