Skip to content

Instantly share code, notes, and snippets.

View MichaelBelousov's full-sized avatar

Michael Belousov MichaelBelousov

View GitHub Profile
@MichaelBelousov
MichaelBelousov / sprite_dedup.py
Created February 23, 2024 20:25
I don't remember. I think it deduped sprites. will read later
from PIL import Image
import tempfile
import os
from math import ceil, sqrt
# import argparse
imgpath = input('What is the path to the image? ')
img = Image.open(imgpath)
img_width = img.size[0]
img_height = img.size[1]
#!/usr/bin/env python3
"""
files created using (this was redacted partially):
```sh
NODE='/home/mike/.local/share/pnpm/node'
for args in "--sampleCase1Arg";
do
for file in input1 input2 input3
@MichaelBelousov
MichaelBelousov / flakyhang-cmd.sh
Last active February 13, 2023 15:32
catching flaky hangs with gdb
for i in {1..2};
do
echo "Run $i"
date
gdb node -ex 'python gdb.events.exited.connect(lambda t: t.exit_code == 0 and gdb.execute("q"))' \
-ex "run script.js --options 2>&1 > run_$i.log" \
|| echo "failed $?";
done
@MichaelBelousov
MichaelBelousov / ltracing
Created January 6, 2023 20:59
generate ltrace filter from includes
ltrace -e "$(grep -h 'linkage_macro' $(find thirdparty_lib -name '*.h') | grep -v '^#' | cut -d' ' -f 3 | paste -sd+)@*my-so*" node script.js
@MichaelBelousov
MichaelBelousov / test.zig
Last active June 2, 2022 20:13
zig compile error
//! parser for nodelang written in zig
pub const Tok = enum {
colon,
other, // need at least two here to trigger it
};
const Token = struct {
tok: Tok,
str: []const u8,
@MichaelBelousov
MichaelBelousov / TankMarker.tsx
Last active January 28, 2021 13:20
even more hooks - use useAsyncInterval
import { useAsyncInterval } from "@bentley/react-hooks";
//...
useAsyncInterval(
async ({isStale, setCancel}) => {
const aborter = new AbortController();
setCancel(() => aborter.abort());
const response = await fetch("http://localhost:3001/tank-params", { signal: aborter.signal });
const result = await response.json();
if (!isStale()) setTankParamValue(result[tankParamType]);
},
@MichaelBelousov
MichaelBelousov / App.tsx
Last active January 28, 2021 13:23
even more hooks - show the marker in App
// at the top add these imports
import TankMarker from "./TankMarker.tsx";
import { Viewer } from "@bentley/itwin-viewer-react";
import { IModelJsViewProvider } from "@bentley/imodel-react-hooks";
const App = () => {//...
//... at the bottom of the file replace the return statement with this
const [imjsInited, setImjsInited] = useState(false);
const [tankParamType, setTankParamType] = useState<"level" | "pressure">("level");
@MichaelBelousov
MichaelBelousov / TankMarker.tsx
Last active January 28, 2021 13:24
even more hooks - TankMarker
import React from "react";
import { Marker } from "@bentley/imodel-react-hooks";
import { useAsyncInterval } from "@bentley/react-hooks";
import { Point3d } from "@bentley/geometry-core";
export default function TankMarker({tankParamType}: {tankParamType: "level" | "pressure"}) {
const [tankParamValue, setTankParamValue] = React.useState<number>();
useAsyncInterval(
async ({ isStale, setCancel }) => {
@MichaelBelousov
MichaelBelousov / install-deps-serve.sh
Created January 27, 2021 14:24
even more hooks - install deps and run server
yarn add express@^4.16.0 cors @bentley/imodel-react-hooks @bentley/react-hooks
node src/server.js
@MichaelBelousov
MichaelBelousov / server.js
Last active January 27, 2021 15:29
even more hooks - create server script
const app = require("express")();
app.use(require('cors')());
app.get("/tank-params", (req, res) => {
res.json({
level: Math.random(),
pressure: Math.random(),
});
});