Skip to content

Instantly share code, notes, and snippets.

@pofulu
pofulu / Subject.ts
Last active January 27, 2023 08:45
Create EventSource in Meta Spark Studio.
import Reactive from 'Reactive';
export class Subject<T> {
private readonly _signalSource: StringSignalSource;
private readonly _eventSource: Omit<EventSource<T>, 'subscribe'> & { subscribe(callback: (args: T) => void): Subscription };
constructor() {
this._signalSource = Reactive.stringSignalSource(uuid());
this._eventSource = this._signalSource.signal.monitor() as any;
this._eventSource.subscribe = (callback: (value: T) => void) =>
@pofulu
pofulu / README.md
Last active November 22, 2022 07:51
Google Web Designer Custom Component Manifest JSON Schema

Usage

.
├── .vscode/
│   └── settings.json
├── manifest.json
└── manifest.schema.json
@pofulu
pofulu / html2json.ts
Last active November 15, 2022 06:05
Convert between HTML/JSON, it's original from https://github.com/Jxck/html2json, this is the TypeScript version. It may not be type perfect, but it will keep the type compiler happy.
import { htmlParser } from './htmlparser'
const DEBUG = false;
const debug = DEBUG ? console.log.bind(console) : function () { };
function removeDOCTYPE(html: string) {
return html
.replace(/<\?xml.*\?>\n/, '')
.replace(/<!doctype.*\>\n/, '')
.replace(/<!DOCTYPE.*\>\n/, '');
@pofulu
pofulu / ZStack.tsx
Last active September 23, 2024 16:50
ZStack component for ChakarUI with React. It's works like ZStack in SwiftUI
import { Grid, GridProps } from '@chakra-ui/react';
import { FC } from 'react';
export interface ZStackProps extends Omit<GridProps, 'justifyItems' | 'alignItems'> {
/** https://developer.apple.com/documentation/swiftui/alignment */
alignment?: 'topLeading' | 'top' | 'topTrailing' | 'leading' | 'center' | 'trailing' | 'bottomLeading' | 'bottom' | 'bottomTrailing';
}
export const ZStack: FC<ZStackProps> = ({ alignment = 'center', ...props }) => {
const justifyItems = (() => {
@pofulu
pofulu / pinInitValues.ts
Last active March 28, 2022 04:46
用於在 Spark AR 中等待任意 Signal 的數值變化
function pinInitValues<T extends readonly string[]>(signal: ISignal, values: T): Promise<{ [K in T[number]]: number }> {
const signals = values.reduce((pre, cur) => {
pre[cur] = signal[cur];
return pre;
}, {})
return new Promise(resolve =>
Reactive.monitorMany(signals, { fireOnInitialValue: true }).select('newValues').take(1).subscribe(resolve)
);
}
@pofulu
pofulu / TargetTrackerDemo.ts
Last active December 6, 2021 02:45
The TypeScript version of script in Spark AR 3D Animated Poster sample project
import Time from 'Time';
import Scene from 'Scene';
import Patches from 'Patches';
import Textures from 'Textures';
import Reactive from 'Reactive';
import Animation from 'Animation';
import TouchGestures from 'TouchGestures';
// Constants for the default visual and interaction style.
const TARGET_ENVELOPE_SCALE = 1.1;
@pofulu
pofulu / OpenSeaAssetsRoot.cs
Last active November 22, 2021 08:01
OpenSea API - JSON of Retrieving assets
using System;
using System.Collections.Generic;
namespace OpenSeaAPI
{
public class AssetContract
{
public string address { get; set; }
public string asset_contract_type { get; set; }
public DateTime created_date { get; set; }
@pofulu
pofulu / TextureTool.cs
Created October 15, 2021 08:55
旋轉圖片
using UnityEngine;
public static class TextureTool
{
public static Texture2D rotateTexture(Texture2D originalTexture, bool clockwise)
{
Color32[] original = originalTexture.GetPixels32();
Color32[] rotated = new Color32[original.Length];
int w = originalTexture.width;
int h = originalTexture.height;
@pofulu
pofulu / AddressableBundleCleaner.cs
Last active October 30, 2023 06:48
快速整理出最新有用到的 bundle
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEditor.AddressableAssets.Settings;
using UnityEngine;
/// <summary>
@pofulu
pofulu / ShinobiWPS-Unity_WebGL_tips.md
Last active June 8, 2021 03:02 — forked from ShinobiWPS/ShinobiWPS-Unity_WebGL_tips.txt
ShinobiWPS - Tips to optimize a WebGL build of a Unity game