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 / 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/[email protected]/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 {
@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 / 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 / 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 / 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 / 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 / list.c++
Created September 27, 2024 05:04
C++ functions chaining using the operator overloading
/**
* Show how to chain functions using the overloaded operator |
* Excerpt from ?? (don't remember)
*/
#include <list>
#include <iostream>
#include <stdlib.h>
using namespace std;
@xaliphostes
xaliphostes / docker-cpp-web.md
Last active October 9, 2024 09:21
Docker, C++ et appel depuis le web

Appel d'un programme C++ en docker depuis une page web

Si votre application C++ est un programme en ligne de commande qui prend uniquement deux arguments (un fichier d'entrée et un fichier de sortie) et ne connaît pas HTTP ou les appels réseau, vous pouvez tout de même créer une API pour la piloter en utilisant une architecture où un serveur web intermédiaire exécute l'application C++ en arrière-plan.

Dans ce cas, vous n'avez pas besoin d'ajouter de code HTTP dans votre application C++. Vous créerez un conteneur Docker qui :

Expose une API via un serveur web léger (comme Flask ou Express). Utilise cette API pour déclencher l'exécution de votre application C++ en ligne de commande avec les arguments appropriés. Solution globale : L'API : Un serveur web léger (Flask) qui accepte les requêtes HTTP pour lancer votre programme en ligne de commande.