Skip to content

Instantly share code, notes, and snippets.

View mukaschultze's full-sized avatar
¯\_(ツ)_/¯

Samuel Schultze mukaschultze

¯\_(ツ)_/¯
View GitHub Profile
@mukaschultze
mukaschultze / rxjs-hooks.ts
Created September 5, 2021 19:39
RxJS hooks for React
import { useEffect, useRef, useState } from "react";
import { BehaviorSubject, Observable, PartialObserver, Subject } from "rxjs";
function useConstant<T>(factory: () => T): T {
const ref = useRef<{ value: T }>();
if (!ref.current) {
ref.current = { value: factory() };
}
@mukaschultze
mukaschultze / Clipboard.cs
Created January 11, 2022 03:25
Unity Clipboard
using UnityEngine;
#if UNITY_WEBGL && !UNITY_EDITOR
using System.Runtime.InteropServices;
#endif
public static class Clipboard {
public static string ClipboardText {
get { return clipboard_read_text(); }
set { clipboard_write_text(value); }
@mukaschultze
mukaschultze / URLParameters.cs
Created January 11, 2022 03:26
Unity URL Parameters (WebGL)
/* * * * *
* URLParameters.cs
* ----------------
*
* This singleton script provides easy access to any URL components in a Web-build.
* Since Unity is about to deprecate the old "Application.ExternalEval" api we can
* no longer inject our javascript into the browser. We now need to use a jslib file
* which holds the javascript part. This script, when imported in a project, will
* automatically extract a jslib file into the Plugins folder named: "URLParameters.jslib".
*
@mukaschultze
mukaschultze / loopback_bind.md
Last active January 2, 2025 00:30
Acessando serviços no docker sem expor as portas publicamente

Acessando serviços no docker sem expor as portas publicamente

Expondo portas apenas no loopback

Com Docker é possível configurar um container para que ele ouça conexões à uma porta apenas em um IP por meio da opção publish, no formato ip:hostPort:containerPort. Isso impede que conexões sejam feitas por outros IPs sejam aceitas.

Se configurarmos o container para ouvir apenas no IP de loopback (127.0.0.1),

@mukaschultze
mukaschultze / .dockerignore
Created January 29, 2022 21:34
Unity + Mirror over WebSockets using traefik as a reverse proxy
*
!/Builds/
!nginx.conf
@mukaschultze
mukaschultze / arch.md
Last active February 18, 2025 14:20
Free Arch Linux on GCP
@mukaschultze
mukaschultze / pin-asterisk-versions-lockfile.js
Last active August 8, 2022 13:12
Pin yarn workspace versions
/** Yarn workspaces currently don't have a way of specifying that a workspace
* (i.e., package) should use the worktree (i.e., root package.json) version for
* a dependency. Some projects use the @* version descriptor (equivalent to
* latest version) to achieve this, although this approach works most of the
* time it can easily get the workspace and worktree versions out of sync when
* some of the packages are explicitly updated via package.json or when
* yarn.lock gets regenerated.
*
* The alternative to using the @* syntax is using the `file:` version
* descriptor, so the workspace uses the package from a given directory, in this
@mukaschultze
mukaschultze / review.ts
Created September 13, 2022 18:44
NativeScript prompt user for app review
import { Application, Device, isAndroid, Utils } from '@nativescript/core';
/**
* This method uses native APIs to request an app review from the user. There's
* no guarantee that the user will actually be prompted when this method is
* called and there's no way to know if the left a review or not. This is a
* limitation of the platform.
*
* NOTES
*
@mukaschultze
mukaschultze / output.env
Created September 28, 2022 16:13
Easy macOS VM
export DEVICE_MODEL="iMacPro1,1"
export SERIAL="--GENERATED--"
export BOARD_SERIAL="--GENERATED--"
export UUID="--GENERATED--"
export MAC_ADDRESS="--GENERATED--"
export WIDTH="1920"
export HEIGHT="1080"
@mukaschultze
mukaschultze / optimize.sh
Created June 15, 2023 21:05
Optimize PNG images using pngcrush
#!/bin/bash
original_total=0
final_total=0
saved_total=0
# Calculate original total size
while IFS= read -r -d '' file; do
size=$(stat -c "%s" "$file")
original_total=$((original_total + size))