Skip to content

Instantly share code, notes, and snippets.

View srph's full-sized avatar
🛠️
Building @Stride-Labs Frontend

Kier Borromeo srph

🛠️
Building @Stride-Labs Frontend
View GitHub Profile
@srph
srph / 0rc.code-snippets
Created April 9, 2024 07:26
React Component Snippet for VS Code (based on filename, with prop types)
{
"React Component": {
"prefix": "0rc",
"body": [
"import React from 'react';",
"",
"interface ${TM_FILENAME_BASE}Props {",
" name: string;",
"}",
"",
@srph
srph / DefaultPalWorldSettings.ini
Last active January 26, 2024 14:18
PalServer mid-rate config
; This configuration file is a sample of the default server settings.
; Changes to this file will NOT be reflected on the server.
; To change the server settings, modify Pal/Saved/Config/LinuxServer/PalWorldSettings.ini.
[/Script/Pal.PalGameWorldSettings]
OptionSettings=(Difficulty=None,DayTimeSpeedRate=1.000000,NightTimeSpeedRate=0.500000,ExpRate=3.000000,PalCaptureRate=1.500000,PalSpawnNumRate=1.500000,PalDamageRateAttack=1.000000,PalDamageRateDefense=1.000000,PlayerDamageRateAttack=1.000000,PlayerDamageRateDefense=1.000000,PlayerStomachDecreaceRate=1.000000,PlayerStaminaDecreaceRate=0.750000,PlayerAutoHPRegeneRate=2.000000,PlayerAutoHpRegeneRateInSleep=1.000000,PalStomachDecreaceRate=1.000000,PalStaminaDecreaceRate=0.750000,PalAutoHPRegeneRate=2.000000,PalAutoHpRegeneRateInSleep=1.000000,BuildObjectDamageRate=1.000000,BuildObjectDeteriorationDamageRate=0.000000,CollectionDropRate=1.500000,CollectionObjectHpRate=1.000000,CollectionObjectRespawnSpeedRate=1.500000,EnemyDropItemRate=2.000000,DeathPenalty=None,
@srph
srph / throttle.manual.ts
Last active August 31, 2023 18:31
throttle: Guarantee an async functions only resolves after X ms
import { delay } from '../time'
import { throttle } from './throttle'
// @TODO: In the future, let's write some tests. It's proving to be challenging
// because vitest has no means of flushing promises, and it causes some tests
// to fail (ergo, we expect callback to resolve faster, but it doesn't).
//
// Manual test for throttle function. To run:
// $ npm i -g ts-node && ts-node throttle.manual.ts
const tests = {
[
[
{
key: 'spender',
value: 'cosmos1x92tnm6pfkl3gsfy0rfaez5myq5zh99aek2jmd'
},
{ key: 'amount', value: '6250uatom' }
],
[
{
@srph
srph / wallet.ts
Created June 21, 2023 10:08
v47 Upgrade
import { Tendermint37Client } from "@cosmjs/tendermint-rpc";
// @see https://github.com/cosmos/cosmjs/issues/1353
// Replace await `SigningStargateClient.connectWithSigner` with this:
const connectWithStargateSigner: typeof SigningStargateClient['connectWithSigner'] = async (rpc, signer, options) => {
const client = await Tendermint37Client.connect(rpc)
return await SigningStargateClient.createWithSigner(client, signer, options)
}
// @see https://github.com/cosmos/cosmjs/issues/1353
@srph
srph / index.html
Created April 28, 2023 03:08
Fixes - Countdown Timer
<script src="https://cdn.tailwindcss.com"></script>
<body class="relative w-full h-screen m-0 bg-gradient-to-b from-mostlyBlackBlue to-veryDarkBlue
font-redHatText">
</div>
<section class="w-full h-full flex flex-col justify-center items-center space-y-12">
<div class="text-4xl text-white tracking-[14px] font-bold">
WE'RE LAUNCHING SOON
</div>
<div class="flex justify-center items-center gap-[40px]">
@srph
srph / useCountdown.ts
Created March 24, 2023 16:26
React: useCountdown hook
import { useState, useMemo } from 'react'
import { intervalToDuration, isAfter, eachDayOfInterval, addMonths } from 'date-fns'
import { useInterval } from '@/hooks'
interface UseCountdownParameters {
target: Date
}
interface UseCountdownDuration {
days: string
@srph
srph / chunk-pattern.ts
Created March 20, 2023 11:13
JS: Slice an array based on provided pattern
// @source https://github.com/srph/chunk-pattern/blob/master/index.js
// Slices the array into chunks based on the pattern.
// Useful for intentionally splitting an array into rows and columns on a specific pattern.
// e.g., display 4 on top, 2 on bottom.
// @use chunkPattern([1, 2, 3, 4, 5], [2, 3]) => [[1, 2], [3, 4, 5]]
// @use chunkPattern([1, 2, 3, 4, 5], [4, 1]) => [[1, 2, 3, 4], [5]]
const chunkPattern = <T>(array: readonly T[], pattern: number[]): Array<T[]> => {
const result: Array<T[]> = [[]]
let patternIndex: number = 0
let patternCount: number = pattern[0]
@srph
srph / gist:1cce7fcf97c83bff86b7a36364739c5c
Created February 19, 2023 02:12
data structure for drag and drop feature with react-query
// API
{
items: []
}
// Query
{
items: {
[id]: {
id: 1,
@srph
srph / poll.ts
Created January 11, 2023 13:02
JS: Poll until condition is true (with max attempts and manual abort)
@@ -0,0 +1,44 @@
import { delay } from '../time'
type PollValueCallback<T> = () => Promise<T>
type PollConditionCallback<T> = (t: T) => boolean
interface PollOptions {
ms?: number
max?: number