Skip to content

Instantly share code, notes, and snippets.

@royerk
royerk / setup.sh
Created March 5, 2024 18:08
Macos setup
# karabiner elements for key mapping
# brew or get .pkg from https://github.com/Homebrew/brew/releases/
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# oh my zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# https://gist.github.com/n1snt/454b879b8f0b7995740ae04c5fb5b7df
@royerk
royerk / fill_set_points_2.py
Created November 21, 2023 02:59
AB infer missing values, pick first value from day before
import pandas as pd
import numpy as np
df = pd.DataFrame(
[
["id_0", "2023-11-01", np.nan, 1, 0.5],
["id_0", "2023-11-02", 0.5, 2, np.nan],
["id_0", "2023-11-03", np.nan, np.nan, np.nan], # device in baseline
["id_0", "2023-11-04", np.nan, np.nan, np.nan], # device in baseline
["id_0", "2023-11-05", np.nan, 1.0, np.nan],
@royerk
royerk / fill_missing_values.py
Created October 24, 2023 01:33
AB infer missing values on row
from typing import List
import pandas as pd
df = pd.DataFrame(
[
["device_1", None, 1.0, 2.0, None, None, 3.0],
["device_2", 1.0, None, 2.0, None, None, None],
],
columns=["device_id", "0", "1", "2", "3", "4", "5"],
)
@royerk
royerk / infer_missing_days.py
Last active October 16, 2023 01:33
AB infer from log
import pandas as pd
df = pd.DataFrame(
[
["2023-01-01", "device_1", 800, True],
["2023-01-01", "device_2", 900, True],
["2023-01-02", "device_1", 800, True],
["2023-01-02", "device_3", 900, True],
["2023-01-03", "device_2", 900, True],
["2023-01-04", "device_1", 999, True],
@royerk
royerk / ubuntu_setup.py
Last active March 7, 2023 21:57
Basic linux setup
ssh-keygen
sudo apt install git
sudo apt install curl zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# log out then back in
# vscode: https://code.visualstudio.com/docs/?dv=linux64_deb
from airflow import DAG
from airflow.decorators import task
from google.cloud import aiplatform
ENV = "my-env-name"
PIPELINE_SPEC_URI = f"gs://bucket/something/something/pipeline-spec-{ENV}.json"
PROJECT_ID = f"my-project-id-{ENV}"
REGION = "moon-southpole1"
PIPELINE_ROOT = f"gs://some-bucket/"
with DAG(
...
) as dag:
my_task = PythonOperator(
task_id="some-name",
python_callable=invoke_container,
op_kwargs={
"url": URL,
"my_param": "toto",
},
from airflow.providers.google.common.utils import (
id_token_credentials as id_token_credential_utils,
)
from google.auth.transport.requests import AuthorizedSession
A_GLOBAL_PARAM = 57
def invoke_container(url: str, my_param: str, **kwargs) -> bool:
@royerk
royerk / python_bundler.py
Created May 5, 2021 16:59
Python script to merge python scripts together
import re
files_to_include = [
'my_class.py',
'dir/other_file.py',
'main.py' # << finish by main
]
output_file = 'bundled_code.py'
@royerk
royerk / useful_cmd.sh
Last active December 26, 2019 18:05
Raspberry
# get core temperature
vcgencmd measure_temp
# spotify
curl -sL https://dtcooper.github.io/raspotify/install.sh | sh