Skip to content

Instantly share code, notes, and snippets.

View jcayzac's full-sized avatar

Julien Cayzac jcayzac

View GitHub Profile

Setting up Miniconda with Conda Forge to avoid licensing issues

brew install miniconda
conda config --remove channels defaults
conda config --add channels conda-forge
conda config --set channel_priority strict

Before changing the config, these are the default channels:

@jcayzac
jcayzac / getTypeName.ts
Created October 2, 2024 07:37
Get the type name of anything
function getTypeName(x: any): string {
return x === undefined ? 'undefined' : x === null ? 'null' : /^(?:class|function) (\w+)/.exec(x.constructor.toString())![1]
}
@jcayzac
jcayzac / cloudflare-pages-commands.txt
Created September 25, 2024 23:46
Cloudflare Pages' PATH listing
/bin/[
/bin/aa-enabled
/bin/aa-exec
/bin/aa-features-abi
/bin/aclocal
/bin/aclocal-1.16
/bin/addpart
/bin/addr2line
/bin/apt
/bin/apt-cache
@jcayzac
jcayzac / frontend design decisions.md
Last active September 19, 2024 08:49
A record of decisions for frontend design

Frontend Design Decisions

# Colors

§ Specify colors in OKLCH

This lets us choose from a wider gamut of colors than sRGB, and for instance pick P3 colors.


@jcayzac
jcayzac / git-sync
Last active August 23, 2024 04:54
Git subcommand for sync'ing a working copy's branches and tags
#!/usr/bin/env bash
set -eu -o pipefail
echo "Pruning local tracking branches that don't exist anymore on the remote…"
git update
echo "Pruning local branches that have been merged…"
echo "Note: top-level branches are considered protected, only branches with a / in their name will be deleted."
git branch --format '%(refname:lstrip=2)' --merged | grep '/' || true | xargs -n 1 git branch -d
@jcayzac
jcayzac / python.ts
Last active December 4, 2023 09:43
Running Python code from Deno (no python installed).
Object.defineProperty(self, 'document', { value: {}, })
self.location = new URL('file:///nowhere')
import 'https://cdn.jsdelivr.net/pyodide/v0.24.1/full/pyodide.asm.js'
const { loadPyodide } = await import('https://cdn.jsdelivr.net/pyodide/v0.24.1/full/pyodide.mjs')
const pyodide = await loadPyodide()
await pyodide.loadPackage('micropip')
const micropip = pyodide.pyimport('micropip')
await Promise.all([
@jcayzac
jcayzac / sleep.ts
Created November 24, 2022 06:56
The ultimate sleep() method for Typescript
export type SleepOptions = {
signal?: AbortSignal
/** If set, aborting will not fail the promise but instead fulfil it right away. */
skipOnAbort?: true
}
export const sleep = (ms: number, options?: SleepOptions) =>
new Promise<void>((ok, ng) => {
// deno-lint-ignore prefer-const
@jcayzac
jcayzac / CONTRIBUTE.js
Last active July 27, 2022 10:22
Google App Script function implementing buy-and-hold rebalancing by splitting a cash inflow into the most meaningful contributions.
/**
* Implements buy-and-hold rebalancing by splitting some cash inflow into the
* most meaningful contributions:
*
* The buckets whose valuations have fallen the most behind their target weight
* are contributed to first. Then, contributions to the buckets with the largest
* inflow from the previous step are prioritized, as to minimize the number of
* transactions and thus transaction fees.
*
* @param values Range with the current valuation of the portfolio's constituents.
@jcayzac
jcayzac / test.ts
Last active July 25, 2022 00:49
A minimal test framework for node/typescript. Handles sync and async tests and subtests all the same. This could also work in deno pending https://github.com/denoland/deno_std/issues/1627#issuecomment-976757905
import chalk from 'chalk'
import ora from 'ora'
import process from 'node:process'
const success = chalk.green.bold(`OK`)
const failure = chalk.red.bold(`FAILED`)
const excludeStackFragment = `(${new URL(import.meta.url).pathname}:`
type TestBlock = (params: { test: TestFunction }) => unknown
type TestFunction = (description: string, body: TestBlock) => void
@jcayzac
jcayzac / Information Discreteness.pine
Created July 23, 2022 05:17
Information Discreteness [TradingView] [PineScript]
// Based on Da, Gurun and Warachka's 2014 paper:
// "Frog in the Pan: Continuous Information and Momentum"
// PDF: https://www3.nd.edu/~zda/Frog.pdf
//@version=5
indicator("Information Discreteness", overlay=false, precision=1, timeframe="D")
LENGTH = input.int(title="Window Length", defval=365, minval=7)
SKIP_RECENT = input.int(title="Skip most recent", defval=30, minval=0)
MA_LENGTH = input.int(title="Average returns over", defval=7, minval=1)