Skip to content

Instantly share code, notes, and snippets.

View vforsh's full-sized avatar
💭
yo

Vladislav Forsh vforsh

💭
yo
View GitHub Profile
@vforsh
vforsh / cc-uuid-utils.ts
Created June 16, 2025 06:30
Cocos Creator UUID Utils
import { createHash, randomUUID } from 'crypto'
const Base64KeyChars: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
const AsciiTo64: number[] = new Array(128)
for (let i = 0; i < 128; ++i) {
AsciiTo64[i] = 0
}
for (let i = 0; i < 64; ++i) {
AsciiTo64[Base64KeyChars.charCodeAt(i)] = i
@vforsh
vforsh / gist:e8e2d577998c919ec6d73b2e1092f158
Created April 2, 2025 18:18
Cocos Creator 3.8.5 + Vitest
<script type="text/javascript">
const systemJSPrototype = System.constructor.prototype;
const originalResolve = systemJSPrototype.resolve;
systemJSPrototype.resolve = function (specifier, importer) {
// Handle vitest imports by returning a mock module with test functions
if (specifier === 'vitest' || specifier.startsWith('vitest/')) {
return `data:text/javascript,System.register([],function(e){
return {
execute: function(){
var mockFn = function() { return mockFn; };
type Route =
| {
route: "/";
search: {
page: string;
perPage: string;
};
}
| { route: "/about"; search: {} }
| { route: "/admin"; search: {} }
@vforsh
vforsh / Permutation.d.ts
Created July 31, 2022 20:45 — forked from betafcc/Permutation.d.ts
Typescript Union Permutation, count of keys in an object, count of cases in an Union
/**
* @example
* type P = Permutation<1 | 2 | 3>
* // [1, 2, 3] | [1, 3, 2] | [2, 1, 3] | [2, 3, 1] | [3, 1, 2] | [3, 2, 1]
*/
export type Permutation<U, T = U> = [U] extends [never]
? []
: T extends unknown
? [T, ...Permutation<Exclude<U, T>>]
: never
function combineOverlappingMatches(matches) {
let hasOverlaps = false
for (let i = matches.length - 1; i >= 0; i--) {
let currentMatch = matches[i]
let overlap = matches.find(match => {
return match !== currentMatch && match.itemsType === currentMatch.itemsType
})
if (overlap) {
import { Gameplay } from "../Gameplay"
import { Submarine } from "./Submarine"
import Vector2Like = Phaser.Types.Math.Vector2Like
export class SubmarineTrail extends Phaser.GameObjects.Graphics {
private readonly colors: number[] = [0x0973B6, 0xF9CA06, 0xFF900B, 0xF2372E, 0xDA3328]
private readonly lineWidth: number = 18
private submarine: Submarine
private dy: number = 0
@vforsh
vforsh / simulate_scanned_PDF.md
Created February 7, 2018 07:49
Simulate a scanned PDF with ImageMagick

Simulate a scanned PDF with ImageMagick

  1. Download and install Ghostscript and ImageMagick + Convert Module
  2. Execute the following command in the console (change the filename)
$ convert -density 200 INPUT.pdf -rotate 0.3 +noise Multiplicative -format pdf  -quality 85 -compress JPEG -colorspace gray OUTPUT.pdf

Description of the options

  • -density: set the input DPI to 200
  • -rotate: set Page rotation to 0.3 degrees
@vforsh
vforsh / ShapeFactory.ts
Created January 23, 2014 09:55
Util for fast creating shapes in CreateJS
///<reference path='../definitions/easeljs.d.ts' />
module qdrj {
export class ShapeFactory {
public static createRect(width:number, height:number, color:string = 'black', centered:boolean = true):createjs.Shape {
var _x:number = centered ? width * 0.5 : 0;
var _y:number = centered ? height * 0.5 : 0;