Skip to content

Instantly share code, notes, and snippets.

@mahdikhashan
mahdikhashan / mutableSource.tsx
Created March 21, 2023 00:05 — forked from Aslemammad/mutableSource.tsx
Consistent version of useMutableSource.
// Consistent version of `useMutableSource`, Inspired by https://github.com/pmndrs/valtio/blob/master/src/useMutableSource.ts
import { useEffect, useRef, useState } from 'react';
const TARGET = Symbol('target');
const GET_VERSION = Symbol('getVersion');
export type Source<TargetType extends any, VersionType extends any> = {
[TARGET]: TargetType;
[GET_VERSION]: (target: TargetType) => VersionType;
};
@mahdikhashan
mahdikhashan / DateTimeFormatMock.js
Created March 28, 2023 12:15
Vitest Mock Timezone
it("should get the client timezone as a string", () => {
const DateTimeFormat = Intl.DateTimeFormat;
vi.spyOn(global.Intl, "DateTimeFormat").mockImplementation(
(locale, options) =>
new DateTimeFormat(locale, { ...options, timeZone: "Asia/Tehran" })
);
const date: MyDate = new MyDate("2023-03-28T11:06:48+00:00");
expect(date.getClientTZ()).toEqual("Asia/Tehran");
@mahdikhashan
mahdikhashan / release.config.js
Created April 18, 2023 09:57 — forked from yyynnn/release.config.js
release.config.js
/* eslint-disable no-template-curly-in-string */
const gitlabUrl = 'https://gitlab.com'
const gitlabApiPathPrefix = '/api/v4'
const assets = [
{ path: 'index.js', label: 'JS distribution' }
]
const verifyConditions = [
['@semantic-release/changelog'],
@mahdikhashan
mahdikhashan / time_step_decorator.py
Created May 28, 2025 12:15
Metaflow `@time_step` Decorator — Track and store execution time of each `@step` in your flow using `flow.step_timings`. Handy for lightweight performance profiling.
import time
import functools
def time_step(func):
"""
A Metaflow-specific decorator to measure and log the execution time of a @step.
This decorator is intended to be used on Metaflow step functions only.
It stores the step's execution duration (in seconds) in the `step_timings`
@mahdikhashan
mahdikhashan / flow_matching.py
Created June 14, 2025 15:18 — forked from francois-rozet/flow_matching.py
Flow Matching in 100 LOC
#!/usr/bin/env python
import math
import matplotlib.pyplot as plt
import torch
import torch.nn as nn
from sklearn.datasets import make_moons
from torch import Tensor
from tqdm import tqdm

For my GSoC project this year, I'm working on an integration between JAX and Kubeflow Trainer v2.

There are multiple challenges which requires consideration, one of them is how to keep multiple backend setup in a single container, when I don't want to have multiple templates / blueprints, i need to validate it.

my current implementation for docker:

FROM python:3.10-bullseye
FROM ghcr.io/nvidia/jax:jax
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
libgoogle-glog-dev \