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 / 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
@xaliphostes
xaliphostes / zip.js
Last active January 21, 2023 10:40
zip multiple arrays in JS
const zip = arrays => {
return Array.apply(null, Array(arrays[0].length)).map( (_,i) => arrays.map( array => array[i] ) )
}
// ----------- testing
const A = [1, 2, 3, 4]
const B = [5, 6, 7, 8]
const C = [9, 4, 3, 2]
@xaliphostes
xaliphostes / forEachOnArrays.js
Last active January 21, 2023 10:39
Iterate on many arrays simultaneously
const forEach = (as, cb) => {
// necessary tests:
// - as is an array and all items in as are arrays
// - length of all arrays in as are the same
as[0].forEach( (serie, i) => cb( as.map( serie => serie[i] ), i, as) )
}
// ---------------- testing
const A = [1, 2, 3, 4]
@xaliphostes
xaliphostes / README.md
Created January 10, 2023 07:43
pybind11 simple test

Wrapping C++ for Python

Your project

  1. You should have the CMakeFiles.txt and the src folder to start.

The CMakeFiles.txt:

cmake_minimum_required(VERSION 3.4...3.18)
project(pimymath)

Reproduces RxJs behavior

There is no generic operators as in RxJs yet, but the main idea behind is presented here...

@xaliphostes
xaliphostes / README.md
Last active February 7, 2024 08:53
Emscripten pthread lib in web worker

A small multi-threaded C++ library (so, does not include any main) compiled with emscripten and pthread running under the main thread in the browser, a web worker or using node.js.

Note: Emscripten will produce lib.js.

Using a web browser

Running this lib in the main thread is fine but, obviously, block the main thread. Running it using a web worker leads no error with modification of the worker script (see below)

Using node.js

Run fine except that it prevents Node app from ever exiting.

@xaliphostes
xaliphostes / Command args.cpp
Last active October 14, 2022 06:38
https://repl.it/CYSv/30 created by xaliphostes
/**
* ------------------------------------------------------------
* Show how convenient it is to use classes instead of a bunch
* of C functions.
*
* Part of the OOP course for PhD students and Researchers.
*
* Contact: [email protected]
* ------------------------------------------------------------
*/