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 / readme.md
Created October 7, 2024 05:51
Vercel Deploy Script

Vercel Deploy Script

This takes advantage of deployment hooks on Vercel. This simply removes the deploy file if it exists. Otherwise, it creates it. Then pushes it to the repository.

Usage

Add to your package.json

{
@srph
srph / index.ts
Last active July 17, 2024 13:59
JS/TS: Multiply BigInt to Float
// Bn -> Float multiplication works like this: 150e6 * (0.5 * 100) / 100
// Also does some coercions for readability
const multiplyBnToFloat = (a: string, b: string) => {
return (BigInt(a) * BigInt(Number(b) * 100)) / BigInt(100)
}
// 75000000
multiplyBnToFloat('150000000', '0.5000000000')
@srph
srph / 0rc.code-snippets
Last active May 30, 2024 19:18
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 28, 2024 08:27
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]