Skip to content

Instantly share code, notes, and snippets.

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

Xaliphostes xaliphostes

🏠
Working from home
View GitHub Profile
@xaliphostes
xaliphostes / fractures-cost.py
Created March 1, 2024 10:16
Fractures cost functions (in 2D)
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)
@xaliphostes
xaliphostes / normal-stress.py
Last active March 1, 2024 10:14
normal and shear stress plot
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]
@xaliphostes
xaliphostes / setView.ts
Last active February 7, 2024 08:20
camera tween movement
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()
@xaliphostes
xaliphostes / ttl.js
Last active January 3, 2024 08:22
Tagged Template literal in ES6
// 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}`;
@xaliphostes
xaliphostes / async-await.ts
Last active October 11, 2023 05:47
async/await for npm
// Example function
export const fetchPackageInfo = async (pkgName: string, signal: AbortSignal): Promise<NpmPackage> => {
const response = await fetch(`https://registry.npmjs.org/${pkgName}`, { signal })
if (response.status === 200) {
return response.json();
} else {
throw response.text();
}
}
@xaliphostes
xaliphostes / index.html
Created June 30, 2023 15:23
solid-js in browser
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src='https://kit.fontawesome.com/daa834e337.js' crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
html,
body {
/**
* 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)
@xaliphostes
xaliphostes / factory-functions.ts
Last active February 8, 2023 09:47
Factory of functions using string names
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<string, myFunction> = new Map()
export const bind = (obj: myFunction, name: string = '') => {
name.length === 0 ? map_.set(obj.name, obj) : map_.set(name, obj)
}
@xaliphostes
xaliphostes / factory-objects.ts
Last active February 8, 2023 10:08
Factory of objects using string names
/* eslint @typescript-eslint/no-explicit-any: off -- need to have any here for the factory */
namespace Factory {
const map_: Map<string, any> = new Map()
export const bind = (obj: any, name: string = '') => {
name.length === 0 ? map_.set(obj.name, obj) : map_.set(name, obj)
}
@xaliphostes
xaliphostes / createObject.ts
Created February 1, 2023 14:38
Create an object instance
// --------------------------------------------------------
const create = (Type: any, params: any) => new Type(params)
// --------------------------------------------------------
// Example
class A {
private a = 0
private b = 0