Skip to content

Instantly share code, notes, and snippets.

View gilzoide's full-sized avatar

Gil Reis gilzoide

View GitHub Profile
@gilzoide
gilzoide / common_string_prefix.gd
Created March 15, 2025 01:12
Common prefix for 2 strings in GDScript
## Get common prefix for 2 strings
static func get_common_string_prefix(s1: String, s2: String) -> String:
var common_length = min(s1.length(), s2.length())
for i in range(common_length):
if s1[i] != s2[i]:
return s1.substr(0, i)
return s1.substr(0, common_length)
@gilzoide
gilzoide / deepcopy.py
Created October 21, 2024 17:35
Deep copy implementation for Python with a fast path that uses `marshal`
import copy
import marshal
def marshal_deepcopy(obj):
"""
Deep copy implementation that uses `marshal` for increased speed if possible,
falling back to `copy.deepcopy` if the passed object is not marshallable.
"""
try:
#include <stdlib.h>
#include <raylib.h>
#include <physfs.h>
#include "raylib-physfs.h"
static unsigned char *LoadPhysfsFileData(const char *fileName, int *dataSize) {
PHYSFS_File *file = PHYSFS_openRead(fileName);
unsigned char *buffer = NULL;
@gilzoide
gilzoide / sql-minify.js
Created October 3, 2024 16:28
Simple SQL minification for JavaScript using regexes
/**
* Minify a SQL query.
* SQL minification removes comments and unnecessary whitespace.
* WARNING: this method will condense whitespace from string literals, beware!
* @param {string} sql SQL raw query
* @returns {string} Minified SQL query
*/
function minifySql(sql) {
return sql
.replace(/--[^\n]*/g, '') // remove line comments
@gilzoide
gilzoide / BoundsCornerEnumerator.cs
Last active April 30, 2024 02:21
Non-alloc IEnumerable/IEnumerator for UnityEngine.Bounds 8 corners
// Usage: foreach (Vector3 corner in bounds.EnumerateCorners()) { ... }
using System.Collections;
using System.Collections.Generic;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;
namespace Gilzoide.BoundsCornerEnumerator
{
public static class BoundsExtensions
{
@gilzoide
gilzoide / SpritePackingTagToAtlas.cs
Last active March 15, 2024 15:08
Converts legacy sprite packing tags to a 2D Sprite Atlas
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.U2D;
using UnityEngine;
// How to use:
// 1. Select a texture that has a "Packing Tag" set
// 2. Open the context menu in the top-right corner of the inspector
@gilzoide
gilzoide / gcloud_secret_envvars.py
Created February 14, 2024 21:16
Python environment variables from Google Cloud Secret Manager
"""
Functionality to fetch environment variables using Google Cloud Secret Manager.
Environment variables with the GCLOUD_SECRET_ prefix will be filled with
secrets fetched from Google Cloud Secret Manager.
This way, you can use secrets for any environment variables without changing
any code, just the environment setup.
"""
import os
@gilzoide
gilzoide / EOS-na-Unity.md
Last active November 22, 2022 12:32
Notas sobre Epic Online Services na Unity

A integração com Unity se dá por meio do SDK C#, que pode ser baixado diretamente do portal da Epic.

Como fazer funcionar na Unity pra builds Android/iOS:

  • É necessário remover ou ignorar a pasta Samples, pois eles definem classes C# com nomes duplicados.
  • Se estiver usando a Unity num computador macOS, é necessário comentar a linha #define EOS_DYNAMIC_BINDINGS no arquivo SDK/Source/Generated/Bindings.cs, pois a biblioteca nativa do macOS não foi compilada com suporte a carregamento dinâmico. Como os bindings dinâmicos já foram desligados, não precisamos fazer o Hook dinâmico no editor no Windows como recomenda a documentação.
  • As bibliotecas xaudio2_9redist.dll são para Windows e precisam ser configuradas de acordo, para não serem consideradas nas builds Android e iOS e quebrá-las.
  • O framework nativo do iOS precisa da flag Add to embedded binaries marcada, ou a aplicação não inicializa corretamente
  • É necessário escolher somente uma das versões da biblioteca nativa para Android e apaga
@gilzoide
gilzoide / GradleAndroidPluginVersionSetter.cs
Created September 21, 2022 15:35
Unity Gradle Android plugin version setter
#if UNITY_ANDROID
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor.Android;
public class GradleAndroidPluginVersionSetter : IPostGenerateGradleAndroidProject
{
public const string GradleAndroidPluginVersion = "3.4.3";
public int callbackOrder => 0;
@gilzoide
gilzoide / lua_string_replace.c
Last active September 7, 2021 14:03
A plain string replacement function for Lua with no magic characters
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
/// Performs plain substring replacement, with no characters in `pattern` or `replacement` being considered magic.
/// There is no support for `string.gsub`'s parameter `n` and second return in this version.
/// @function string.replace
/// @tparam string str
/// @tparam string pattern
/// @tparam string replacement