Skip to content

Instantly share code, notes, and snippets.

View sjdonado's full-sized avatar
:atom:
The enemy of the art is the absence of limitations - Orson Welles

Juan Rodriguez sjdonado

:atom:
The enemy of the art is the absence of limitations - Orson Welles
View GitHub Profile
@sjdonado
sjdonado / Editor.tsx
Last active November 29, 2024 12:17
Fabric 2d editor prototype
import React, { useEffect, useRef } from 'react';
import { fabric } from 'fabric';
import { useCanvas } from './useCanvas';
const PVEditor = () => {
const canvasRef = useRef(null);
const { state, addObject, updateObject, deleteObject, selectObject, syncActiveObject } = useCanvas();
useEffect(() => {
const canvas = new fabric.Canvas('canvas', { width: 800, height: 600 });
@sjdonado
sjdonado / sjdonado_feeds.opml
Last active November 3, 2024 00:19
My collection of RSS feeds
<?xml version="1.0" encoding="UTF-8"?>
<!-- OPML generated by NetNewsWire -->
<opml version="1.1">
<head>
<title>sjdonado_feeds.opml</title>
</head>
<body>
<outline text="NetNewsWire News" title="NetNewsWire News" description="" type="rss" version="RSS" htmlUrl="https://netnewswire.blog/" xmlUrl="https://netnewswire.blog/feed.xml"/>
<outline text="Finance" title="Finance">
<outline text="Darius Foroux" title="Darius Foroux" description="" type="rss" version="RSS" htmlUrl="https://dariusforoux.com/" xmlUrl="https://dariusforoux.com/feed/"/>
@sjdonado
sjdonado / 08.05.23-9.js
Created May 8, 2023 19:02
Tower of Hanoi in P5.js + WASM - Dev.to
const getHanoiMoves = async (n) => new Promise((resolve) => {
wasmWorker.onmessage = (event) => resolve(event.data);
wasmWorker.postMessage({ n });
});
@sjdonado
sjdonado / 08.05.23-8.js
Created May 8, 2023 19:01
Tower of Hanoi in P5.js + WASM - Dev.to
const wasmWorker = new Worker(new URL('../workers/hanoi.js', import.meta.url), {
type: 'module',
});
@sjdonado
sjdonado / 08.05.23-7.js
Created May 8, 2023 19:00
Tower of Hanoi in P5.js + WASM - Dev.to
import { get_moves } from '@wasm/games';
onmessage = (event) => {
const moves = get_moves(event.data.n);
postMessage(moves);
};
@sjdonado
sjdonado / 08.05.23-6.rs
Created May 8, 2023 19:00
Tower of Hanoi in P5.js + WASM - Dev.to
use gloo_utils::format::JsValueSerdeExt;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn get_moves(n: i32) -> JsValue {
fn move_tower(n: i32, from: i32, to: i32, aux: i32, moves: &mut Vec<String>) {
if n == 1 {
moves.push(format!("{}:{}", from, to));
} else {
move_tower(n - 1, from, aux, to, moves);
@sjdonado
sjdonado / 08.05.23-5.js
Created May 8, 2023 18:59
Tower of Hanoi in P5.js + WASM - Dev.to
import { get_moves } from '@wasm/games';
@sjdonado
sjdonado / 08.05.23-4.diff
Last active May 8, 2023 19:03
Tower of Hanoi in P5.js + WASM - Dev.to
import { defineConfig } from 'vite';
import solidPlugin from 'vite-plugin-solid';
+ import wasm from 'vite-plugin-wasm';
+ import topLevelAwait from 'vite-plugin-top-level-await';
import path from 'path';
export default defineConfig({
plugins: [
@sjdonado
sjdonado / 08.05.23-3.toml
Created May 8, 2023 18:57
Tower of Hanoi in P5.js + WASM - Dev.to
...
[lib]
path = "logic/lib.rs"
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "0.2"
getrandom = { version = "0.2.8", features = ["js"] }
gloo-utils = { version = "0.1", features = ["serde"] }
@sjdonado
sjdonado / 08.05.23-2.js
Created May 8, 2023 18:56
Tower of Hanoi in P5.js + WASM - Dev.to
function recursiveHanoi(A, C, B, n){
if (n == 1) {
moves.push(A + ":" + C);
} else {
recursiveHanoi(A, B, C, n - 1);
moves.push(A + ":" + C);
recursiveHanoi(B, C, A, n - 1);
}
}
function generateHanoiArray(disksNumber) {