This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.gis.geos import Point | |
point = Point(1, 1, srid=4326) | |
point.transform(3857) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
NewerOlder