Skip to content

Instantly share code, notes, and snippets.

View PranavSK's full-sized avatar

Pranav Koundinya PranavSK

  • Zendesk
  • Bangalore
  • 08:58 (UTC +05:30)
View GitHub Profile
import { type WritableStore, action, onNotify } from 'nanostores'
export function createHistory<Value>(store: WritableStore<Value>): {
clearHistory: () => void
redo: () => void
undo: () => void
} {
let historyIndex = -1
let history: Value[] = [store.get()]
let isInternalChange = false
import type { Store } from 'nanostores'
import { onMount } from 'nanostores'
export function createStoreFactory<Id, StoreType extends Store<unknown>>(
initializer: (id: Id) => StoreType,
equal?: (a: Id, b: Id) => boolean
) {
const stores = new Map<Id, StoreType>()
const storeGetter = equal
func get_all_files(path: String, file_ext := "", files := []):
var dir = Directory.new()
if dir.open(path) == OK:
dir.list_dir_begin(true, true)
var file_name = dir.get_next()
while file_name != "":
if dir.current_is_dir():
// Those snippets are in vec4 type but you can change to another types like:
// vec3, vec2, float, int ..........
vec4 when_eq(vec4 x, vec4 y) {
return 1.0 - abs(sign(x - y));
}
vec4 when_neq(vec4 x, vec4 y) {
return abs(sign(x - y));
}
/**
* Generates a unique string for use as ID(s).
* @summary Similar in concept to
* <http://wiki.ecmascript.org/doku.php?id=strawman:names>.
*
* The goals of this function are twofold:
*
* - Provide a way to generate a string guaranteed to be unique when compared
* to other strings generated by this function.
shader_type spatial;
render_mode unshaded;
uniform sampler2D pattern_map: hint_albedo;
uniform vec2 uv_offset = vec2(0.5, 0.5);
uniform vec2 uv_tiling = vec2(1.0, 1.0);
float when_lt(float x, float y) {
return max(sign(y - x), 0.0);
import os
import sys
def ensure_site_packages(packages):
""" `packages`: list of tuples (<import name>, <pip name>) """
if not packages:
return
import site
extends Node
## Based on https://github.com/Zylann/godot_debug_draw
## @brief Single-file autoload for debug drawing and printing.
## Draw and print on screen from anywhere in a single line of code.
# TODO: Thread-safety
# TODO: 2D functions
## @brief How many frames HUD text lines remain shown after being invoked.
class_name MathUtils
static func clamp_magnitude(vector, amount):
return vector if vector.length() < abs(amount) else vector.normalized() * amount
static func get_aabb_center(bounds: AABB) -> Vector3:
return bounds.position + bounds.size / 2
class_name NodeUtils
static func get_children_of_type(node: Node, type) -> Array:
var ret: = []
for child in node.get_children():
if child is type:
ret.append(child)
if child.get_child_count() > 0:
ret += get_children_of_type(child, type)