Skip to content

Instantly share code, notes, and snippets.

View Naartti's full-sized avatar

Mattias Naarttijärvi Naartti

View GitHub Profile
fig, ax = plt.subplots(1, 1, figsize=(18, 7))
sns.lineplot(x=df.index, y="mem_percentage", hue="NAME", data=df, drawstyle="steps")
plt.legend(bbox_to_anchor=(1.01, 1), loc='upper left')
plt.ylabel("MEM [%]")
plt.title(f"Memory")
plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False)
plt.grid()
plt.show()
import re
def get_only_characters(string):
return re.sub('[^a-zA-Z]+', '', string)
def get_only_numbers(string):
return float(re.sub('[^\d\.]', '', string))
def to_bit(value):
return int({
df = pd.concat(
[
pd.read_csv(filename, delimiter=r"\s\s+", engine="python")
for filename
in raw_data_filenames
],
axis=0,
ignore_index=True,
)
import os
from glob import glob
ROOT_PATH = os.path.abspath("..")
raw_data_filenames = glob(os.path.join(ROOT_PATH, "assets/*.csv"))
raw_data_filenames.sort()
class Movie(TypedDict, total=False):
title: str
release_year: int
rating: Literal[1, 2, 3, 4, 5]
comments: list[str]
sequel: Optional[str]
from typing import TypedDict, Literal
class Movie(TypedDict):
title: str
release_year: int
rating: Literal[1, 2, 3, 4, 5]
comments: list[str]
m_1: Movie = {
"title": "Star Wars: A New Hope",
type Movie = {
title: string
releaseYear: number
rating: 1 | 2 | 3 | 4 | 5
comments: string[]
sequel?: string
}
let m1: Movie = {
title: "Star Wars: A New Hope",
from typing import Optional
class Person():
_id_counter = 0
def __init__(self, name: str, age: Optional[int]):
self._id = Person.get_id()
self.name = name
self.age = age or 0
class Person {
private static idCounter = 0
readonly id!: number
name!: string
age!: number
constructor(name: string, age?: number) {
this.id = Person.getId()
this.name = name
this.age = age ?? 0
@Naartti
Naartti / typed_python_for_typescript_developers__optional_parameters.py
Created April 18, 2021 11:27
Typed Python function with optional parameters
from typing import Optional
def optional_foo(bar: Optional[str]):
return bar or "No input"