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
Last active January 9, 2025 06:12
React: Flash success state before reverting back to normal state

Usage

Here's an example of using this hook on top of react-query.

When your react-query mutation succeeds, we'll only flash the success state for 3 seconds until it's reverted back to normal

const isSuccess = useEphemeralState(
  mutation.isSuccess,
  3000,
);
@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 / 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 = {
@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 / stm.js
Last active April 25, 2024 17:54
js: standard time to military time
/**
* Standard Time to Military time
*
* @param {number} t Time to be converted
* @param {string} moridiem AM/PM
* @return {int}
*/
export default function stm (t, m) {
t = parseInt(t, 10);
@srph
srph / GenderInputSelect.jsx
Created April 2, 2016 13:19
react: gender input select
import React from 'react';
const GenderInputSelect = (props) =>
<select {...props}>
<option>Select gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
export default GenderInputSelect;
@srph
srph / parser.ts
Created November 25, 2022 17:27
Stride: stride.vesting.StridePeriodicVestingAccount
import { Pubkey } from '@cosmjs/amino'
import { Uint64 } from '@cosmjs/math'
import { decodePubkey } from '@cosmjs/proto-signing'
import { assert } from '@cosmjs/utils'
import { stride } from '@stride/proto'
import { BaseAccount, ModuleAccount } from 'cosmjs-types/cosmos/auth/v1beta1/auth'
import {
BaseVestingAccount,
ContinuousVestingAccount,
DelayedVestingAccount,
@srph
srph / DummyLink.jsx
Created March 31, 2016 23:33
react: dummy link (useful for non-link anchor elements / aka `href="#"`)
@srph
srph / web.php
Created November 2, 2016 00:07
Laravel - Catch all except /api routes. Useful for SPAs inside Laravel.
<?php
Route::get('{all}', function () {
return view('index');
})->where('all', '^((?!api).)*');