Skip to content

Instantly share code, notes, and snippets.

@miguelmota
miguelmota / promiseTimeout.ts
Created March 14, 2023 06:10
JavaScript promise timeout
class TimeoutError extends Error {}
export async function promiseTimeout<T> (promise: Promise<T>, timeout: number): Promise<T> {
return await new Promise(async (resolve, reject) => {
let timedout = false
const t = setTimeout(() => {
timedout = true
reject(new TimeoutError('timedout'))
}, timeout)
@miguelmota
miguelmota / instructions.sh
Created February 22, 2023 18:59
Arch linux install mullvad vpn
yay -S mullvad-vpn
@miguelmota
miguelmota / image_uri_output.txt
Last active February 15, 2023 17:53
get image uris for trending opensea collections
moonbirds-oddities https://live---metadata-5covpqijaa-uc.a.run.app/oddities_images/1
alphasharksofficial https://ettcvwksjfmsyce9.sfo3.digitaloceanspaces.com/1.jpg
illusion-pt-1 https://assets.bueno.art/images/cff13f6e-83dd-46a4-ac7a-696fc8f0cfd1/default/1?s=a1549611ccf81a9252c2ff1977757d15
genesis-box https://wcnft.mypinata.cloud/ipfs/Qme4SpgD8jgNyDo8AUfAsHfWS4qL8du7Vw4J4qzJ3YKS4J
webaverse-genesis-pass https://arweave.net/wGACLov8--kcHSbwkNJ_hmZj76QC_Ddkj1LFdRePTpY/OT_Thumbnail.png
strangershq https://factorlabs.mypinata.cloud/ipfs/QmXDWzbzoajAr16ACrXLa2LpczVj86T83WvZ3kcvCu6fEg/CodingProjects/Crypto/StrangersV2/Strangers/FINALFINAL/1.png
blurbears ipfs://bafybeihwzci6b426f7bekqgwa6zu4vldioqri2ui2gdwd6as3p6u75urfu/1.png
blurglyphs ipfs://QmZKyoLPBxSuyeckFqUdxzzEXyryNdWMjFJwdYMosEe9jX
remilio-babies https://remilio.org/remilio/1.png
town-star undefined
@miguelmota
miguelmota / cors_server.js
Created February 7, 2023 21:51
Node.js CORS express.js server example
import express from 'express'
import cors from 'cors'
const app = express()
app.use(cors())
app.options('*', cors())
@miguelmota
miguelmota / pricefeed_cache_example.ts
Created January 30, 2023 02:19
JavaScript pricefeed cache example
const cache: {
[tokenSymbol: string]: Promise<any>
} = {}
const cacheTimestamps: {
[tokenSymbol: string]: number
} = {}
class MyClass {
cacheTimeMs = 5 * 60 * 1000
@miguelmota
miguelmota / git_commit_amend.sh
Created December 27, 2022 04:19
git commit amend date in past example
GIT_COMMITTER_DATE="Sat Oct 11 00:29:26 2018 -0700" git commit --amend --date="Sat Oct 11 00:29:26 2018 -0700"
@miguelmota
miguelmota / SyntaxHighligher.tsx
Created December 22, 2022 05:28
React syntax highligher code example component
import React from 'react'
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
import { tomorrow as theme } from 'react-syntax-highlighter/dist/esm/styles/prism'
export function SyntaxHighligher (props: { code: string }) {
const { code } = props
return (
<SyntaxHighlighter
language="javascript"
style={theme}
@miguelmota
miguelmota / default.conf.template
Last active December 9, 2022 18:14
Nginx reverse proxy server with url parameter
server {
listen 80 default_server;
listen [::]:80 default_server;
access_log off;
resolver 8.8.8.8 ipv6=off;
location / {
proxy_pass $arg_url;
proxy_ssl_server_name on;
@miguelmota
miguelmota / tilReady.ts
Created December 9, 2022 01:03
TypeScript wait tilReady
import wait from 'wait'
class MyClass {
ready = false
async tilReady (): Promise<boolean> {
if (this.ready) {
return true
}
await wait(100)
@miguelmota
miguelmota / 64bit_buffer.js
Created November 30, 2022 21:42
Node.js 64-bit buffer example
const buf = Buffer.alloc(8)
const view = new DataView(buf.buffer)
view.setBigInt64(0, BigInt(100), false) // true when little endian
console.log(buf.toString('hex')) // "0000000000000064"