Skip to content

Instantly share code, notes, and snippets.

View geekrelief's full-sized avatar
🤖

Don-Duong Quach geekrelief

🤖
View GitHub Profile
@geekrelief
geekrelief / here.nim
Last active June 28, 2024 18:22
A Nim debugEcho with file, line number, and callsite.
import std/macros
# calls debugEcho with the lineInfo
macro here*(x: varargs[typed, `$`]):untyped {.noSideEffect.} =
{.cast(noSideEffect), warning[Deprecated]:off.}: # callsite is deprecated, there's no alternative: https://github.com/nim-lang/RFCs/issues/387
result = newTree(nnkCommand, ident "debugEcho")
result.add newStrLitNode("--- " & x[0].lineInfo & " ---\n")
result.add newStrLitNode(" " & callsite().toStrLit().strVal & " -> \n")
for c in x:
result.add c
@geekrelief
geekrelief / macro_nilable.nim
Created January 22, 2022 19:34
Nim: Check if a type is nilable in a macro.
import std/[ macros, strformat ]
proc parseParts(x: NimNode): seq[NimNode]
proc parseDotExpr(x: NimNode): seq[NimNode] =
result.add parseParts(x[0])
result.add x
proc parseBracketExpr(x: NimNode): seq[NimNode] =
result.add parseParts(x[0])
@geekrelief
geekrelief / gist:7d5238fe59adae279c153c1668a7dd91
Created January 4, 2022 02:57
getTypeImplEx: A version of `getTypeImpl` that returns the "expressed" type after transformations.
import std / macros
type
Vec[N: static[int], T] = object
arr: array[N, T]
Vec4[T] = Vec[4, T]
Vec4f = Vec4[float32]
var a: Vec4f
proc isTypeDesc(n: NimNode): bool =
@geekrelief
geekrelief / apply.nim
Last active December 10, 2021 20:38
Apply / Splat for Nim
import macros
proc mysum(a, b, c, d:int) =
echo a + b + c + d
macro apply(fun, args: typed): untyped =
result = newCall(fun)
var funArgLen = getType(fun).len - 2
case args.kind:
of nnkBracket:
for a in args:
@geekrelief
geekrelief / SynthMachine.tm_theme
Last active September 11, 2021 17:48
Synthwave theme for The Machinery (screenshot below)
{
"__type": "tm_ui_theme",
"name": "SynthMachine",
"colors": [
{
"name": "chrome_background",
"color": {
"r": 0.01967233046889305,
"g": 0.01114554610103369,{
"__type": "tm_ui_theme",
extends Node
export var move_speed := 3.0
var db
func _ready():
db = get_node("/root/DataBind")
func _physics_process(delta):
extends Node
var data:Dictionary #key: name:String, val:[Node, property:NodePath]
var handlers:Dictionary # key: name:String, val:[Node, meth name:String]
func dump():
print("Data:")
for key in data:
print(String(path(key)) + ":" + String(property(key)))
print("\nHandlers:")
// using System.Collections.Generic;
// using UnityEngine;
// using UnityEditor;
// for ordered selection
HashSet<GameObject> selectionSet = new HashSet<GameObject>();
HashSet<GameObject> newSet = new HashSet<GameObject>();
HashSet<GameObject> deleteSet = new HashSet<GameObject>();
List<GameObject> selectionOrdered = new List<GameObject>();
function multilineString(_fn)
{
// takes a function with a multiline comment in it and converts it to a multiline string
//
// example:
// var str = loq.mstring(function(){
// /*
// 123
// abc
// */});
/* compile.hxml
-swf-version 10
-swf sfx.swf
-main Soundfx
-swf-header 600:400:30:ff6600
*/
// Soundfx.hx - example for playing back mp3s in haxe
import flash.media.Sound;