Instantly share code, notes, and snippets.

🏠
Working from home

# Xaliphostes xaliphostes

🏠
Working from home
Created March 1, 2024 10:16
Fractures cost functions (in 2D)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import math import matplotlib.pyplot as plt import random def costJoint(normal: tuple[float, float], S3: tuple[float, float]): return 1 - abs(normal[0]*S3[0] + normal[1]*S3[1]) def costStylolite(normal: tuple[float, float], S3: tuple[float, float]): return 1 - costJoint(normal, S3)
Last active March 1, 2024 10:14
normal and shear stress plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import math import matplotlib.pyplot as plt Stress = list[list[float], list[float]] Vector = list[float] Angle = float def normalAndShear(S: Stress, theta: Angle) -> Vector: a = math.radians(theta) sxx = S[0][0]
Last active February 7, 2024 08:20
camera tween movement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import { Vector3 } from 'three' import * as TWEEN from 'tween' export type Callback = () => void export function setView(position: Vector3, target: Vector3, duration = 0, callback: Callback = null) { let endPosition = position.clone() let endTarget = target.clone() const startPosition = this.position.clone()
Last active January 3, 2024 08:22
Tagged Template literal in ES6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates // See https://tc39wiki.calculist.org/es6/template-strings/ // function ttl(strings, ...rest) { console.log(rest); } ttl `a\${1}b\${2}c\${3}`; ttl `a\${1}b\${2}c\${3}d\${4}`;
Last active October 11, 2023 05:47
async/await for npm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 // Example function export const fetchPackageInfo = async (pkgName: string, signal: AbortSignal): Promise => { const response = await fetch(`https://registry.npmjs.org/\${pkgName}`, { signal }) if (response.status === 200) { return response.json(); } else { throw response.text(); } }
Created June 30, 2023 15:23
solid-js in browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

Last active May 22, 2023 13:17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 /** * Simulate a 1 second computation */ function computeFast() { console.log("Init fast") return new Promise(resolve => { setTimeout(function() { resolve(" Fast") console.log(" End of fast") }, 1000)
Last active February 8, 2023 09:47
Factory of functions using string names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 type myFunction = (params: any) => void /* eslint @typescript-eslint/no-explicit-any: off -- need to have any here for the factory */ namespace Factory { const map_: Map = new Map() export const bind = (obj: myFunction, name: string = '') => { name.length === 0 ? map_.set(obj.name, obj) : map_.set(name, obj) }
Last active February 8, 2023 10:08
Factory of objects using string names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 /* eslint @typescript-eslint/no-explicit-any: off -- need to have any here for the factory */ namespace Factory { const map_: Map = new Map() export const bind = (obj: any, name: string = '') => { name.length === 0 ? map_.set(obj.name, obj) : map_.set(name, obj) }
Created February 1, 2023 14:38
Create an object instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 // -------------------------------------------------------- const create = (Type: any, params: any) => new Type(params) // -------------------------------------------------------- // Example class A { private a = 0 private b = 0