Skip to content

Instantly share code, notes, and snippets.

View inca's full-sized avatar

Boris Okunskiy inca

View GitHub Profile
@inca
inca / image-resize.js
Last active August 29, 2015 14:15
Canvas-based image resize
var ImageResize = module.exports = exports = function(file) {
this.originalFile = file;
this.backgroundColor = '#fff';
};
ImageResize.prototype.resize = function(width, height, mime, cb) {
mime = mime || 'image/jpeg';
var self = this;
var reader = new FileReader();
reader.onload = onLoadFile;
@inca
inca / generate-combinations.js
Last active March 26, 2024 13:39
Generate Combinations Without Repetition
function* generateCombinations(array) {
if (array.length == 0) {
return;
}
const head = array[0];
const tail = array.slice(1);
yield [head];
for (const comb of generateCombinations(tail)) {
yield comb;
yield [head].concat(comb);
@inca
inca / Hex.cs
Last active April 28, 2024 06:42
[Unity] Simple Hex Grid System
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public static class HexVectorExtensions {
public static Vector2 WorldToPlanar(this Vector3 world) {
return new Vector2(world.x, world.z);
}
@inca
inca / slider-captcha.ts
Created March 10, 2020 17:24
Slider Captcha Solution Action
import { Element, Ctx } from '@ubio/engine';
export async function captchaSlider(el: Element, ctx: Ctx) {
const page = el.page;
// Obtain elements to interact with
const sliderEl = (await el.queryOne('.yidun_jigsaw', false))!;
const imageEl = (await el.queryOne('.yidun_bg-img', false))!;
// Get image resources (base64) so that we can send them for offscreen canvas processing
@inca
inca / json-schema.d.ts
Created July 17, 2020 12:40
JSON Schema Loose Type Annotations
export type JsonSchemaTypePrimitive = 'null' | 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
export type JsonSchemaType = JsonSchemaTypePrimitive | JsonSchemaTypePrimitive[];
export interface JsonSchema {
type?: JsonSchemaType;
// number
minimum?: number;
maximum?: number;
exclusiveMinimum?: number;
exclusiveMaximum?: number;
@inca
inca / RCE.md
Created November 11, 2022 08:48

Realtime Collaborative Editing

This document describes both high level and more in-depth aspects of realtime collaborative editing. If you're busy, here's a TL;DR:

  • users expect it
  • we need it
  • we can do it
  • we can sustainably support it
  • there are a number of problems to solve of various severity, all of them solvable
@inca
inca / README.md
Last active January 16, 2023 16:56
Icons for NodeScript
  • Automation Cloud:
@inca
inca / README.md
Last active June 5, 2025 14:57
ESBuild + Watch + Reload in Node.js

ESBuild + Watch + Reload in Node.js

Iterate on a module locally, and dynamically assemble it with ESBuild.

Especially useful with npm link but can also work on arbitrary entrypoints.

@inca
inca / README.md
Created June 5, 2025 14:57
Node.js hot module loading: await import cache busting

Hot Module Loading

When loading modules with await import() in Node.js, they become permanently cached. The subsequent await import(url), given the same url will return the exact same module.

If one needs to pick up the changes made to file system, they need custom loader hooks.

For this purpose specifically, only resolve is sufficient (note how mtime is used for cache busting).

Warning! The old modules are never actually reclaimed from memory, so some additional considerations must be taken into account: