Skip to content

Instantly share code, notes, and snippets.

View AlexanderNenninger's full-sized avatar
🏠
Working from home

Alexander Nenninger AlexanderNenninger

🏠
Working from home
View GitHub Profile
@deanm0000
deanm0000 / gist:485291942b47b4d32113973eff493e72
Created July 23, 2024 15:51
make fake ufunc to avoid map_batches
import polars as pl
import pyarrow.compute as pc
# Example df
df = pl.DataFrame(
[
pl.Series("a", [1, 2, 3], dtype=pl.Int64),
]
)
@AlexanderNenninger
AlexanderNenninger / event_timer_cb.rs
Last active January 13, 2022 13:32
Callback to track time when last event occured. Written in Rust for referential transparency.
use std::boxed::Box;
type Callback<U, T> = Box<dyn Fn(&mut U, &T)>;
type Condition<U, T> = Box<dyn Fn(&U, &T) -> bool>;
type Effect<U, T> = Box<dyn Fn(&mut U, &T)>;
fn make_callback<U: 'static, T: 'static>(
condition: Condition<U, T>,
effect: Effect<U, T>,
) -> Callback<U, T> {
#!/usr/bin/env python3
import sys
import re
points = set()
folds = []
for line in sys.stdin:
line = line.strip()
@aryan-f
aryan-f / scaler.py
Last active March 7, 2025 17:01
Standard Scaler for PyTorch Tensors
import torch
class StandardScaler:
def __init__(self, mean=None, std=None, epsilon=1e-7):
"""Standard Scaler.
The class can be used to normalize PyTorch Tensors using native functions. The module does not expect the
tensors to be of any specific shape; as long as the features are the last dimension in the tensor, the module
@oJshua
oJshua / iso8601date.jl
Created October 20, 2019 05:08
Parse ISO8601 date string with 'Z' for UTC in Julia
using Dates
escaped_format = "yyyy-mm-dd\\THH:MM:SS.sss\\Z"
Zulu = String
Dates.CONVERSION_SPECIFIERS['Z'] = Zulu
Dates.CONVERSION_DEFAULTS[Zulu] = ""
df = Dates.DateFormat(escaped_format)
function convert_date(datestring::String)
Dates.parse(DateTime, datestring, df)
@peterhurford
peterhurford / pytest-fixture-modularization.md
Created July 28, 2016 15:48
How to modularize your py.test fixtures

Using py.test is great and the support for test fixtures is pretty awesome. However, in order to share your fixtures across your entire module, py.test suggests you define all your fixtures within one single conftest.py file. This is impractical if you have a large quantity of fixtures -- for better organization and readibility, you would much rather define your fixtures across multiple, well-named files. But how do you do that? ...No one on the internet seemed to know.

Turns out, however, you can define fixtures in individual files like this:

tests/fixtures/add.py

import pytest

@pytest.fixture