Skip to content

Instantly share code, notes, and snippets.

View sodiray's full-sized avatar
🥊
Training

Sodiray sodiray

🥊
Training
View GitHub Profile
// As needed, add imports
export const createGMXClient = () => {
// As needed, create shared resources or
// shared functions
// _placeDeposit = async () => { ... }
/**
* When called, the function should place an order, using the given
* arguments, with the GMX V2 contract and return an identifier for
@sodiray
sodiray / useCachedResopnse.ts
Created August 25, 2022 04:38
An Exobase hook to automagically cache function responses
import { try as tryit, partial, mapValues } from "radash";
import * as uuid from "uuid";
import dur, { Duration } from "durhuman";
import type { Props, ApiFunction } from "@exobase/core";
interface CacheClient {
get: (key: string) => Promise<string>;
set: (key: string, value: string, ttl: number) => Promise<void>;
}
export type ListingView = {
_view: 'listing'
id: string
title: string
categoryId: string
description: string
price: number
userId: string
expiresAt: number
}
import * as t from 'src/types'
export class ListingView {
static toView(model: t.Listing): t.ListingView {
return {
_view: 'listing',
id: model.id,
title: model.title,
categoryId: model.categoryId,
description: model.description,
export type Listing = {
id: string
title: string
categoryId: string
description: string
price: number
userId: string
expiresAt: number
reported: number
}
import { compose } from 'radash'
import { useNext } from '@exobase/next'
import { useService, useJsonArgs } from '@exobase/hooks'
import type { Props } from '@exobase/core'
import makeDatabase from 'src/database'
import * as t from 'src/types'
import * as mappers from 'src/view/mappers'
type Args = {
listingId: string
export type ListingDocument = Listing & {
_id: ObjectId
_categoryId: ObjectId
_userId: ObjectId
}
import { omit } from 'radash'
import * as t from 'src/types'
import { ObjectId } from 'mongodb'
export class Listing {
static toModel(document: t.ListingDocument): t.Listing {
return omit(document, ['_id', '_userId', '_categoryId'])
}
static toDocument(model: t.Listing): t.ListingDocument {
return {
@sodiray
sodiray / PasswordResetEmail.tsx
Created February 3, 2022 08:27
Mailwind + React => Dynamic Tailwind Emails
export default function PasswordResetEmail({
link,
user
}: {
link: string
user: User
}) {
return (
<div className="bg-slate-200">
@sodiray
sodiray / App.tsx
Last active August 18, 2021 23:47
A React hook that makes storing data in local storage simple, easy, and helpfully typed.
import _ from 'radash'
import { useStoredData } from './useStoredData'
interface StoredUser {
email: string
}
export default function App () {
const storedUsers = useStoredData({