Skip to content

Instantly share code, notes, and snippets.

View jcayzac's full-sized avatar

Julien Cayzac jcayzac

View GitHub Profile
@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)
@jcayzac
jcayzac / using-conda-with-blender.md
Last active April 14, 2024 06:54
How to replace Blender's builtin CPython with a Miniconda-managed python

Using Blender with Miniconda

If you want to play with Blender scripting but the Python packages it ships with aren't enough, you can replace its built-in Python with your own. Here I give you some instructions to swap in a miniconda-managed environment.

These instructions apply for macOS. YMMV.

1. Install Blender

# If you don't like Homebrew you can just get it from https://www.blender.org/download/

Loading a remote SVX into a route

@jcayzac
jcayzac / On PID 1 and Containers.md
Last active September 8, 2021 09:18
Explainer for init in docker / k8s

The process identifier (a.k.a. process ID or PID) is a number used by most operating system kernels, such as those of Unix, macOS and Windows, to uniquely identify an active process.

In Unix-like operating systems, PID 1 is usually the init[^init-name] process spawned by the kernel and responsible for starting and shutting down the rest of the system.

A process can create child processes using the fork system call. At any arbitrary time, this means processes can be represented by a tree structure. For example:

─┬─ PID 1 (init)
 ├─┬─ PID 2
 │ └─┬─ PID 4

│ └─── PID 7

Companies with work-from-home policies

  • Basecamp
  • DataStax
  • DuckDuckGo
  • Etsy
  • Facebook
  • GitHub
  • GitLab
  • Moneytree 🇯🇵

This is a test1.


Footnotes

  1. A footnote.