Skip to content

Instantly share code, notes, and snippets.

@Voyz
Voyz / infer_dtypes.py
Last active June 4, 2024 07:02
infer_dtypes infers datatypes from a list of values. This file includes an example from pd.DataFrame.
import string
import warnings
from typing import List, Dict
import numpy as np
import pandas as pd
def infer_dtypes(values: List, sample_size: int = 300, stop_after: int = 300):
"""
import multiprocessing
import time
from collections import deque
class ThrottleBarrier():
def __init__(
self,
counter: multiprocessing.Value,
lock: multiprocessing.Lock,
import datetime
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from ratelimiter import ThrottleBarrier, CrossProcessesThrottle
def log(*args, **kwargs):
print(datetime.datetime.now().strftime('[%H:%M:%S]'), *args, **kwargs)
@Voyz
Voyz / timeseries_vertices_voy_A01.py
Created October 23, 2022 14:48
Vertices of a timeseries
def timeseries_vertices(ser:pd.Series, distance=15, coeff=3):
name = ser.name
# remove intermediate vertices on lines
def no_lines(df):
df.loc[:, 'gt_before'] = df.loc[:, name] > df.loc[:, name].shift(1)
df.loc[:, 'gt_after'] = df.loc[:, name] > df.loc[:, name].shift(-1)
df.loc[:, 'is_peak'] = df.loc[:, 'gt_before'] == df.loc[:, 'gt_after']
df = df.loc[df.loc[:, 'is_peak'], :].copy()
@Voyz
Voyz / bouquets_log.json
Last active August 31, 2022 12:34
Tulip matching challenge - pubic data
[
{"side": "SELL", "tulips": 15, "tulip_price": 111.5, "transaction_date": "2022-02-01T00:00:00.250000"},
{"side": "BUY", "tulips": 15, "tulip_price": 107.5, "transaction_date": "2022-02-01T00:30:00.250000"},
{"side": "BUY", "tulips": 15, "tulip_price": 107, "transaction_date": "2022-02-01T01:30:00.250000"},
{"side": "SELL", "tulips": 20, "tulip_price": 104.5, "transaction_date": "2022-02-01T02:00:00.250000"},
{"side": "BUY", "tulips": 10, "tulip_price": 105, "transaction_date": "2022-02-01T02:00:00.250000"},
{"side": "SELL", "tulips": 15, "tulip_price": 112.5, "transaction_date": "2022-02-01T03:00:00.250000"},
{"side": "BUY", "tulips": 15, "tulip_price": 111.5, "transaction_date": "2022-02-01T03:30:00.250000"},
{"side": "SELL", "tulips": 20, "tulip_price": 111.0, "transaction_date": "2022-02-01T04:00:00.250000"},
{"side": "BUY", "tulips": 15, "tulip_price": 109.5, "transaction_date": "2022-02-01T04:30:00.250000"}
@Voyz
Voyz / IBeamDockerfileArm
Created April 14, 2021 13:55
IBeam arm64 Dockerfile
FROM python:3.7.7-slim-buster
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN mkdir -p /usr/share/man/man1
RUN apt-get update && \
apt-get install -y default-jre && \
apt-get -y install dbus-x11 xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalable && \
@Voyz
Voyz / ibkr_inlet.py
Last active March 22, 2021 03:14
Databay Inlet for IBKR CP Web API
TS_DATE_FORMAT_DB_ISO = '%Y-%m-%dT%H:%M:%S,%f' # comma works for mongodb and is valid ISO
def datetimeindex_to_UTC(_dti):
dti = _dti.copy(deep=True)
if 'tz' not in dti or dti.tz is None:
dti = dti.tz_localize('UTC')
else:
dti = dti.tz_convert('UTC')
dti = dti.dt.strftime(TS_DATE_FORMAT_DB_ISO).astype(str).str.slice(0, -3)
return dti
@Voyz
Voyz / databay_batch_outlets_and_splitters.py
Created February 14, 2021 14:09
databay_batch_outlets_and_splitters
import csv
import os
from pathlib import Path
from typing import List
from databay import Outlet, Update, Record, Link
from databay.inlets import RandomIntInlet
from databay.outlet import MetadataKey
from databay.outlets import CsvOutlet
@Voyz
Voyz / path_between_nulls.js
Created January 4, 2021 07:57
After Effects path between nulls
offset = [thisComp.width, thisComp.height]/2
p1 = thisComp.layer("P1").toComp([0,0]).slice(0,2) - offset
p2 = thisComp.layer("P2").toComp([0,0]).slice(0,2) - offset
t1 = thisComp.layer("T1").toComp([0,0]).slice(0,2) - offset - p1
t2 = thisComp.layer("T2").toComp([0,0]).slice(0,2) - offset - p2
ps = [p1, p2]
in_tangents = [[0,0], t2]
out_tangents = [t1, [0,0]]
createPath(ps, in_tangents, out_tangents, is_closed=false)
@Voyz
Voyz / weather_finder_basic.txt
Last active December 7, 2020 08:50
Weather finder basic
*** Originally built for my mate Sam as part of our mentoring sessions. See: https://youtu.be/TXoDvTJuEb0 ***
####################
WEATHER FINDER BASIC
####################
Utilise an online weather API to fetch and display current weather information based on the city and country code provided.
###################